Cross-correlation issue: how can I align two signals?

21 ビュー (過去 30 日間)
Antonio Morales
Antonio Morales 2017 年 1 月 20 日
編集済み: John Chilleri 2017 年 1 月 20 日
I have two signals A and B (please, see them attached), which have been recorded from different devices with different sampling frequencies, on the same events.
I am trying to align both signals through cross-correlation methods. However, when using the alignsignals function, it does seem to actually delay even more the signals:
load A
load B
% Sampling frequencies
Fs_A = 1000; %
Fs_B = 1926; % 1925.93 Hz is the one provided by the device
% Resample signal A
A = resample(A, Fs_B, Fs_A);
% Plot of the two signals "delayed"
figure(1)
plot(A)
hold
plot(B*1000)
% Aling both signals
X = A;
Y = B;
[Xa,Ya,D] = alignsignals(X,Y,[],'truncate');
figure(2) % plot both signals "aligned"
plot(Xa)
hold
plot(Ya*1000)
I have also tried using xcorr function, with similar result:
load A
load B
% Sampling frequencies
Fs_A = 1000; %
Fs_B = 1926; % 1925.93 Hz is the one provided by the device
% Resample signal A
A = resample(A, Fs_B, Fs_A);
% Plot to visualize that one signal is delayed
figure(1)
plot(A)
hold
plot(B*1000)
% Aling both signals using xcorr
[C,lag] = xcorr(A,B);
figure(2)
plot(lag,C);
[M,I] = max(C);
D = lag(I);
figure(3),plot(1:length(A), A, 'b',1+abs(D):length(B)+abs(D), B*1000, 'r'), title(' "Synchronised" signals ');
Am I making any mistake? Maybe resampling?

採用された回答

John Chilleri
John Chilleri 2017 年 1 月 20 日
編集済み: John Chilleri 2017 年 1 月 20 日
Hello,
The reason (I suspect) the alignsignals is being weird is because of the huge negative spikes in your B signal. If we set these huge negative spikes to 0 for the align signals calculation, it will properly align the signals (what seems to be properly aligned):
load A
load B
% Sampling frequencies
Fs_A = 1000; %
Fs_B = 1926; % 1925.93 Hz is the one provided by the device
% Resample signal A
A = resample(A, Fs_B, Fs_A);
% Plot of the two signals "delayed"
figure(1)
plot(A)
hold
plot(B*1000)
% Aling both signals
X = A;
Y = B;
Y2 = Y;
Y2(Y2<0) = 0;
[Xa,Ya,D] = alignsignals(X,Y2,[],'truncate');
figure(2) % plot both signals "aligned"
plot(Xa)
hold
plot(Ya*1000)
See for yourself. If you want to still use the original B signal without the zeroing that I implemented, then utilize the delay D output from the alignsignals function, as the D output would remain correct. Simply apply the delay D to the unchanged Y and you'll have your desired result.
Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMeasurements and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by