phase shift using xcorr

33 ビュー (過去 30 日間)
ZIYI LIU
ZIYI LIU 2022 年 5 月 17 日
編集済み: ZIYI LIU 2022 年 5 月 17 日
Dear all, I have a question really need your help. I have two functions, and I want to know their phase shift based on the period, but not the lags.
Here is the code: (I just modified the code from other questions)
t = 1 :0.1: 20;
phaseshift= pi/2;
s1 = sin (2*t);
s2 = sin (2*t+ phaseshift);
figure(1); clf;
plot (t,s1,'r', t,s2,'k');
figure;
[c,lag] = xcorr(s1,s2);
plot(lag,c)
[c,lags]=xcorr(s1,s2);
[~,iLag]=max(c(find(lags==0):end))
s3=circshift(s2,[0 iLag]);
figure;
plot(t,s1,t,s3)
I know the lags, but how do I get the phase shift based on 2*pi? (eg. the phase shift betweenthese two lines is pi, 1/2 period, because 2*t)
Thank you very much!
BEST,
zIYI

回答 (1 件)

VBBV
VBBV 2022 年 5 月 17 日
t = 1 :0.1: 20;
phaseshift= pi/2;
s1 = sin(2*t);
s2 = sin(2*t+ phaseshift);
figure(1); clf;
plot (t,s1,'r', t,s2,'k');
figure;
[c,lag] = xcorr(s1,s2);
plot(lag,c)
[c,lags]=xcorr(s1,s2);
[~,iLag]=max(c(find(lags==pi):end)) % compare with pi
iLag = 1×0 empty double row vector
s3=circshift(s2,[0 iLag]);
figure;
plot(t,s1,t,s3)
  1 件のコメント
ZIYI LIU
ZIYI LIU 2022 年 5 月 17 日
編集済み: ZIYI LIU 2022 年 5 月 17 日
Hi VBBV,
Yes, I got the lags of the max c is around 8, but how do I connect the x with phase shift?
For example, we don't know the phase shift, we only have two data like the lines, and want to know the phase shift between these two lines. Now, we have the lags is 8, how do we know the phase shift is pi/2(or 1/4 period)?
Thanks!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by