zero lag when using xcorr on 2 near-similar, shifted timeseries

4 ビュー (過去 30 日間)
Jos Muller
Jos Muller 2023 年 9 月 22 日
編集済み: dpb 2023 年 9 月 26 日
Hi all,
I try to cross correlate two signals which are from 2 different instruments.
I use xcorr to find the lag between signal A (blue) and signal B (red). However, I keep getting 0 lag which should not be the case. As can be seen from the figure, the lag should be around ~ 110 where it gives a quit nice fit.
Attached are the signals A & B.
I'm using xcorr as the following:
[c,lags] = xcorr(A,B);
Thanks in advance for you help.
Kind regards,
Jos
  2 件のコメント
Adam Danz
Adam Danz 2023 年 9 月 22 日
load A.mat
whos
Name Size Bytes Class Attributes PIV_mag_test 1x623 2492 single ans 1x30 60 char cmdout 1x33 66 char
load B.mat
whos
Name Size Bytes Class Attributes ADV_sampled 1x623 4984 double PIV_mag_test 1x623 2492 single ans 1x30 60 char cmdout 1x33 66 char
Which variables are A and which are B?
Jos Muller
Jos Muller 2023 年 9 月 26 日
Hi Adam,
Thanks for you comment. This was a bit messy from my side. Indeed as below, it is PIV_mag_test for A.mat and ADV_sampled for B.mat.
Sorry for the inconvenience.
Best,
Jos

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

回答 (1 件)

dpb
dpb 2023 年 9 月 22 日
編集済み: dpb 2023 年 9 月 26 日
load A, load B
whos
Name Size Bytes Class Attributes ADV_sampled 1x623 4984 double PIV_mag_test 1x623 2492 single ans 1x30 60 char cmdout 1x33 66 char
subplot(2,1,1)
plot(ADV_sampled)
hold on
plot(PIV_mag_test)
xlim([300 inf])
subplot(2,1,2)
plot(ADV_sampled)
hold on
plot(PIV_mag_test)
xlim([1 200])
legend('B','A','location','northwest')
The two are perfectly in phase over almost 90% of the total signal length; that the lag between the two is zero is what I would expect. From about sample 80 on, the peaks align almost perfectly.
Only the ramp up stage of B before any regular fluctuating behavior was achieved won't correlate highly, and there there simply isnt any significant similar behavior yet to even try to compare. I suppose B is somehow driven by A and you're trying to find where the two become phase locked, maybe?
The only area that appears to have a small phase shift is that A seems to lag B some in that initial startup section between 100 and 200+ samples, but other than within that small segment of the overall signal, there's simply so little lag that a lag shift by even one sample would appear to make the overall worse -- which is what xcorr() is telling you.
A subset section might show something...
  2 件のコメント
Jos Muller
Jos Muller 2023 年 9 月 26 日
編集済み: Jos Muller 2023 年 9 月 26 日
Hi DPB,
Thanks for your comment and effort.
The signals are from 2 different instruments measuring the same sinusodial pattern and then made absolute. There is a spinup time indeed. Signal A was started logging a bit earlier (indeed ~100 samples) than signal B. So indeed i'm looking for this lag of signal A to B of expected ~100 samples.
Should I try cross-correlating this spinup period of both signals instead of the full series, to help xcorr finding a more distinct difference?
Best,
Jos
dpb
dpb 2023 年 9 月 26 日
編集済み: dpb 2023 年 9 月 26 日
There simply isn't a phase lag to speak of anywhere there's a defined sinsoidal component so I don't think correlation is the tool that will help.
Making the best first match to the amplitude of the initial peak in A by subsequent peaks in B, might serve to give a way to align them; that might then need a bit of a lag adjustment after the initial guess.
With some creativity, it should be possible to use lsqnonlin to minimize the error between the two traces by adjusting the offset of B relative to A as the parameter to solve for -- the error function would have to account for the changing length for B as it is shifted in some manner; updating the indices to match lengths between the two as pieces are lopped off the front of B.

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

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by