我有两个时间序列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