Electronics > Projects, Designs, and Technical Stuff
Signal processing - getting exact frequency from short ADC sample
<< < (14/18) > >>
Berni:

--- Quote from: ogden on December 17, 2019, 11:28:23 pm ---
--- Quote from: Berni on December 17, 2019, 09:38:41 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° ?

--- End quote ---
Yes. You prepare real waveform for complex DFT or FFT same way.


--- Quote ---And it uses DFT to do it.

--- End quote ---

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.

--- End quote ---

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.


--- Quote from: ogden on December 18, 2019, 12:56:19 am ---
--- Quote from: Kleinstein on December 17, 2019, 09:25:54 pm ---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.

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

--- Quote from: daqq on December 13, 2019, 09:48:55 am ---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.

--- End quote ---
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.

--- End quote ---

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.
nctnico:

--- Quote from: Berni on December 18, 2019, 08:48:17 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.

--- End quote ---
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.
Kalvin:
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.
Berni:

--- Quote from: nctnico on December 18, 2019, 10:12:16 am ---
--- Quote from: Berni on December 18, 2019, 08:48:17 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.

--- End quote ---
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.

--- End quote ---

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).
Kleinstein:
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).
Navigation
Message Index
Next page
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod