How to calculate period of signal with matlab

Illustration
Teagan - 2021-01-19T14:05:44+00:00
Question: How to calculate period of signal with matlab

Hi , 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

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

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.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!