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

0 Members and 1 Guest are viewing this topic.

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6747
  • Country: nl
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #75 on: December 19, 2019, 08:03:57 pm »
And quadrature mixing doesn't do anything for averaging readings from multiple periods (which is a big advantage of using zero crossing).

I kinda missed what quadrature mixing was supposed to do, it's mostly a way to get a complex signal near DC which you can use with the phase method (multiply each complex sample with the conjugate of the subsequent sample, sum them all up, take the angle of the result). The signal being near DC does do something for averaging though, any signal near DC can be trivially filtered through a simple window average before processing. Hilbert transform does not get you this.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27207
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #76 on: December 19, 2019, 11:17:42 pm »
And quadrature mixing doesn't do anything for averaging readings from multiple periods (which is a big advantage of using zero crossing).

I kinda missed what quadrature mixing was supposed to do, it's mostly a way to get a complex signal near DC which you can use with the phase method (multiply each complex sample with the conjugate of the subsequent sample, sum them all up, take the angle of the result). The signal being near DC does do something for averaging though, any signal near DC can be trivially filtered through a simple window average before processing. Hilbert transform does not get you this.
But a signal near DC also gets you into trouble with offsets. And due to aliasing you'll need to have both a bandpass filter in the analog and (at least a DC blocking filter) in the digital domain to remove any DC which gets into the ADC. All in all quadrature mixing doesn't give you any advantages because for a practical implementation you'll need just as much processing (filtering) compared to using the zero crossings method. And with quadrature mixing you can't do stuff like throwing away zero crossings which don't make sense (get rid of outlyers).
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 #77 on: December 20, 2019, 07:08:24 am »
Okay yeah i did forget about DC offset on the input, that would cause issues for a mixer.

But in terms of the aliasing filter that does need to a physical analog filter before the actual ADC. If the ADC acquires aliased samples there is no way to tell in the digital domain if the tone is a real tone or something higher that got aliased down.

And yes the mixer does spit out a useless result at zero crossing, but you would generally have your downsampling window large enough to cover more than one entire period of the signal since yeah there is a lot of the carrier still left in the output signal. Most of the reason i claim it as being computational cheep is because the filter can be combined with the mixer into one MAC operation that generally takes a single cycle to execute(And also works well with SIMD).

For when computational power is not so much of a concern i do admit that FFT is probably the best choice since not only does it have excellent noise resilience and selectivity, but it does it for the whole spectrum simultaneously (makes tracking multiple doppler targets easy) and the same FFT result can later be used to perform correlation of the input with the transmitted signal, since that's a nice fast way that can find an echo even when its buried under noise.
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14367
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #78 on: December 20, 2019, 09:14:44 am »
If computational effort is not a big problem, the best solution is usually (for white noise it is the best) the least square fit.  The time it needs for the fit depends on the implementation - general methods can be relatively slow. However in the right form only the frequency is a nonlinear parameter. Amplitudes and DC offset are linear and the linear approximation is thus quite good, so that the convergence can be quite good, so that only few (e.g. 2 or 3)  iterative steps are needed. Each step takes a little more than twice the time of the mixing method. Because of the similarity to the mixing method, chances are that even a single approximation step could be already as accurate as the mixing method with the best block size.

So the effort for the fit is not that high, if an adapted code is used and a reasonable starting point for the frequency is available.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #79 on: December 20, 2019, 12:43:11 pm »
Possibly useful observation...

If the frequency range of the desired signal is very narrow, and the data has been filtered, and your sample rate is a multiple of four for the desired frequency you can convert the real data into I+Q data very simply.

If the wavelength is 20 samples (+/- a smidgen) then:

Code: [Select]
   data_i[i] = (data_r[i-5]-data_r[i+5])/2;

So, if 'data_r' has 200 samples of clean, filtered, valid data the following works:

Code: [Select]
   double phase10, phase190,change;

   // Calculate the quadrature component of the real data in data_r
   data_i[10]  = (data_r[ 10-(WAVELENGTH/4)]-data_r[10+(WAVELENGTH/4)])/2;
   data_i[190] = (data_r[190-(WAVELENGTH/4)]-data_r[190+(WAVELENGTH/4)])/2;

   // work out phase as close to the start and end of the data as possible
   phase10 = atan2(data_r[10],data_i[10]);
   phase190 = atan2(data_r[190],data_i[190]);

   // work out the change in phase per sample over 180 samples
   change = (phase190-phase10)/180;

   // print results.
   printf("Angle at sample 49 is  %10.6f\n",phase10);
   printf("Angle at sample 149 is %10.6f\n",phase190);
   printf("Change in cycles after 100,000 samples %10.6f\n", change*100000/(2*M_PI));

The key requirement is that your sample rate has to be a multiple of four of the nominal frequency of the signal of interest so you easily access data a quarter of a cycle away from any given sample - so for 10kHz you might want to use 80kS/s or 120kS/s, rather than 100kS/s.
« Last Edit: December 20, 2019, 12:49:06 pm by hamster_nz »
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27207
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #80 on: December 20, 2019, 07:17:10 pm »
For when computational power is not so much of a concern i do admit that FFT is probably the best choice since
No. Absolutely not. FFT (and also Goertzel) is utterly useless for detecting tones because in the frequency domain the bins are not shaped rectangular but parabolic. At the sides of the bin the signal strength will appear weaker.

@hamster_nz: if there is a bandpass filter in the analog domain with sufficient suppresion you can even undersample. I have used that trick in an ultrasonic distance meter in order to use a lower samplerate.
« Last Edit: December 20, 2019, 07:20:06 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 #81 on: December 21, 2019, 06:13:58 pm »
For when computational power is not so much of a concern i do admit that FFT is probably the best choice since
No. Absolutely not. FFT (and also Goertzel) is utterly useless for detecting tones because in the frequency domain the bins are not shaped rectangular but parabolic. At the sides of the bin the signal strength will appear weaker.

I meant FFT as a process to convert the real ADC samples into complex form so that you can find the phase of that tone. We don't care about what frequency each bin is, they are just used to tell apart the signal of interest from other crap like noise, tones, harmonics etc.. Sort of like a narrow bandpass filter that happens to also convert the signal from real to complex form.

Do this FFT twice on two different sections of the signal and you can get a phase difference between the two points to get the exact freqency. The wraparound integer phase can be gotten from zero crossing or calculating it from the FFT bin frequency if it has enough bins to be accurate within one whole wave.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4865
  • Country: vc
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #82 on: December 21, 2019, 06:15:58 pm »
@daqq - could you post some data such the people may have something to play with?
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27207
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #83 on: December 21, 2019, 06:47:04 pm »
For when computational power is not so much of a concern i do admit that FFT is probably the best choice since
No. Absolutely not. FFT (and also Goertzel) is utterly useless for detecting tones because in the frequency domain the bins are not shaped rectangular but parabolic. At the sides of the bin the signal strength will appear weaker.
I meant FFT as a process to convert the real ADC samples into complex form so that you can find the phase of that tone. We don't care about what frequency each bin is, they are just used to tell apart the signal of interest from other crap like noise, tones, harmonics etc.. Sort of like a narrow bandpass filter that happens to also convert the signal from real to complex form.
Nope. The result will still heavily rely on how well the actual frequency is aligned to the FFT bins. Besides that for FFT you'll need to use some kind of windowing to turn the burst signal from the OP into a seemingly continuous signal which esentially means not using all the incoming information.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6747
  • Country: nl
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #84 on: December 21, 2019, 08:20:57 pm »
All in all, given the way DC makes things hard for the mixing/phasor approaches I think the FFT based method still is the easiest to implement.

Fast enough, close to optimal, doesn't care about DC. I don't really care about the way frequencies cover bins, he said he did the Monte Carlo simulations to test his formula and it performed near optimal. I'm not going to do them myself, but unless I see someone do it and contradict him I have no reason to distrust his results.
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6381
  • Country: ro
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #85 on: March 01, 2020, 10:20:01 am »
Without reading very carefully all the proposed solutions, the OP problem looks to me like an ideal application for a lock-in amplifier, simply because there is prior knowledge of the Tx signal.

There were some quadrature based solutions mentioned, not sure if those will eventually implement an ad-hoc lock-in amplifier or not (at a draft look I perceived them as an implementation of a heterodyne).

I'll go for the homodyne method first (in EE also known as a lock-in amplifier, in optics known as an interferometer) and see if it can get the required resolution.  Also very important, try to make use of all of the prior knowledge, including expected S/N, expected frequency shift ranges, rate of frequency change.

I never had to solve a similar problem, so my advice might be completely off.   ;D

Whatever method you'll choose, "One can not find what one is not looking for", here meaning if you want to squeeze out the best results out of those few samples, you must take advantage of any prior knowledge you have about them, here the most important is that you have the original Tx-ed signal, followed by the expectations about the Rx signal (expected S/N, deviation range, etc.).

Chances are you might be able to vary the Tx signal parameters, too (from the OP is not very clear if this is allowed).  If true, this ability might improve the end results even more, depending on the exact application (e.g. the chirp modulation in radar/sonar type of applications).
« Last Edit: March 01, 2020, 10:35:07 am by RoGeorge »
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #86 on: March 01, 2020, 07:15:23 pm »
Without reading very carefully all the proposed solutions, the OP problem looks to me like an ideal application for a lock-in amplifier, simply because there is prior knowledge of the Tx signal.
Apparently you did not read your lock-in amplifier homework as well. Homodyne detectors (lock-in amplifiers) are used to demodulate either phase or amplitude, not frequency modulation/shift.
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6381
  • Country: ro
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #87 on: March 01, 2020, 07:55:55 pm »
You could have said that without commenting about my person.   :)

"Frequency modulation/shift" can always be seen as a phase modulation.

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #88 on: March 01, 2020, 09:17:11 pm »
"Frequency modulation/shift" can always be seen as a phase modulation.
Shifted carrier frequency can't be considered as modulation. Anyway lock-in amplifier requires carrier and LO frequencies to be identical which is not the case in doppler application.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf