lag time in matlab
Afficher commentaires plus anciens
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)]);
Réponses (1)
nadom mutlib
le 16 Mar 2014
0 votes
use cross correlation function it is easier. xcorr(x,y).
Catégories
En savoir plus sur Elementary Math dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!