r/DSP•
jayknow05

Most accurate method of determining frequency and phase shift?

I am using a least squares fit of two input signals of a known frequency to determine phase shift. The frequency has a +/- 10Hz error so as well as fitting for phase, I do another iteration to fit for the exact frequency.

My question is, is this the most accurate way to go about this? Is there another method that is just as accurate and more efficient? Currently the algorithm is implemented in Matlab, but eventually it will need to be an embedded solution.

Posted Nov 17, 2013, 7:49 PM UTC

58
ooterness•

The method you describe should be fine, but computationally expensive. For a real-time application, you can probably get similar performance using a phase-locked loop.

5
jayknow05OP•

I'll definitely look into this. I hadn't thought of using a software PLL.

2
rlbond86•

Do you need to do it online (i.e., with streaming data) or offline (i.e., measure first, then figure it out)?

If it's online, u/ooterness's suggestion to use a PLL is a good one and probably the route I would go.

If offline, I'd do a ML estimate of the frequency first. Then, if you know the frequency f, you can find the phase with atan2(<y, sin(2pift)>, <y, cos(2pift)>).

3
jayknow05OP•

Online is not a requirement, though it may be desirable. I think that I can tightly control the frequency so perhaps the solution you mentioned would be the easiest.

Could you elaborate on the function at the end of your comment, or at least point me in the right direction?

1
rlbond86•

atan2 is the inverse tangent function http://en.wikipedia.org/wiki/Atan2

the inner parts are dot products with sin and cos functions of the same frequency. essentially you get the "real part" from inner product with cos and the "imaginary part" from sin.

For example, if it's cos(2pift + 0) you get atan2(0,1) = 0 degrees if it's cos(2pift + 90 deg) you get atan2(1,0) = 90 degrees

2
necroforest•

Can't you just do a cross correlation on their (complex) signals and look at the phase of that?

2
jayknow05OP•

That was in fact how it was done in a prior iteration. However it took longer than the LSM we're using.

1
DieRaketmensch•

Useful paper on frequency estimation; http://www.ingelec.uns.edu.ar/pds2803/Materiales/Articulos/AnalisisFrecuencial/04205098.pdf

Also, it seems rather obvious that you'll want to get the frequency set first before figuring out the phase offset.

2