How can I calculate the frequency when my samples don't span a whole period?

822 Views Asked by At

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?

2

There are 2 best solutions below

4
On BEST ANSWER

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

3
On

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$.