phase-VIV Post

find the phase difference between two singnals

matlab code

% phase lag of sine and cosine function
% https://www.mathworks.com/help/signal/ug/cross-correlation-of-phase-lagged-sine-wave.html
rng default

t = 0:99;
x = cos(2*pi*1/12*t);  % 12 samples in one periods
y = sin(2*pi*1/12*t);
[xc,lags] = xcorr(y,x,24,'coeff');  % '24' equal to 2 periods 

stem(lags(25:end),xc(25:end),'filled')

hold on
plot (t,x)
%plot (t,y)
plot([2.5 2.55],[-1 1])

ax = gca;
ax.XTick = 0:2.5:20;

 

posted @ 2020-04-13 22:10  kaiming_ai  阅读(163)  评论(0编辑  收藏  举报