MATLAB: Findig period of arbitrary function given a vecor of approximated data

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
4 replies · 10K views
hfrid
Messages
4
Reaction score
0
Problem: Given a vector of approximated output for an arbitrary periodic function, find the function's period.

Example: Let's say we approximate a solution to the ODE

dy/dt = cos(t)

using a numerical method (for example Euler's method or MATLAB's ode45), we will get a vector containing approximated values of y(t) = sin(t) on a given interval. Our problem is to determine the period P (in this example P = 2*pi) of the function approximated in this vector.

Question: How is this problem normally solved? Is there a MATLAB function that solves this problem or is there a general algorithm?

If not, should I simply start writing my own program for identifying periods in a vector of data?

Thanks in advance,
Henrik
 
Physics news on Phys.org
Thanks for your response! I googled Lomb-Scargle Periodogram and found this MATLAB program:

http://www.mathworks.com/matlabcentral/fileexchange/20004-lomb-lomb-scargle-periodogram

I wrote the following script

x = [0:0.01:2*pi]'; y = [sin(x)]';
[f p Prob] = lomb(x,y,4,1);
[~, index] = max(p);
mostCommonFrequency = f(index); mostCommonPeriod = 1/mostCommonFrequency

and my output was "mostCommonPeriod = 6.2800" which was the expected value => it seems to be working!

I am an undergraduate student and will not do Fourier analysis until next semester, so there is no way for me prove that this will work for any periodic function. I simply need an algorithm to utilize without really understanding how it works until next semester. This is why I ask the following question:

Have I used this algorithm correctly?
Will this work for an arbitrary periodic function with some small error?
Is there anything I could do differently?

Thanks in advance,
Henrik
 
Last edited:
I noticed that the value changed when changing the interval. Example: when using

x = [0:0.01:10]';

in the script above, the output is:

mostCommonPeriod = 6.6667

wich has a larger error than when using x = [0:0.01:2*pi]'; When dividing the interval into a larger number of steps MATLAB goes out of memory.

Is there a better method than

[~, index] = max(p); mostCommonFrequency = f(index);

to find the period? Would it be better to calculate a mean value?

Thanks in advance,
Henrik
 
Last edited:
luckily, we managed to solve this problem without having to calculate the period this way.