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

In summary: We used the MATLAB function "lomb()". Lomb() calculates the length of the longest side of a triangle. This length is called the "Lomb-Scargle Periodogram". The "Lomb-Scargle Periodogram" is a graph that shows the frequency of occurrence of the different periods in a given set of data. The "Lomb-Scargle Periodogram" can be used to find the period of a periodic function. The "Lomb-Scargle Periodogram" can be used to find the period of a periodic function even if the data is not in a form that can be analyzed by Fourier analysis.
  • #1
hfrid
4
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
  • #2
Look up "Lomb-Scargle Periodogram".
 
  • #3
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:
  • #4
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:
  • #5
luckily, we managed to solve this problem without having to calculate the period this way.
 

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

How does MATLAB find the period of an arbitrary function given a vector of approximated data?

MATLAB uses a variety of algorithms to analyze the data and determine the underlying periodicity. These algorithms include peak detection, Fourier analysis, and autocorrelation. The specific method used will depend on the nature of the data and the user's input.

Can MATLAB accurately determine the period of non-sinusoidal functions?

Yes, MATLAB has the ability to analyze and find the period of arbitrary functions, including non-sinusoidal ones. However, the accuracy of the determination may depend on the quality and quantity of the data provided.

What is the input required for MATLAB to find the period of an arbitrary function?

MATLAB requires a vector of approximated data points for the function in question. This vector should have a consistent sampling rate and include at least one full period of the function.

Can MATLAB find the period of a function with multiple periods?

Yes, MATLAB can identify and find the period of a function with multiple periods. However, the accuracy of the determination may be affected if the periods are not equally spaced or if there are large variations in the amplitude of the function.

How can I use the period determined by MATLAB in my further analysis or calculations?

MATLAB provides the option to output the period as a variable or to use it directly in further calculations. The user can also use the period to create a new vector with a consistent sampling rate, making it easier to analyze the function in the frequency domain.

Similar threads

Replies
1
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
4
Views
2K
Replies
5
Views
4K
Replies
2
Views
3K
Back
Top