DSPRelated.com
Forums

Accurate frequency measurement problem

Started by Unknown February 11, 2016
W dniu czwartek, 11 lutego 2016 17:22:05 UTC użytkownik Tim Wescott napisał:
> On Thu, 11 Feb 2016 07:33:24 -0800, a.turowski wrote: > > > W dniu czwartek, 11 lutego 2016 13:42:02 UTC użytkownik > > mako...@yahoo.com napisał: > >> On Thursday, February 11, 2016 at 7:14:42 AM UTC-5, Tauno Voipio wrote: > >> > On 11.2.16 12:21, a.turowski@ymail.com wrote: > >> > > Hi all, > >> > > > >> > > Recently I've been faced with a problem of very accurate sine wave > >> > > frequency measurement. Let me give you some details: > >> > > I've got a sensor which outputs measurement result as a frequency > >> > > of a sine wave. The frequency of the signal is within 149.4kHz - > >> > > 150.6kHz range and is very stable, as sensed parameter changes very > >> > > slowly. Say the frequency can change no more than tens of ppb > >> > > (parts per billion) per second. Also the signal amplitude should be > >> > > very stable - it may vary very slowly with temperature. The goal is > >> > > to measure the frequency to 10-100ppb accuracy at least every > >> > > second - it may be just a frequency change or if possible, absolute > >> > > frequency value. Lets denote the frequency we want to measure as f. > >> > > > >> > > I spent some time thinking about a solution and here is the idea I > >> > > came up with. Lets assume that I undersample the signal using 5kHz > >> > > sampling frequency. Then I use FFT to estimate roughly what the > >> > > signal frequency is. Lets denote it as f_approx. Using automatic > >> > > gain control I make sure that incoming signal has known and stable > >> > > amplitude. Lets denote this signal as sig_in_agc. In digital domain > >> > > I generate a sine wave of frequency f_approx and the same amplitude > >> > > as sig_in_agc. Lets denote this signal as sig_approx. Next step is > >> > > to multiply sig_in_agc by sig_approx. This is a standard mixing, > >> > > which gives me a signal which is the sum of two cosines: one having > >> > > frequency equal to f_approx+f, the other f_approx-f. Then I filter > >> > > out the high frequency component with low pass filter and as a > >> > > result I get only a signal which frequency is the difference > >> > > between f_approx-f. Lets denote it f_diff. Actually this signal > >> > > represents the instantaneous phase difference between sig_in_agc > >> > > and sig_app > >> > rox. I sample this phase difference periodically and then can > >> > calculate the f_diff as a derivative over time of the phase > >> > difference. > >> > > > >> > > Do you think that above makes any sense? Are there other (better) > >> > > methods that you can recommend to measure the frequency accurately? > >> > > > >> > > Best regards, > >> > > Adam Turowski > >> > > >> > > >> > How about getting a reference-quality 150 kHz complex oscillator and > >> > doing I/Q mixing with it? You'll get an analytic signal (two > >> > channels) > >> > of -600 Hz to 600 Hz, which should then be sampled with good > >> > high-resolution A/D converters. > >> > > >> > You have to follow the phase of the signal to get ppb frequency > >> > changes every second. > >> > > >> > Your frequency reference will be critical at ppb accuracy levels. > >> > > >> > -- > >> > > >> > -Tauno Voipio > >> > >> right.. > >> > >> OP...fundamentally, if you are measueing the absolute frq, you will > >> need a reference with accuracy better than what you are trying to > >> read.... > >> > >> or > >> > >> if you are measuring only changes, then you will still need a reference > >> with STABILITY better than what you are trying to read. > >> > >> next, is filter the BW to as low as possible, if the changes are slow, > >> some type of PLL or tracking filter where the loop BW is very narrow. > >> > >> no free lunch > >> > >> M > > > > Hi all, > > > > Thank you for the responses. Yes, I realize that the frequency reference > > is critical here (or at least its short term stability if I only measure > > frequency changes). > > > > Evgeny, > > > > Thank you for the hint about noise increase when doing undersampling. I > > think I will have to consider using say 1MHz sampling frequency and then > > down-converting, low pass filtering and decimating in the digital > > domain. > > > > Tauno, > > I think that using external analog I/Q mixer may not be a very good idea > > in my application. The reason is that I have to be measure the phase > > very precisely and I feel that having to have two mixers (one for I the > > other for Q) will introduce phase mismatches obscuring actual > > measurement. Anyway, thanks for the suggestion. > > I think you're best off to keep things in the digital domain as much as > possible. If you need mixing, do it in digital-land. > > > Mako, > > I fail to see how PLL would help me in solving the problem. I understand > > that one could infer the phase difference between signals from the > > voltage/signal driving VCO/NCO, but it wouldn't be easy. I think that > > the solution I've proposed originally would give me the same answer > > without having to go through PLL behavior analysis (this is usually a > > very hard to crack problem). > > Phase-locked loop analysis is _easy_ if you have the chops. Lock to the > signal, then "infer" the frequency by looking at the frequency of your > reference. > > I don't think you need a super-fancy PLL here. > > > Any other ideas? > > Get a good book on PLL theory and read it. > > -- > > Tim Wescott > Wescott Design Services > http://www.wescottdesign.com
Hi Tim, Can you recommend any good book on PLL theory and/or DPLL design? Best regards, Adam
I'm surprised no one has mentioned using an fft with interpolation. So my recipe would be

Use an audio-class signs delta a/d. You can get over 100 db SNR for cheap 

Apply band pass filter to clean it up

Optionally digitally low pass filter and decimate 

Take windowed fft

Find fft peak

Fit the peak and the upper and lower neighbors with a polynomial (fit magnitude only)

Find where the derivative of the polynomial is 0. This is your frequency. 

This is a very standard method and you can find the formulas in the archives of comp.dsp. 

What I'm less sure about is the accuracy when you only use 3 fft bins to fit. It may be that you need to use 5 bins (the peak and the 2 upper and 2 lower neighbors). I haven't crunched the math for that case so I don't know how complicated it would be. 

You can increase the accuracy of the  fit by using an fft longer than 1second. You can zero-pad the input buffer to get a longer fft , and this will minimize the frequency estimation errors in your polynomial fit routine.  So it may make more sense to blow up the fft and stick with a simple 3-point polynomial fit. 

Bob

Bob
Eric Jacobsen <eric.jacobsen@ieee.org> wrote:

>On Thu, 11 Feb 2016 22:31:21 +0000 (UTC), spope33@speedymail.org
>><a.turowski@ymail.com> wrote:
>>>Mako, >>>I fail to see how PLL would help me in solving the problem.
>>That's right, a PLL does not help solve this problem. You do >>not need to track this sinusoid; you do not need to generate >>a clock with a defined relationships to the sinusoid. You do >>not need/want a PLL.
>Actually, a properly designed PLL provides everything he needs and >more, so I don't see how it does not help solve the problem. >Depending on details it might not be the most efficient solution (I >don't think we know enough to know whether it is or isn't), but from >what's been given I think your statement is incorrect.
Well, my instinct is to not use a feedback-based algorithm in a situation that can be fully addressed with a feed-forward algorithm. In this particular problem, a PLL will always have a small amount of frequency wander that needs to be damped or otherwise minimized (again, because of the feedback inherenet in a PLL) and I do not see why the designer would want to buy into this sort of artifact when they don't have to. Maybe I am missing something however. Steve
<a.turowski@ymail.com> wrote in message 
news:52214a5d-2ced-4e41-b16b-074b3a32b04d@googlegroups.com...
Recently I've been faced with a problem of very accurate sine wave frequency 
measurement. Let me give you some details:
I've got a sensor which outputs measurement result as a frequency of a sine 
wave. The frequency of the signal is within 149.4kHz - 150.6kHz range and is 
very stable, as sensed parameter changes very slowly.

-----ooooo-----

At those frequencies, measure them with an on-chip counter/timer and use an
ovenned or GPS-locked crystal oscillator for the clock of the CPU.


On 12.2.16 14:28, radams2000@gmail.com wrote:
> I'm surprised no one has mentioned using an fft with interpolation. So my recipe would be > > Use an audio-class signs delta a/d. You can get over 100 db SNR for cheap > > Apply band pass filter to clean it up > > Optionally digitally low pass filter and decimate > > Take windowed fft > > Find fft peak > > Fit the peak and the upper and lower neighbors with a polynomial (fit magnitude only) > > Find where the derivative of the polynomial is 0. This is your frequency. > > This is a very standard method and you can find the formulas in the archives of comp.dsp. > > What I'm less sure about is the accuracy when you only use 3 fft bins to fit. It may be that you need to use 5 bins (the peak and the 2 upper and 2 lower neighbors). I haven't crunched the math for that case so I don't know how complicated it would be. > > You can increase the accuracy of the fit by using an fft longer than 1second. You can zero-pad the input buffer to get a longer fft , and this will minimize the frequency estimation errors in your polynomial fit routine. So it may make more sense to blow up the fft and stick with a simple 3-point polynomial fit. > > Bob
An audio class A/D does not work on 150 kHz. The OP ruled out analog mixing. For a known single frequency, FFT is not the solution. A much simpler complex number phase detection will do after initiali acquisition. -- -TV
On Fri, 12 Feb 2016 12:28:43 +0000 (UTC), spope33@speedymail.org
(Steve Pope) wrote:

>Well, my instinct is to not use a feedback-based algorithm in a >situation that can be fully addressed with a feed-forward >algorithm. > >In this particular problem, a PLL will always have a small amount >of frequency wander that needs to be damped or otherwise minimized >(again, because of the feedback inherenet in a PLL) and I do >not see why the designer would want to buy into this sort of >artifact when they don't have to. >
I agree with that. PLL technology is good for digging a single frequency out of the noise. But here there is almost no noise, and cycles can be counted directly. The frequency can be calculated from a single phase measurement (not much CPU overhead) once per second, along with cycle counting. The cycle counting gives the whole number number of cycles of the 150kHz signal and the phase measurements give the fractions of cycle. As long as the phase measurements once per second can be made with an accuracy of 2.7 degrees of a cycle, you will have your 100 ppb frequency accuracy, with no need for feedback and loop stability and locking concerns. Each one second frequency measurement will depend only on the frequency during that one second and not at all on what went before it. You cannot say that of the PLL. Direct measurement is the most responsive to changes in frequency. To measure phase to within 2.7 degrees, you could sample the sine-wave signal at 1MHz for 10 msec every second (10,000 samples). This would cover about 1500 cycles of the sensor signal. From these 10,000 samples, correlate with sine and cosine and use atan2 to get the phase. The sine and cosine would be from a digitally synthesized reference frequency that was calculated from the whole number of cycles counted during the past one second. -Robert Scott Hopkins, MN
> > >Well, my instinct is to not use a feedback-based algorithm in a > >situation that can be fully addressed with a feed-forward > >algorithm. > > >
Everyone sees the advantage a reducing the bandwidth to reduce noise. You reduce the BW as much as possible before sampling but that BW needs to be at least as wide as the expected RANGE of the input signal. The advantage of a tracking loop (feedback PLL) is that you can further reduce the BW since this narrow BW tracks the frequency as it moves. THe BW of the tracking filter needs to be only sufficently wide to track the RATE of movement. The pre filter needs to be sufficently wide to track the RANGE of movment. If the RATE is << the RANGE, then a tracking filter can be very helpful to increase the SNR by reducing the BW and hence noise. A PLL is one way to implement a tracking filter. If the input signal is really noiseless, this is all moot. M
Mis-read the frequency as 150 Hz. But anyway I still think the tried-and true FFT method is very robust

Bob

On Friday, February 12, 2016 at 8:35:44 AM UTC-5, Tauno Voipio wrote:
> On 12.2.16 14:28, radams2000@gmail.com wrote: > > I'm surprised no one has mentioned using an fft with interpolation. So my recipe would be > > > > Use an audio-class signs delta a/d. You can get over 100 db SNR for cheap > > > > Apply band pass filter to clean it up > > > > Optionally digitally low pass filter and decimate > > > > Take windowed fft > > > > Find fft peak > > > > Fit the peak and the upper and lower neighbors with a polynomial (fit magnitude only) > > > > Find where the derivative of the polynomial is 0. This is your frequency.
> > > > This is a very standard method and you can find the formulas in the archives of comp.dsp. > > > > What I'm less sure about is the accuracy when you only use 3 fft bins to fit. It may be that you need to use 5 bins (the peak and the 2 upper and 2 lower neighbors). I haven't crunched the math for that case so I don't know how complicated it would be. > > > > You can increase the accuracy of the fit by using an fft longer than 1second. You can zero-pad the input buffer to get a longer fft , and this will minimize the frequency estimation errors in your polynomial fit routine. So it may make more sense to blow up the fft and stick with a simple 3-point polynomial fit. > > > > Bob > > > An audio class A/D does not work on 150 kHz. The OP ruled out analog > mixing. > > For a known single frequency, FFT is not the solution. A much simpler > complex number phase detection will do after initiali acquisition. > > -- > > -TV
On Fri, 12 Feb 2016 07:04:50 -0800 (PST), makolber@yahoo.com wrote:

> >>=20 >> >Well, my instinct is to not use a feedback-based algorithm in a=20 >> >situation that can be fully addressed with a feed-forward >> >algorithm. >> > >> > >Everyone sees the advantage a reducing the bandwidth to reduce noise.=20 >You reduce the BW as much as possible before sampling but that BW needs to = >be at least as wide as the expected RANGE of the input signal. > >The advantage of a tracking loop (feedback PLL) is that you can further red= >uce the BW since this narrow BW tracks the frequency as it moves. THe BW o= >f the tracking filter needs to be only sufficently wide to track the RATE o= >f movement. The pre filter needs to be sufficently wide to track the RANGE= > of movment. If the RATE is << the RANGE, then a tracking filter can be ve= >ry helpful to increase the SNR by reducing the BW and hence noise. A PLL i= >s one way to implement a tracking filter. >
Any advantage you can gain in S/N with a PLL you can also gain with proper filtered phase detection in a totally feed-forward process. Plus the feed-forward design gives you: 1. Instant signal acquisition on start-up (no lock-up problem) 2. No need for careful loop dynamics trimming. 3. Lowest possible latency between frequency change and detection. -Robert Scott Hopkins, MN
On Fri, 12 Feb 2016 08:03:37 -0800 (PST), radams2000@gmail.com wrote:

>Mis-read the frequency as 150 Hz. But anyway I still think the tried-and tr= >ue FFT method is very robust > >Bob
It is, and, for obvious reasons, I'm usually a big advocate of this approach. To get to 10ppb this way, though, might be a stretch. If the observation window is only a second, the interpolator has to increase the estimation accuracy from the 1Hz bin with to 10ppb, which is asking a lot. Increasing the observation window by a factor of N also increases the FFT size by a factor of N, so that's not necessarily a happy trend. Anything can be made to work, but I think in this case other techniques beckon. Eric Jacobsen Anchor Hill Communications http://www.anchorhill.com