フィルターのクリア

Phase shift correction between 2 signals using cross-correlation

70 ビュー (過去 30 日間)
Sebsatien
Sebsatien 2015 年 2 月 18 日
コメント済み: dpb 2022 年 5 月 17 日
Hello
I'm in need of some help if you please.
I have 2 sinsoidal signals with a phase shift of 2Pi/3 between them. Basically, I need to eliminate the phase shift and obtain 2 signals with the same phase. I'm looking forward to use the cross-correlation, that represents the differnce between both signals (the phase shift, in our case), to do so.
My problem is to know how to use the cross-correlation to "correct" the shifted signal by eliminating the phase shift indiquated by the cross-correlation. Which operation to use to do so?
Here is a portion of the code for further understanding :
t = 1 : 1000;
phaseshift= 2*pi/3;
s1 = sin (2*pi*t/500);
s2 = sin (2*pi*t/500+ phaseshift);
figure(1); clf;
plot (t,s1, t,s2);
Axis_x = [-length(s1)+1 : 1 : length(s1)-1];
cross_corr = xcorr(s1,s2,'coeff');
figure(2); clf;
plot( Axe_x, coss_corr,'r');
Thanks in advance

採用された回答

dpb
dpb 2015 年 2 月 18 日
編集済み: dpb 2015 年 2 月 18 日
[c,lags]=xcorr(s1,s2); % compute cross correlation; keep lags vector
[~,iLag]=max(c(find(lags==0):end)); % find the max in one-sided
s3=circshift(s2,[0 iLag]); % correct for the shift
For your case I get
>> [~,iLag]=max(c(1000:end))
iLag =
162
>> 2*pi*iLag/500
ans =
2.0358
>> phaseshift
phaseshift =
2.0944
This isn't perfect; illustrates even with pure sine
  8 件のコメント
ZIYI LIU
ZIYI LIU 2022 年 5 月 17 日
Hi dpb,
What if I don't know the functions of these two lines, but only two set of data like these two lines. Then I can have the lags, how do I know the phase shift? Thanks!
dpb
dpb 2022 年 5 月 17 日
You know the number of lags and the sampling time, don't you?

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

その他の回答 (1 件)

Sebsatien
Sebsatien 2015 年 2 月 19 日
Thanks a lot dpb. I tried to keep the lags vector before and I haven't succeded doing so. Now Thanks to you, it's clear. I shall therefore test the code.

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by