How can I use cross-correlation as a tool to align two signals in MATLAB?

3 ビュー (過去 30 日間)
RS
RS 2014 年 3 月 16 日
コメント済み: Youssef Khmou 2014 年 3 月 16 日
How can I use cross-correlation as a tool to align two signals in MATLAB?

回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 16 日
And I hope you know (though you probably don't because it's not well known) that the max of the cross correlation does not guarantee the best alignment. Just imagine a signal that's a Gaussian hump on the left and a tall box (taller than the Gaussian) on the right. And you're correlating it with a template that's the same as the Gaussian. The max will not be where the two Gaussians would align. Is that surprising to you? Run this demo to find out why:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
sigma = 10
x = 1:200;
longSignal = exp(-(x-50).^2/sigma^2);
longSignal(120:160) = 2;
subplot(3,1,1);
plot(x, longSignal, 'b-', 'LineWidth', 3);
grid on;
title('Long Signal', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Make template to correlate with.
template = exp(-(x-50).^2/sigma^2);
subplot(3,1, 2);
plot(x, template, 'b-', 'LineWidth', 3);
grid on;
title('Template Signal', 'FontSize', fontSize);
ylim([0 2]);
xc = xcorr(longSignal, template);
subplot(3,1, 3);
plot(xc, 'b-', 'LineWidth', 3);
grid on;
title('Cross Correlation', 'FontSize', fontSize);
See, the max is where the Gaussian aligns with the tall box, not where it aligns with "itself".
  2 件のコメント
Image Analyst
Image Analyst 2014 年 3 月 16 日
For comparison, here's what you get if the box is not in the signal:
And here's what you get if the template is centered at 90.
I imagine from looking at those you can figure out something.
Youssef  Khmou
Youssef Khmou 2014 年 3 月 16 日
you are right, i will delete the answer .

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeBartlett についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by