[英]Cross correlation in Matlab to compute time lag for two time series
我有兩個時間序列y1和y2,需要在Matlab中使用互相關來找到它們之間的時間差。 然后,我需要繪制互相關圖,對齊兩個圖並重新繪制圖。 我已經寫了一些Matlab代碼來做到這一點,但是我認為互相關圖很奇怪,我無法解釋它。 我不確定我在做什么錯,請您能幫忙嗎? 謝謝。
這是我現在的代碼:
% Generate time series
t = 1:1000;
y1=2*sin(2*pi*t/5);
y2=2*sin(2*pi*t/5 + 2); % y2 has an introduce phase lag of 2
% Plot the two time series
figure (1)
plot (t,y1, 'b-', t,y2, 'r-');
axis ([0 50 -2 2]), grid;
% compute the cross correlation using the function xcorr
maxlag = length(y1); %# set a max lag value here
[c,lags]=xcorr(y1,y2, 'coeff');% compute cross correlation
figure (2);
plot(lags,c)% plot lag versus correlation
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.