lag time in matlab

조회 수: 6 (최근 30일)
Susan
Susan 2011년 8월 2일
답변: nadom mutlib 2014년 3월 16일
hey, I researched how to find the lag time in Matlab and I found a code that worked for the online example, but did not calculate the correct lag in mine.. I have two signal that are 2x100 size both and one is delayed version of other. The code though its complicated a bit, Is there a quicker way in Matlab to calculate the lag time, any in-built function?
mxlag=100; % Make a guess
R=zeros(2*mxlag+1,1);
for ilag=1:mxlag
t1=detrend(X(1:end-ilag),0); % Remove mean
t2=detrend(X1(ilag+1:end),0);
R(ilag+mxlag+1)=mean(t1.*t2)/(std(t1)*std(t2));
t1=detrend(X1(1:end-ilag),0);
t2=detrend(X(ilag+1:end),0);
R(mxlag+1-ilag)=mean(t1.*t2)/(std(t1)*std(t2));
end
% Zero lag
t1=detrend(X,0);
t2=detrend(X1,0);
R(mxlag+1)=mean(t1.*t2)/(std(t1)*std(t2));
lag=[-mxlag:mxlag]';
[Rmx,imx]=max(R);
num2str(lag(imx)*pi);
disp(['The calculated lag is: ' num2str(lag(imx)*pi)]);

답변 (1개)

nadom mutlib
nadom mutlib 2014년 3월 16일
use cross correlation function it is easier. xcorr(x,y).

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by