Aligning two noisy signals
이전 댓글 표시
Hi,
I need to align two noisy signals (sig1 and sig2). I tried to use both alignsignals and xcorr functions, as they seem to be perfectly fit to this task- but I have no success, both of these methods give delay = 0.
My code:
Fs = 500;
N= length(sig1);
t = 0:1/Fs:(N-1)/Fs;
figure;plot(t,sig1,t,sig2);

[Xa,Ya,D] = alignsignals(sig1,sig2);
figure;plot(t,Xa);hold on;plot(t,Ya); title(num2str(D/Fs));

[C1,LAG] = xcorr(sig1,sig2);
figure;plot(LAG/Fs,C1)

I tried smoothing the signals, but it doesn't help.
Edit: correct signals attached.
채택된 답변
추가 답변 (2개)
Image Analyst
2022년 8월 18일
이동: Image Analyst
2022년 8월 18일
0 개 추천
I'd think that should work but you forgot to attach your data. Alternatively you could smooth the data with sgolayfilt and then find the one or two major peaks with findpeaks and find the shift based on that.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Smoothing is NOT necessary. Lacking your data to use as an example...
t = 0:500;
S1 = sin(t/10) + randn(size(t))/10;
S2 = cos(t/10) + randn(size(t))/10;
plot(t,[S1;S2])
Now, we know the two signals (sine and cosine) are apart by a phase shift of pi/2, So in terms of the x axis used, the shift should be 10*pi/2.
[C,lag] = xcorr(S1,S2)
plot(lag,C)
grid on
hold on
plot(10*pi/2*[1 1],[-250,250],'r-')
We see the peak where we would expect a peak. So the translation wil be found as we expect.
[~,ind] = max(abs(C));
translation = lag(ind)
댓글 수: 1
Image Analyst
2022년 8월 18일
I only suggested smoothing because he said alignsignals and xcorr weren't working and if you don't smooth it there would be far too many peaks to match them up one-by-one.
Anyway, he has now attached two .mat files with the signals so maybe one of us will try with them soon.
카테고리
도움말 센터 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



