Cross-correlation issue: how can I align two signals?
Show older comments
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?
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!