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

AI Thread Summary
To determine the period of an arbitrary periodic function from a vector of approximated data in MATLAB, the Lomb-Scargle Periodogram is a recommended method. A user successfully implemented this approach, yielding the expected period for a sine function. However, they noted discrepancies in results when altering the data interval, leading to concerns about accuracy and memory issues with larger datasets. Questions arose regarding the effectiveness of the method and potential alternatives, such as calculating a mean value. Ultimately, the user found a solution without needing to calculate the period through this method.
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
Look up "Lomb-Scargle Periodogram".
 
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.
 
Back
Top