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

Click For Summary

Discussion Overview

The discussion revolves around finding the period of an arbitrary periodic function given a vector of approximated data, specifically in the context of using MATLAB. Participants explore methods and algorithms for determining the period from numerical approximations of functions derived from ordinary differential equations (ODEs).

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • Henrik presents a problem of determining the period of a function approximated by numerical methods, specifically asking if there are existing MATLAB functions or algorithms for this task.
  • One participant suggests using the "Lomb-Scargle Periodogram" as a potential solution.
  • Henrik shares a MATLAB script utilizing the Lomb-Scargle Periodogram and reports successful output for a specific case, questioning its general applicability to arbitrary periodic functions.
  • Henrik notes that changing the interval in the script affects the output period, raising concerns about the accuracy and stability of the method.
  • Henrik inquires if there are alternative methods to find the period, such as calculating a mean value, to improve accuracy.
  • A later reply indicates that the problem was resolved without needing to calculate the period using the discussed methods.

Areas of Agreement / Disagreement

Participants express varying degrees of confidence in the Lomb-Scargle Periodogram's effectiveness for arbitrary periodic functions, and there is no consensus on the best method for determining the period, as Henrik continues to seek clarification and alternatives.

Contextual Notes

Henrik's results vary with different intervals, suggesting potential limitations in the method's robustness. The discussion does not resolve the mathematical or algorithmic uncertainties surrounding the period determination.

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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
Replies
15
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K