Author Topic: Signal processing - getting exact frequency from short ADC sample  (Read 9449 times)

0 Members and 1 Guest are viewing this topic.

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #50 on: December 17, 2019, 03:22:00 pm »
He isn't suggesting just downmixing it, he's suggesting downmixing it by sines in quadrature.

I think after low pass filtering, the phase of the quadrature results treated as a complex vector will give you the frequency shift (side effect of the PM/FM equivalence).
Downmixing, then measuring phase do not make any sense - if you can use same (phase) math on carrier directly. To avoid gigantic phase numbers that multiple times exceeds 2*PI you do not need to use downmixing. Just use your head.
« Last Edit: December 17, 2019, 03:29:19 pm by ogden »
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6746
  • Country: nl
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #51 on: December 17, 2019, 04:22:53 pm »
You can, but at least for low SNR signals you can't get near the error bound with a weighted linear predictor. I'm not sure the quadrature mixer method can of course.

I'm also not sure how relevant using near optimal algorithms is at high SNR.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #52 on: December 17, 2019, 04:26:08 pm »
You can, but at least for low SNR signals you can't get near the error bound with a weighted linear predictor. I'm not sure the quadrature mixer method can of course.
If you signal is noisy - apply filter.
 

Online Berni

  • Super Contributor
  • ***
  • Posts: 4997
  • Country: si
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #53 on: December 17, 2019, 05:00:23 pm »
But still i think OP is looking at the problem from the wrong direction. If you use a quadrature mixer to convert the 100.1KHz signal down to a pair of 100Hz signals things get a lot easier (Its essentially a software defined radio at this point). Not only is this computationally cheap to do, but unlike his method of taking 1 second long 1MSPS recordings of the signal and processing them later, this downconversion method can also operate continuously on a signal, giving you a result on every sample rather than just one sample per second.
I am afraid that you drive OP into wrong direction as well. Estimating precise frequency of downmixed 100Hz do not seem to be simpler than just counting zero crossings of "carrier".

I am not saying it is simpler than counting zero crossings. Im saying that doing it using downconversion offers a lot of advantages like being computationally cheap, resilient to noise, offering a lot of measurements per second, able to work on very short captures of the signal (few ms rather than needing a full second of data), able to continuously pipeline data trough it rather than process it as one by one 1 second long recordings. All of that while providing well under 1 Hz resolution and involving only high school level math. Im sure there plenty more advanced ways to do this that might perform even better, but this one has quite a lot of pros versus cons.

Downmixing, then measuring phase do not make any sense - if you can use same (phase) math on carrier directly. To avoid gigantic phase numbers that multiple times exceeds 2*PI you do not need to use downmixing. Just use your head.

The point of down-mixing here is as Marco said is to easily convert the real input signal into a pair of quadrature I/Q signals. Advantage of these quadrature signals being that its possible to compute the phase by looking at just 1 sample. No need to see a zero crossing, pick any random point on the sinewave and just look at that  one sample and you will know the exact phase of it by using trigonometry. Its not the only way to get a I/Q signal from it but its a pretty attractive one because choosing a carrier frequency that is close lets you downsample the signal afterwards, as a result reducing your computational requirements while retaining the accuracy and noise resilience. Since phase and frequency are bound together by time means if you know the phase in two spots you also know the frequency. You can chose these two points anywhere along the data, the farther apart you place them the more area you will average between them and the more resolution and noise resilience you have (Tho you do have to phase unwrap the signal since it jumps back around at 360 deg)

What method do you propose as being better or simpler than this?
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14366
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #54 on: December 17, 2019, 05:12:33 pm »
The down-mixing with a quadrature mixer is mathematical similar to the Hilbert transformation. It can be a relative fast (less computational effort) way and can still be close to the optimum, at least for longer data sets. The reduced data volume is only second to getting the phase information. However there no need to get the phase information for really every point of the original data set. The phase data are smoothed anyway. So one could as well use the reduced number of points without loosing much information.
A nice point about the down mixing is that this part can be done while the data are coming in and there is no need to store to whole data set. This is not so relevant here with a short data set, but it can be with 1 second or more at 1MSPS.

The down conversion method is also quite simple, especially with a background from EE.
The full nonlinear fit gets a better result, but with more effort. The math behind it is still not that complicated. Finding an efficient algorithm can be some extra effort.

Filtering can remove out of band noise, but many of the methods discussed here (least square fit, Hilber transformation / down mixing and FFT and interpolation) are not sensitive to out of band noise anyway. So with these method an extra filtering run does not help or change a thing.

Even with relatively good data the SNR can be relevant, as noise in the input data translates to noise in the frequency reading. From the Fit data it takes at least some 80 dB SNR to get 1 ppm frequency resolution or 60 dB to get the 0.1 Hz target. There is a point at rather low SNR that some of the methods may fail and could produce biased or totally off values. This tends to happen when the noise is no longer a small distortion in the linear range. So one might miss whole periods or see ambiguities in  2 pi steps in the phase.
From the linked paper about FFT interpolation methods it looks like not so good method add a more or less constant factor to the noise, e.g. giving 2 or 3 times the frequency noise of the near optimum ML estimate.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #55 on: December 17, 2019, 05:43:07 pm »
Im saying that doing it using downconversion offers a lot of advantages like being computationally cheap
Wrong. Other methods requires just single filter. IQ downmixer requires not only two mixers but two decimating filters as well.

Quote
resilient to noise
Compared to unfiltered signal - yes. As I said - other methods can and shall use filter as well.

Quote
offering a lot of measurements per second
Much less measurements per second than direct phase estimator I mentioned in my first post.

Quote
able to work on very short captures of the signal (few ms rather than needing a full second of data)
Nonsense argument. There is no other method which would need/require full second of data.

Quote
able to continuously pipeline data trough it rather than process it as one by one 1 second long recordings.
Nonsense again. Phasor angle estimator and even zero crossings counter can be run continuously. As I said - my proposal is the same, just do not need two mixers and two filters, needs just one filter. Dont you see.

Quote
The point of down-mixing here is as Marco said is to easily convert the real input signal into a pair of quadrature I/Q signals. Advantage of these quadrature signals being that its possible to compute the phase by looking at just 1 sample.
Looking at 1 sample (angle difference between two actually) do not achieve meaningful resolution.

Quote
No need to see a zero crossing, pick any random point on the sinewave and just look at that  one sample and you will know the exact phase of it by using trigonometry.
I do not see this as an argument. If filtering, counting zero crossings, calculating phase shift for sine waveform appears problem for someone then I doubt that he will succeed implementing IQ downmixer with two decimator filters, then doing essentially the same - estimating phase shift between two or more IQ samples. Complexity while doing math with single sine compared to two (IQ) is not much different. You just propose to add completely superflous step - downmixing.

Your method have huge drawback - it's frequency range is kinda limited.

[edit] Paper that compares many methods mentioned in this thread: https://www.researchgate.net/publication/321255243_Power_System_Frequency_Measurement_for_Frequency_Relaying

Following are mentioned:

Modified zero-crossing methods [4], [3], [44], [52], [53]
DFT with compensation [23], [28], [65], [68]
Orthogonal decomposition [40], [55], [59]
Signal demodulation [2], [11]
Phase locked loop [12], [16], [27]
Least square optimization [7], [34], [49], [62]
Artificial intelligence [8], [13], [30], [32], [45], [58]
Wavelet transform [9], [36], [35], [31], [64]
Quadratic forms [29], [30]
Prony method [38], [42]
Taylor approximation [51]
Numerical analysis [67]
« Last Edit: December 17, 2019, 06:04:47 pm by ogden »
 

Online Berni

  • Super Contributor
  • ***
  • Posts: 4997
  • Country: si
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #56 on: December 17, 2019, 07:32:44 pm »
Quote
No need to see a zero crossing, pick any random point on the sinewave and just look at that  one sample and you will know the exact phase of it by using trigonometry.
I do not see this as an argument. If filtering, counting zero crossings, calculating phase shift for sine waveform appears problem for someone then I doubt that he will succeed implementing IQ downmixer with two decimator filters, then doing essentially the same - estimating phase shift between two or more IQ samples. Complexity while doing math with single sine compared to two (IQ) is not much different. You just propose to add completely superflous step - downmixing.

Your method have huge drawback - it's frequency range is kinda limited.

[edit] Paper that compares many methods mentioned in this thread: https://www.researchgate.net/publication/321255243_Power_System_Frequency_Measurement_for_Frequency_Relaying

Following are mentioned:

Modified zero-crossing methods [4], [3], [44], [52], [53]
DFT with compensation [23], [28], [65], [68]
Orthogonal decomposition [40], [55], [59]
Signal demodulation [2], [11]
Phase locked loop [12], [16], [27]
Least square optimization [7], [34], [49], [62]
Artificial intelligence [8], [13], [30], [32], [45], [58]
Wavelet transform [9], [36], [35], [31], [64]
Quadratic forms [29], [30]
Prony method [38], [42]
Taylor approximation [51]
Numerical analysis [67]

That paper is an excellent find.

It shows these methods being fed sinewaves with various types of noise and distortion applied to them. One of them being my proposal that is here named as "Signal demodulation". On page 13 and on you will find figures 9 to 17 showing graphs of the results, notice how graph D (showing the demodulation method) is always rock solid on the right frequency no matter what kind of noise is injected into the signal, nor does it show any quantization steps.

Using a FIR bandpass filter is more computationally expensive than the entire quadrature mixing process. Yes you do need to compute the mixers for every input sample to get all of the noise rejection benifits, but this cost is 2 MAC operations for the I and Q mix, and 2 additions with 2 sine table lookups for generating the mixers local oscillator. Downsampling only costs one bitshift every 1024 samples, turning this into a phase angle does require annoyingly slow division along with another trigonometry table lookup, but this is done at the slow rate so it all costs the equivalent computing power of about 0.05 of a MAC operation per input sample. So what sort of FIR filter can you build out of about 3 MAC and 2 sum and 2 lookup operations per sample?

Yes with downsampling you are looking at a narrow window, but this is a good thing because it rejects any frequencies out of this band so its an advantage not a hindrance, you can still not downsample and then get the full 500KHz of bandwith with the reduced noise immunity and higher computing cost that comes with that, but you do get 1 000 000 frequency measurements per second(Noise free too as long as your phase window is large enugh). Whats even better is that the band of interest can be moved around by simply changing the rate of incrementing trough the sine table (a FIR filter needs new coefficients for this) and multiple sets of mixers can be used to track two or more doppler targets in the same signal (Other methods require FFT of filters to separate multiple sinewaves before measurement).

As for the Phasor angle estimator, i agree. If you convert the signal into a phasor you know its exact frequency and job done. However can you recommend a simple and reliable algorithm for turning ADC samples into a phasor?

I'm sorry if i am being annoying with this, not trying to argue or anything but just trying to get on the same page with this phasor approach.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #57 on: December 17, 2019, 08:18:13 pm »
As for the Phasor angle estimator, i agree. If you convert the signal into a phasor you know its exact frequency and job done. However can you recommend a simple and reliable algorithm for turning ADC samples into a phasor?
Cartesian to polar coordinate transform. I think paper in the link below may answer this question as well.

Quote
I'm sorry if i am being annoying with this, not trying to argue or anything but just trying to get on the same page with this phasor approach.
Don't be sorry at all. This is interesting topic, thank you for arguing. I believe that there is no single "ultimate" solution, every approach may have it's strong and weak points. I think following paper will give some insight into phasor approach. https://www.researchgate.net/publication/323628162_Implementation_Techniques_for_Frequency_Phasor_Estimation_in_Phasor_Measurement_Units_PMUs
 

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 1934
  • Country: us
    • KE5FX.COM
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #58 on: December 17, 2019, 08:36:15 pm »
He isn't suggesting just downmixing it, he's suggesting downmixing it by sines in quadrature.

I think after low pass filtering, the phase of the quadrature results treated as a complex vector will give you the frequency shift (side effect of the PM/FM equivalence).
Downmixing, then measuring phase do not make any sense - if you can use same (phase) math on carrier directly. To avoid gigantic phase numbers that multiple times exceeds 2*PI you do not need to use downmixing. Just use your head.

Optimizing the SNR performance of this sort of measurement usually comes down to reducing the measurement bandwidth, given that the target signal is a narrowband signal embedded in noise whose spectrum is potentially (DC-daylight].  It's easy to implement a narrowband filter near DC, not so easy to implement it at any arbitrary RF carrier frequency. 

This is as true nowadays as it was for Major Armstrong in 1918.
« Last Edit: December 19, 2019, 07:17:55 pm by KE5FX »
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #59 on: December 17, 2019, 08:50:23 pm »
Optimizing the SNR performance of this sort of measurement usually comes down to reducing the measurement bandwidth, given that the target signal is a narrowband signal embedded in noise whose spectrum is potentially (DC-daylight].  It's easy to implement a narrowband filter near DC, not so easy to implement it at any arbitrary RF carrier frequency. 

This is is true nowadays as it was for Major Armstrong in 1918.
Near DC means very limited (narrow) range of input frequencies, big group delays of filters, thus long sampling/processing periods. If this method is so good for RF, then why all frequency counters uses zero crossing count method instead? ;)
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14366
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #60 on: December 17, 2019, 09:25:54 pm »
Optimizing the SNR performance of this sort of measurement usually comes down to reducing the measurement bandwidth, given that the target signal is a narrowband signal embedded in noise whose spectrum is potentially (DC-daylight].  It's easy to implement a narrowband filter near DC, not so easy to implement it at any arbitrary RF carrier frequency. 

This is is true nowadays as it was for Major Armstrong in 1918.
Near DC means very limited (narrow) range of input frequencies, big group delays of filters, thus long sampling/processing periods. If this method is so good for RF, then why all frequency counters uses zero crossing count method instead? ;)

Filtering the signal to a narrow band does not have to run as a classical FIR or similar filter. Frequency sensitivity can be a inherent more hidden feature. If one is only interested in the frequency one does not care about group delays per se. However the group delays have to be kept in mind when using a classical narrow band filter, especially for the important beginning and end. The data points at the ends are the most valuable. Use them just for filter settling is a bad idea.

The usual frequency counters use the zero crossing method. This is because it is very easy and can be used at rather high frequencies.
However microwave range "counters" do use different methods, like first mixing the input signal and down conversion to a, much lower frequency that is than analyzed in a different way. I don't know the details, but in modern implementation it could be well possible to use some kind of digital analysis like describes in the articles cited here. 
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27203
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #61 on: December 17, 2019, 09:36:08 pm »
It shows these methods being fed sinewaves with various types of noise and distortion applied to them. One of them being my proposal that is here named as "Signal demodulation". On page 13 and on you will find figures 9 to 17 showing graphs of the results, notice how graph D (showing the demodulation method) is always rock solid on the right frequency no matter what kind of noise is injected into the signal, nor does it show any quantization steps.
I wouldn't say that. SDM shows weird startup behaviour in several graphs and it seems that the ZC (zero crossing) is determined over one period only. If you filter the input signal to a frequency band of interest and average the ZC over multiple periods (which is very applicable to the OP's intended use) you'll get very good results as well. You have to keep in mind that the paper is about tracking mains frequency which is a continuous signal and not a burst. Besides that tracking mains frequency seems to be time sensitive as in needing the answer as quickly as possible.
« Last Edit: December 17, 2019, 09:44:46 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Berni

  • Super Contributor
  • ***
  • Posts: 4997
  • Country: si
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #62 on: December 17, 2019, 09:38:41 pm »
As for the Phasor angle estimator, i agree. If you convert the signal into a phasor you know its exact frequency and job done. However can you recommend a simple and reliable algorithm for turning ADC samples into a phasor?
Cartesian to polar coordinate transform. I think paper in the link below may answer this question as well.

Yes i agree that's what my approach uses to turn a quadrature I/Q signal into phase and magnitude.

But since the ADC is only spitting out real number samples where do you get the imaginary component to plug into the Cartesian input value? Or is the polar phase always just 0° or 180° ?

Quote
I'm sorry if i am being annoying with this, not trying to argue or anything but just trying to get on the same page with this phasor approach.
Don't be sorry at all. This is interesting topic, thank you for arguing. I believe that there is no single "ultimate" solution, every approach may have it's strong and weak points. I think following paper will give some insight into phasor approach. https://www.researchgate.net/publication/323628162_Implementation_Techniques_for_Frequency_Phasor_Estimation_in_Phasor_Measurement_Units_PMUs

I do agree there is no single best method. As it usually is in engineering every solution has its own sets of different advantages and disadvantages.

Yep that paper does describe the approach to turning a sequence of real samples into a phasor:
Quote
MATLAB model of Phase Measurement Unit is
developed using recursive and non-recursive DFT algorithms
to get the required phase and magnitude of the signal.

And it uses DFT to do it. So its pretty much just doing FFT of the ADC signal and then picking out the bin of interest, checking its phase. Doing another FFT of a signal sometime in the future, getting the phase of that too, finnaly calculating the difference between the two phases to get the full phasor.

The DFT takes a horrendously large amount of computational work to calculate when you have decent sized inputs of >1024 samples. So anyone in the right mind would use FFT as it takes a lot less calculation to get the same result the DFT would give. On the upside there is no need for a input FIR filter to clean the signal since FFT can select the frequency it wants to look at, but even with FFT the computation for 1024 points takes around 25000 multiply operations and around 50000 sum operations(Or about 25 mul and 50 sum per sample). But since we are only interested in a narrow frequency window its not really necessary to calculate all of the spectrum, FFT unfortunately can't calculate just part of it, but DFT can do that. Yet if you look at what one frequency bin of a DFT actually does, you will find that its just correlating the signal against a sine and cosine of the given frequency, returning a complex number in rectangular form... much like a quadrature I/Q mixer does. Okay i admit if we are completely accurate here mixers don't do the same thing as correlation (that is integrating via sum, not via multiply), but the end result is pretty much the same thing, extracting the real and imaginary component so that it can be turned into a polar complex number.

You are going for the same idea as the approach i suggested, the only difference is that my suggestion takes a bit of a computational shortcut using a mixer.

Near DC means very limited (narrow) range of input frequencies, big group delays of filters, thus long sampling/processing periods. If this method is so good for RF, then why all frequency counters uses zero crossing count method instead? ;)

Its because DC is a real bitch to deal with. This is the reason why analog circuitry often uses AC coupling capacitors in the signal path as soon as they are not required to work down to DC. Makes designing the analog circuit in the real world so much easier.

This is also one of the reasons why mixers are usually not used with a local oscillator frequency that is identical to the signal of interest, you put the local oscillator off by a little bit on purpose so that your mixers output path can be AC coupled. Using this you move the signal of interest into an frequency area where your particular filter works best rather than the other way around for having to make your filter good where your particular signal is. In the case of FIR filters this means you need less steep of a filter, hence fewer coefficients hence easier to compute.

As for why frequency counters use zero crossing, its because its the easiest thing to do in hardware and we know how to make really fast GHz speed divide by 2 clock dividers. Also they usually don't try to focus on a frequency band of interest and are designed to measure any shape of signal, not just sine waves.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #63 on: December 17, 2019, 11:28:23 pm »
But since the ADC is only spitting out real number samples where do you get the imaginary component to plug into the Cartesian input value? Or is the polar phase always just 0° or 180° ?
Yes. You prepare real waveform for complex DFT or FFT same way.

Quote
And it uses DFT to do it.

Not what I wanted to say. My bad. Can't find *that* document anymore. Will try to explain, in brief, simplest possible approach that obviously can be " extended".

1) low-pass filter and normalize amplitude to (+/-) 1.0  2) run through "rising edge" zero-crossing detector to find first sample of sine period. As we have normalized waveform, calculate initial phase directly from amplitude: arcsin(amplitude1) 3) after enough (N) periods, thus zero-crossing detector "triggers", find final sample - and calculate final phase arcsin(amplitude2). 4) that's it. Calculate frequency f = (2*PI*N-arcsin(amplitude1)+arcsin(amplitude2))/(2*PI*delta_t). Example calculation for 1MSPS system, single period 10 samples, amplitude1 = 0.1 and amplitude2 = 0.2 here, result is 101.61 KHz. Frequency is higher than 100KHz because phase rotated more than 2*PI. You can plug 0.1 number into both arcsins to get expected 100KHz - period exactly 10 samples.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #64 on: December 18, 2019, 12:56:19 am »
If one is only interested in the frequency one does not care about group delays per se. However the group delays have to be kept in mind when using a classical narrow band filter, especially for the important beginning and end. The data points at the ends are the most valuable. Use them just for filter settling is a bad idea.

Well, well. I would like to remind what is written in the Subject of this thread and OP:

Assuming that I have data sampled at 100ksps @ 12bit, ignoring timing jitter, the sample size is 2ms (200 samples), is there any method that would enable me to determine the shift of a frequency of sine sampled using this with a large, 0.1Hz resolution? Basically doppler stuff, with the base signal being a pulsed sine at 10kHz. The expected shift is pretty small, 1 to 2 Hz max.

2ms means just 20 periods of the carrier signal. Nothing much you can downconvert, then low-pass filter in this case. You will hit end of the sample buffer long before low-pass filter settling. Berni may think about this as well.
 

Online Berni

  • Super Contributor
  • ***
  • Posts: 4997
  • Country: si
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #65 on: December 18, 2019, 08:48:17 am »
But since the ADC is only spitting out real number samples where do you get the imaginary component to plug into the Cartesian input value? Or is the polar phase always just 0° or 180° ?
Yes. You prepare real waveform for complex DFT or FFT same way.

Quote
And it uses DFT to do it.

Not what I wanted to say. My bad. Can't find *that* document anymore. Will try to explain, in brief, simplest possible approach that obviously can be " extended".

1) low-pass filter and normalize amplitude to (+/-) 1.0  2) run through "rising edge" zero-crossing detector to find first sample of sine period. As we have normalized waveform, calculate initial phase directly from amplitude: arcsin(amplitude1) 3) after enough (N) periods, thus zero-crossing detector "triggers", find final sample - and calculate final phase arcsin(amplitude2). 4) that's it. Calculate frequency f = (2*PI*N-arcsin(amplitude1)+arcsin(amplitude2))/(2*PI*delta_t). Example calculation for 1MSPS system, single period 10 samples, amplitude1 = 0.1 and amplitude2 = 0.2 here, result is 101.61 KHz. Frequency is higher than 100KHz because phase rotated more than 2*PI. You can plug 0.1 number into both arcsins to get expected 100KHz - period exactly 10 samples.

Yep now that is a more sensible method for extracting the phase out of a signal. Simple to do and needs even less computation.

But since telling the exact zero crossing and amplitude of a noisy sine wave is a lot trickier it would still need a narrow bandpass filter in front in order to get the same amount of noise resilience. This comes with its computational cost and group delay.

I admit that i am making a big deal out of noise even tho the OP did not mention it. But from experience with radar and sonar i know that these doppler signals that come out of them are often covered with all sorts of noise. Last time i had to deal with doppler radar i just used zero crossing and a fast timer to measure the periods (it also had a quadrature output so it could sense the target direction, not only speed). Simple but it worked well enough for the application it was for. But if you use some DSP magic you can often recover perfectly usable data from a signal that is 10 times smaller than the noise covering it.

If one is only interested in the frequency one does not care about group delays per se. However the group delays have to be kept in mind when using a classical narrow band filter, especially for the important beginning and end. The data points at the ends are the most valuable. Use them just for filter settling is a bad idea.
Well, well. I would like to remind what is written in the Subject of this thread and OP:
Assuming that I have data sampled at 100ksps @ 12bit, ignoring timing jitter, the sample size is 2ms (200 samples), is there any method that would enable me to determine the shift of a frequency of sine sampled using this with a large, 0.1Hz resolution? Basically doppler stuff, with the base signal being a pulsed sine at 10kHz. The expected shift is pretty small, 1 to 2 Hz max.
2ms means just 20 periods of the carrier signal. Nothing much you can downconvert, then low-pass filter in this case. You will hit end of the sample buffer long before low-pass filter settling. Berni may think about this as well.

Okay sorry i did loose track of the original spec (I was going on about 1MSPS 100Khz)

But in any case this is not a problem since the mixer does not even need 1 complete period to work. Okay in practice if you used only 10 samples to feed the mixer you would be really sensitive to noise and distortion, but you would get the correct result if you fed in a clean sinewave.

Averaging samples together as downsampling has no settling time and has a fixed predictable group delay of half the averaging window size. So in this case to get the most out of the 200 available samples one would mix the whole thing and then downsample by a factor of 100 resulting in 2 samples. These two samples are the phasors of the input signal that are 100 sampling periods apart in time(Centered on sample 50 and 150). So knowing the phase of the two and the time between them gives you the frequency. The whole thing required 400 MAC computations, 400 sums and 400 sine table lookups for the mixing and a handful of math operations to turn the 2 complex output samples into a frequency. All this with excellent noise rejection since 100 phase measurements are averaged together for each resulting sample. Im tempted to try and make this in excel to try out.

But if you do require a settling time for the particular type of filter used then you can easily get around that in radar/sonar since you typically have a continuous stream of data to be fed trough processing, the OP has likely just pre trimmed the target of interest from his signal to result in 200 samples. So if you lay out your process correctly you tend to easily find some leftover data around the signal of interest to flush trough the slow filter and prime it for the real data of interest.
 
The following users thanked this post: ogden

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27203
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #66 on: December 18, 2019, 10:12:16 am »
But since telling the exact zero crossing and amplitude of a noisy sine wave is a lot trickier it would still need a narrow bandpass filter in front in order to get the same amount of noise resilience. This comes with its computational cost and group delay.
Not really. A single 2nd order IIR filter section (4 multiplies and 4 additions) is probably good enough. Averaging several cycles takes care of the rest of the noise. About 2 decades ago I implemented a DTMF decoder in an FPGA which uses zero cross detection (frequency counters) to detect the tones. Worked like a charm and didn't need any complex math.
« Last Edit: December 18, 2019, 10:13:55 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #67 on: December 18, 2019, 11:39:50 am »
One can remove the IIR-filter group delay by running the signal twice through the filter: First in normal sample order, and second time using reversed sample order for the filtered signal. At the same time one will get twice the filter order.
 
The following users thanked this post: nctnico

Online Berni

  • Super Contributor
  • ***
  • Posts: 4997
  • Country: si
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #68 on: December 18, 2019, 05:45:26 pm »
But since telling the exact zero crossing and amplitude of a noisy sine wave is a lot trickier it would still need a narrow bandpass filter in front in order to get the same amount of noise resilience. This comes with its computational cost and group delay.
Not really. A single 2nd order IIR filter section (4 multiplies and 4 additions) is probably good enough. Averaging several cycles takes care of the rest of the noise. About 2 decades ago I implemented a DTMF decoder in an FPGA which uses zero cross detection (frequency counters) to detect the tones. Worked like a charm and didn't need any complex math.

Yep and that is already more computation than is needed to quadrature mix the signal where filtering and phase extraction both happen in one go.

But yes if the signal is reasonably clean and you don't need to be tightly selective of what frequencies you look at just zero crossings will be close enough. On a project that involves radar i did the frequency measurement even simpler by analog filtering it, sending it trough a comparator for zero crossing and finally using a timer in a MCU to count the pulse periods. It did need the signal to be a good bit out of the noise before it would reliably measure it, but that doppler radar module had enough SNR that it still detected far enough for what the client wanted, so i left it like that.

But if put enough DSP effort into it to narrow your bandwidth onto what matters you can really pull out signals that are many times smaller than the noise floor itself (Tho in a lot of these cases you have to know what you are looking for, like a special tone, or frequency sweep or phase encoding etc to tell it apart from noise).
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14366
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #69 on: December 18, 2019, 07:11:30 pm »
The iterative steps for the least square fit can be quite similar to the down-mixing method:
The down mixing followed by linear interpolation to calculate the slope of the phase and thus frequency mulitplies the data with sine , cosine and a step like function from the slope calculation. The fit in the linearized form uses t*cos(wt), t*sin(wt) instead of the step functions. So the difference is not that large. The comparison also shows that it may not be a good idea to use only 2 blocks to get a start and end phase. The two steps are a rather coarse approximation to a linear slope. Using 3 blocks has the funny effect that the center block does no enter in the frequency calculation, so one does not even need to calculate the phase for the center part. Chances are the 3 block way may still be better than the 2 block version despite of ignoring 1/3 of the data. It probably gets even better with more block. However there is a limit - the down mixing to get a local phase only works well if the blocks for averaging have the length of full periods. Very short blocks may also reduce the suppression of off band noise.

Most FIR filters are symmetric in time - so it does not make a difference running them forward or backwards. So no group delay involved from the start. The difference to analog filter is that such FIR filters are non causal (as the look in the future).
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27203
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #70 on: December 18, 2019, 10:35:52 pm »
But since telling the exact zero crossing and amplitude of a noisy sine wave is a lot trickier it would still need a narrow bandpass filter in front in order to get the same amount of noise resilience. This comes with its computational cost and group delay.
Not really. A single 2nd order IIR filter section (4 multiplies and 4 additions) is probably good enough. Averaging several cycles takes care of the rest of the noise. About 2 decades ago I implemented a DTMF decoder in an FPGA which uses zero cross detection (frequency counters) to detect the tones. Worked like a charm and didn't need any complex math.
Yep and that is already more computation than is needed to quadrature mix the signal where filtering and phase extraction both happen in one go.
I'm not quite sure whether that is true because you'll still be aliasing the noise allover the place. And quadrature mixing doesn't do anything for averaging readings from multiple periods (which is a big advantage of using zero crossing). There is only so much you can do with signal processing; at some point it is better to use an algorithm which looks at the signal in the time-domain to make sense of it.
« Last Edit: December 18, 2019, 10:40:21 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2292
  • Country: us
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #71 on: December 19, 2019, 06:05:22 pm »
My guess would be cross-correlation (auto-correlation) is a more productive starting point than FFT...  In fact the whole thing sounds like it would have solutions in echo detection.
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 720
  • Country: us
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #72 on: December 19, 2019, 06:49:34 pm »
This thread has been really interesting to follow.  EE version of a Rorschach test  :-DD
 
The following users thanked this post: iMo

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14665
  • Country: fr
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #73 on: December 19, 2019, 06:55:20 pm »
This thread has been really interesting to follow.  EE version of a Rorschach test  :-DD

Ahah, sounds pretty close. ;D
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #74 on: December 19, 2019, 07:15:12 pm »
 
The following users thanked this post: Berni, iMo


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf