0

I am taking samples at 30Hz of a signal which is a slowly-varying sinewave.

The period of the sinewave is expected to drift slowly, but will always be somewhere between 0.5s and 2s.

I would like calculate a estimate of the period/frequency of the sinewave, from just the last 1s of data (i.e. the last 30 samples).

I've tried Discrete Fourier Transform, but from what I can tell it doesn't behave well when you have less than a whole cycle sampled.

A naive approach is just to measure the time since the amplitude was roughly where it is at the current sample (two times ago), but that will get fiddly if I happen to be exactly at a maxima with the current sample.

Are there any other approaches I should be trying?

dbruning
  • 103

2 Answers2

0

The fitting to experimental data of the function : $$y(x)=a+b\cos(\omega x)+c \sin(\omega x)$$ or $$y(x)=a+\rho\sin(\omega x+\varphi)$$ can be carried out thanks to the a method based on integral equation : https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

(in French, presently no translation available) Nevertheless, the synopsis of equations is legible pages 35-36.

The method is convenient especially for data covering only a small part of period.

Also, a specific part of the paper deals with damped sinusoidal regression : $$y(x)=\rho\sin(\omega x+\varphi)e^{\alpha x}$$ in English, pages 64-67.

A numerical example is included in the referenced paper :

The data is :

-1.983 , 0.936

-1.948 , 0.81

-1.837 , 0.716

-1.827 , 0.906

-1.663 , 0.247

-0.815 , -1.513

-0.778 , -1.901

-0.754 , -1.565

-0.518 , -1.896

0.322 , 0.051

0.418 , 0.021

0.781 , 1.069

0.931 , 0.862

1.51 , 0.183

1.607 , 0.311

Equations (12), (13) yield $S_k$ and $SS_k$ :

enter image description here

Equations (15), (16) yield $\omega_1, a_1, b_1, c_1$ :

enter image description here

Then, equations (18), (19) , (20) yield $\rho_1 , \phi_1 , \Phi_k , K_k , \theta_k$ :

enter image description here

Equations (21), (22) yield $\omega_2 , \phi_2$ , with $a_2=a_1$ and $b_2=\rho_2\cos(\phi_2) \: ; \: c_2=\rho_2\sin(\phi_2)$ :

enter image description here

Finally, with $\omega_3=\omega_2$ , equation (23) yields $a_3 , b_3 , c_3$ which are approximates of $\omega , a , b , c$ :

enter image description here

JJacquelin
  • 66,221
  • 3
  • 37
  • 87
  • Thanks for your answer. I tried to work through the method in the document using Excel (and using the input data from page 23 of that document). However, when I feed the inputs (x) back through the formula with the coefficients resulting from the algorithm, they don't look anything like the y values of the original data. I don't suppose you have any fully worked examples for that algorithm? – dbruning Jul 08 '15 at 05:32
  • @dbruning : a full worked example is given in the referenced paper, pages 21-32. The copy of this example is now added to my first answer. If you need more explanation I will be again available within about one month because now I am on the verge to go abroad. – JJacquelin Jul 08 '15 at 08:20
  • I appreciate those additional workings - I was able to confirm my workings were correct up until stage 3. When you're back from your holiday, would you mind also posting the values for the final matrix multiplication to actually generate a3, b3 and c3? Also - if you happen to be holidaying in NZ, let me know and I'll buy you a beer. – dbruning Jul 08 '15 at 23:03
  • Never mind the final values - when I implemented this in code, it worked out correctly, so must have been an Excel error on my part. Accepting this answer - thanks for your help! – dbruning Jul 12 '15 at 20:46
0

Once again, JJacquelin came with a nice answer based on a direct solution of the problem.

As said, the problem of fitting (in the least square sense) a model such as $$y=a+b\cos(\omega x)+c \sin(\omega x)$$ based on $(x_i,y_i)$ data points is simple if $\omega$ is known; in such a case, the problem reduces to a multilinear regression and solves immediately. The problem is much more complex if $\omega$ is not known and would involve nonlinear regression which required "good" starting values.

So, let us assign a given value to $\omega$; perform the linear regression which gives $a(\omega)$, $b(\omega)$, $c(\omega)$ and $SSQ(\omega)$. Try with different values of $\omega$ (marching using a small fixed stepsize) until you identify a minimum of $SSQ(\omega)$. At this point, you are ready for the nonlinear regression.

For illustration purposes, I used the data given in page 23 of JJacquelin's book (I take the opportunity of this post to thank him from providing me an easy access to the data) and I varied $\omega$ from $0$ by steps of $0.1$. I reproduce below the sums of squares around the optimum

1.50         3.8688
1.60         2.8146
1.70         1.7823
1.80         0.9409
1.90         0.4405
2.00         0.3261
2.10         0.5258
2.20         0.9282
2.30         1.4761
2.40         2.2159
2.50         3.2727   

For $\omega=2$, we have $a=-0.3979$, $b=1.2831$, $c=-0.5736$. Starting the nonlinear regression using these estimates, the convergence is really fast and the solution is $a=-0.3907$, $b= 1.2893$, $c=-0.5717$, $\omega=1.9813$ corresponding to a sum of squares equal to $0.3204$.

All of the above can easily be done using Excel.

Edit

If I repeat the same process using only the data points corresponding to $x_i<0$ (they then cover less than a period), the results are "quite" similar : the preliminary step shows a minimum for $\omega =1.7$ and the nonlinear regression leads to $a=-0.3820$, $b= 1.0958$, $c=-1.0378$, $\omega=1.7430$.

  • Thankyou for your answer. I understand the concept, but I'm not sure how to "perform the linear regression", can you provide more information there , or even show more of the workings you used to get those results? – dbruning Jul 08 '15 at 05:29
  • If $\omega$ if fixed, then the model write $y=a+b w+ c z$ with $w_i=\cos(\omega x_i)$ and $z_i=\sin(\omega x_i)$. So, $a,b,c$ are immediately obtained using a multilinear regression (define the new regressors) as well as the sum of squared errors. If you want, send me a sample of your data in a .TXT file (my e-mail address is in my profile); in such a way, you would probably better see (I hope). – Claude Leibovici Jul 08 '15 at 05:40
  • Thanks for the offer, the other answer gave a great result without having to iterate, so I've accepted that. Good to know that your approach would also work. – dbruning Jul 12 '15 at 20:48