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!



