MATLAB: How to calculate period of signal with matlab

periodsignalSignal Processing Toolbox

Hi everybody, I have the signal x2(t)=|cos(10*pi*t)|.How can i calculate its period with matlab?I am new matlab so each help will be usefull

Best Answer

use autocorrelation. If your data is periodic you should get high correlation once the lag time matches the period. here is an example:
x=0:0.1:20*2*pi;
y=sin(x); % so we know the period is 2*pi roughly 6.28
ac=xcorr(y,y);
[~,locs]=findpeaks(ac);
mean(diff(locs)*0.1)
ans =
6.2842
In a more complex data set including some noise you need to work around the find peaks a little bit. That might be too noisy.
In the example you gave here is what you will get
x=0:0.01:20*2*pi;
y=abs(cos(10*pi*x));
ac=xcorr(y,y);
[~,locs]=findpeaks(ac);
mean(diff(locs)*0.01)
ans =
0.1000
Another approach is using FFT, particularly if you have a more complex signal.
Related Question