http://cn.mathworks.com/help/signal/examples/measuring-signal-similarities.html

 
 

This example shows how to measure signal similarities. It will help you answer questions such as: How do I compare signals with different lengths or different sampling rates? How do I find if there is a signal or just noise in a measurement? Are two signals related? How to measure a delay between two signals (and how do I align them)? How do I compare the frequency content of two signals? Similarities can also be found in different sections of a signal to determine if a signal is periodic.

Comparing Signals with Different Sampling Rates

Consider a database of audio signals and a pattern matching application where you need to identify a song as it is playing. Data is commonly stored at a low sampling rate to occupy less memory.

% Load data
load relatedsig.mat;

figure
ax(1) = subplot(311);
plot((0:numel(T1)-1)/Fs1,T1,'k');
ylabel('Template 1');
grid on
ax(2) = subplot(312);
plot((0:numel(T2)-1)/Fs2,T2,'r');
ylabel('Template 2');
grid on
ax(3) = subplot(313);
plot((0:numel(S)-1)/Fs,S);
ylabel('Signal');
grid on
xlabel('Time (secs)');
linkaxes(ax(1:3),'x')
axis([0 1.61 -4 4])

The first and the second subplot show the template signals from the database. The third subplot shows the signal which we want to search for in our database. Just by looking at the time series, the signal does not seem to match to any of the two templates. A closer inspection reveals that the signals actually have different lengths and sampling rates.

[Fs1 Fs2 Fs]
ans =

        4096        4096        8192

Different lengths prevent you from calculating the difference between two signals but this can easily be remedied by extracting the common part of signals. Furthermore, it is not always necessary to equalize lengths. Cross-correlation can be performed between signals with different lengths, but it is essential to ensure that they have identical sampling rates. The safest way to do this is to resample the signal with a lower sampling rate. The resample function applies an anti-aliasing(low-pass) FIR filter to the signal during the resampling process.

[P1,Q1] = rat(Fs/Fs1);          % Rational fraction approximation
[P2,Q2] = rat(Fs/Fs2); % Rational fraction approximation
T1 = resample(T1,P1,Q1); % Change sampling rate by rational factor
T2 = resample(T2,P2,Q2); % Change sampling rate by rational factor

Finding a Signal in a Measurement

We can now cross-correlate signal S to templates T1 and T2 with the xcorr function to determine if there is a match.

[C1,lag1] = xcorr(T1,S);
[C2,lag2] = xcorr(T2,S); figure
ax(1) = subplot(211);
plot(lag1/Fs,C1,'k');
ylabel('Amplitude');
grid on
title('Cross-correlation between Template 1 and Signal')
ax(2) = subplot(212);
plot(lag2/Fs,C2,'r');
ylabel('Amplitude');
grid on
title('Cross-correlation between Template 2 and Signal')
xlabel('Time(secs)');
axis(ax(1:2),[-1.5 1.5 -700 700 ])

The first subplot indicates that the signal and template 1 are less correlated while the high peak in the second subplot indicates that signal is present in the second template.

[~,I] = max(abs(C2));
SampleDiff = lag2(I)
timeDiff = SampleDiff/Fs
SampleDiff =

   499

timeDiff =

    0.0609

The peak of the cross correlation implies that the signal is present in template T2 starting after 61 ms. In other words, signal T2 leads signal S by 499 samples as indicated by SampleDiff. This information can be used to align the signals.

Measuring Delay Between Signals and Aligning Them

Consider a situation where you are collecting data from different sensors, recording vibrations caused by cars on both sides of a bridge. When you analyze the signals, you may need to align them. Assume you have 3 sensors working at same sampling rates and they are measuring signals caused by the same event.

figure,
ax(1) = subplot(311);
plot(s1);
ylabel('s1');
grid on
ax(2) = subplot(312);
plot(s2,'k');
ylabel('s2');
grid on
ax(3) = subplot(313);
plot(s3,'r');
ylabel('s3');
grid on
xlabel('Samples')
linkaxes(ax,'xy')

Measuring Signal Similarities的更多相关文章

  1. ### Paper about Event Detection

    Paper about Event Detection. #@author: gr #@date: 2014-03-15 #@email: forgerui@gmail.com 看一些相关的论文. 1 ...

  2. Signal Handling--ref

    http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_21.html A signal is a software interrupt d ...

  3. java 线程 Lock 锁使用Condition实现线程的等待(await)与通知(signal)

    一.Condition 类 在前面我们学习与synchronized锁配合的线程等待(Object.wait)与线程通知(Object.notify),那么对于JDK1.5 的 java.util.c ...

  4. Linux 信号(二)—— signal 函数

    弗洛伊德认为:要解决这些苦恼,当事人就要通过回忆并理解自己早期的童年经历,来获得对潜意识冲突的顿悟.弗洛伊德的疗法被称为“精神分析” (psychoanalysis),在 20 世纪的很长一段时间被心 ...

  5. Fatal signal xx (SIGSEGV) at

    Fatal signal 11问题的解决方法 http://blog.csdn.net/tankai19880619/article/details/9004619 如何定位Android NDK开发 ...

  6. php php-5.6.4.tar.bz2 apache 兼容问题 child pid 27858 exit signal Segmentation fault

    环境 [root envirotar]# uname -a Linux i2..el6.x86_64 # SMP Thu Jul :: UTC x86_64 x86_64 x86_64 GNU/Lin ...

  7. The Similarities and Differences Between C# and Java -- Part 1(译)

    原文地址 目录 介绍(Introduction) 相似点(Similarities) 编译单位(Compiled Units) 命名空间(Namespaces) 顶层成员(类型)(Top Level ...

  8. QT 中 关键字讲解(emit,signal,slot)

    Qt中的类库有接近一半是从基类QObject上继承下来,信号与反应槽(signals/slot)机制就是用来在QObject类或其子类间通讯的方法.作为一种通用的处理机制,信号与反应槽非常灵活,可以携 ...

  9. C标准头文件<signal.h>

    信号即异常,或者理解为中断,一个进程接收到一个信号,如果没有处理机制,就会按照默认的处理方式进行处理,而默认的处理方式通常是终止当前进程或忽略该信号.当然,程序也可以编写相应的处理信号的函数,一旦接收 ...

随机推荐

  1. UVa 11389 (贪心) The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...

  2. Discuz 7.2 /faq.php SQL注入漏洞

    测试方法: 提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!   Discuz 7.2 /faq.php SQL注入漏洞   http://www.xxx.com/faq.php?a ...

  3. Android之 环境搭建

    一. 使用ADT Bundle多合一下载包 下载地址:链接:http://pan.baidu.com/s/1gepNRjX  密码: ozdi 说      明:多合一下载包,里面包含了:sdk + ...

  4. python模拟http请求

    下文主要讲述如何利用python自带的库模拟http请求,为以后利用python做API测试做准备. 只讲述模拟http的过程,具体到自己用的时候,要以自己的应用为准做出适当的调整. #!coding ...

  5. Library cache lock/pin详解

    Library cache lock/pin 一.概述 ---本文是网络资料加metalink 等整理得来一个实例中的library cache包括了不同类型对象的描述,如:游标,索引,表,视图,过程 ...

  6. liux vim命令

    命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...

  7. 【转】Masonry介绍与使用实践(快速上手Autolayout)

    原文网址:http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/ 前言 1 MagicNumber -> aut ...

  8. 【转】MegaSAS RAID卡 BBU Learn Cycle周期的影响

    http://ju.outofmemory.cn/entry/140 背景 最近遇到有些带MegaSAS RAID卡的服务器,在业务高峰时突然IO负载飚升得很高,IO性能急剧下降,查了日志及各种设置最 ...

  9. InnoDB一定会在索引中加上主键吗

    InnoDB一定会在索引中加上主键吗 http://www.penglixun.com/tech/database/will_innodb_store_pk_in_index.html

  10. hdu 3938 Portal(并查集+离线+kruskal)2011 Multi-University Training Contest 10

    搜了题解才把题搞明白.明白之后发现其实题意很清晰,解题思路也很清晰,只是题目表述的很不清晰…… 大意如下—— 给你一个无向图,图中任意两点的距离是两点间所有路径上的某一条边,这条边需要满足两个条件:1 ...