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

0 Members and 1 Guest are viewing this topic.

Offline daqqTopic starter

  • Super Contributor
  • ***
  • Posts: 2302
  • Country: sk
    • My site
Hi guys,

I'm playing around with signals, I wanted to ask whether it's possible to measure a small frequency shift on a short pulse of a signal.

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. I've tried playing with the raw data, using my naive applications of some methods (fft, as well as brute force correlation with a bunch of sines at different phases and different frequencies) it seems the best I can do is a difference of 3Hz-ish so far.

My question is, is it even possible? If so, could you tell me the name of the methods I should look at?

Thanks,

David
Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
 

Offline EEEnthusiast

  • Frequent Contributor
  • **
  • Posts: 375
  • Country: in
  • RF boards, Precision Analog, Carpentry
    • https://www.zscircuits.in/
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #1 on: December 13, 2019, 10:11:22 am »
David
For sampled signals, the resolution frequency is given by the formula Fres = Fs/N where Fs is the sampling frequency and N is the number of samples. You can calculate this directly as per your signals.

essentially for a 1Msps ADC, you need to capture 1Million samples to get 1Hz resolution.
Making products for IOT
https://www.zscircuits.in/
 

Online iMo

  • Super Contributor
  • ***
  • Posts: 4860
  • Country: vc
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #2 on: December 13, 2019, 10:25:03 am »
Sure you can, with a reciprocal counter (with TIC for higher resolution).
 

Offline daqqTopic starter

  • Super Contributor
  • ***
  • Posts: 2302
  • Country: sk
    • My site
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #3 on: December 13, 2019, 10:39:45 am »
Quote
Sure you can, with a reciprocal counter (with TIC for higher resolution).
Thanks, unfortunately I'm stuck with the data sampled by the ADC. I know that it can be done using some other methods (high resolution Time to Digital converters and such or even simple timers clocked fast).
Quote
For sampled signals, the resolution frequency is given by the formula Fres = Fs/N where Fs is the sampling frequency and N is the number of samples. You can calculate this directly as per your signals.

essentially for a 1Msps ADC, you need to capture 1Million samples to get 1Hz resolution.
Are you sure about this? Assuming 100Hz, sampled at 1Msps, with 1M samples, the signal will look pretty differently if it's shifted by 0.1Hz. I have a gut feeling that using some kind of sine fitting you should be able to get the 0.1Hz out of there.
Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7483
  • Country: nl
  • Current job: ATEX product design
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #4 on: December 13, 2019, 11:25:45 am »
What you have is a window function. Window function makes samples outside the window 0. You have a rectangular window, which is not very useful. Probably a Hamming window would be much nicer, where the frequency in question would "pop out" nicer. Check this:
https://en.wikipedia.org/wiki/Window_function
Your frequency resolution is the bin size. You need a certain amount of data to have a bin. It 200/2=100 bins for you, well not really, Lets say it is 64, or 128. Your sample rate it 100KSPS, so each bin is 781 Hz or 1.562KHz (Fs/N). Thats not very useful. Clearly, you need to decrease the sample rate or increase the sample size. For both, you need the signal to be stable for longer. So FFT is not how you do it.
« Last Edit: December 13, 2019, 11:28:18 am by NANDBlog »
 
The following users thanked this post: daqq

Online Berni

  • Super Contributor
  • ***
  • Posts: 4997
  • Country: si
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #5 on: December 13, 2019, 11:41:33 am »
Are you sure about this? Assuming 100Hz, sampled at 1Msps, with 1M samples, the signal will look pretty differently if it's shifted by 0.1Hz. I have a gut feeling that using some kind of sine fitting you should be able to get the 0.1Hz out of there.

Yes you can, but the result will be fuzzy.

You can fiddle with the data in various ways in order to get FFT to compute to finer resolution or try correlating against near by sine waves. But say your signal is 99.5Hz you will also get a strong signal at 99.1 99.2 99.3 99.4 99.6 99.7 99.8 99.9 100. As a result when graphing it you get a big hump around your 99.5 Hz (You have seen this hump in FFT before im sure). This is because mathematically that 1 second slice of time actually does contain all these frequencies. You can still find the 99.5 because it will be in the middle of that hump. Possible to do if what you have is a nice clean signal with no noise. But if your sine wave has some variation or jitter, or there is a lot of noise mixed in then the peak of the hump could move around a lot, making all that extra 0.1 digit of resolution useless since its just randomly jumping around.

Since you are doing doppler processing its probably best to first mix the signal with the carrier. This gives you a sine wave where phase changes with your target range. If you repeat the same with a 90 degree offset you get a quadrature signal where you can instantaneously determine the phase angle. How fast this phase angle moves is your doppler speed.
 
The following users thanked this post: daqq

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14366
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #6 on: December 13, 2019, 12:03:04 pm »
The data set is quite short. So one could do a "brute force" least squares fit of a sine function. Depending on the algorithm used this can need quite some computations, but it is possible. The frequency resolution can be quite high, limited by the noise.  A resolution in the 0.1 Hz range sounds plausible, if the signal is a real sine. Additional amplitude modulation (e.g. decay in amplitude could complicate things).

Another possibility could be using a Hilbert-transformation. However the data set is rather short, with only some 20 periods. It could still work, but may need extra attention. This is essentially calculating a local phase relatively to a virtual first estimate frequency signal over bunches of some 5 periods each and than look at the time dependence of the phase that gives the difference to the first frequency estimate.
This is faster than the full fit, but could still give good results, especially with longer data sets. 
The Method Berni just describes is about this from a different perspective.
I have used that method to measure frequencies form data sets like 30000 point's over 1 s to get a frequency resolution in the 1 µHz range for a 1 kHz signal.

One can get more frequency resolution from FTT too: just extend the data with leading and trailing zeros to some 4096 points or even more. It is still not easy to look at the FFT result, as more than 1 bin will have amplitude and the real frequency can be in between.
 
The following users thanked this post: daqq

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6746
  • Country: nl
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #7 on: December 13, 2019, 12:23:59 pm »
l as brute force correlation with a bunch of sines at different phases and different frequencies

Because you have a constrained model of the signal I'm not sure how the math works out on what frequency difference can be theoretically detected ... but I can say that you shouldn't do what you just said.

Always correlate with sines and cosines and take the RMS, that way you can ignore phase. So do that with three frequencies, with the outer frequencies being beyond the min/max doppler shift you expect, then do peak interpolation and see what you get.

I suspect you shouldn't multiply with a window.
 
The following users thanked this post: daqq

Offline EEEnthusiast

  • Frequent Contributor
  • **
  • Posts: 375
  • Country: in
  • RF boards, Precision Analog, Carpentry
    • https://www.zscircuits.in/
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #8 on: December 13, 2019, 12:52:54 pm »
I suggest to Matlab this and find out. I really doubt if you can reliably resolve the frequency below Fres, with a limited sample set. The accuracy is degraded severely.
Making products for IOT
https://www.zscircuits.in/
 
The following users thanked this post: daqq

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14665
  • Country: fr
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #9 on: December 13, 2019, 03:55:56 pm »
This sounds like a pretty challenging endeavor.

As you probably already figured, you'll get ~20 periods of your signal. A simple calculation shows that a time difference of just one sample period (10µs here) over 20 periods of a 10kHz signal is roughly equivalent to a difference of 50Hz in your input signal. This is just to give an idea of what we're looking at.

Assuming the input signal is a perfect sine wave (how distorted/noisy is it? is a 12-bit ADC enough?), you could get better resolution than this, but 0.1Hz?

I'd be curious to see a working algorithm giving you this kind of resolution with your above parameters, and taking into account noise/distortion and the 12-bit quantization.
 
The following users thanked this post: daqq

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 720
  • Country: us
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #10 on: December 13, 2019, 10:49:01 pm »
Whether this is possible or not is going to depend on the signal to noise ratio.  You haven't told us much about the signal except that it is sinusoidal and pulsed.  As was already mentioned, if the SNR were infinite (the "just math" case) you could have infinite frequency resolution.  In reality, noise will limit you, even if it is just the quantization noise inherent in your 12-bit ADC.

If you can model your signal as a sinusoid in noise, i.e. you know for certain that the sinusoid is always there (it does not turn on and off during your data capture) and there are no other signals present, just noise, then you can use methods like MUSIC or ESPRIT.  These achieve much better frequency resolution than an FFT followed by peak interpolation.

In any case, your next step is definitely to build some simulations in Matlab or python to find out if this will work, and how to optimize it for your situation.
 
The following users thanked this post: daqq

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27203
  • Country: nl
    • NCT Developments
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #11 on: December 13, 2019, 11:47:00 pm »
Hi guys,

I'm playing around with signals, I wanted to ask whether it's possible to measure a small frequency shift on a short pulse of a signal.

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. I've tried playing with the raw data, using my naive applications of some methods (fft, as well as brute force correlation with a bunch of sines at different phases and different frequencies) it seems the best I can do is a difference of 3Hz-ish so far.

My question is, is it even possible? If so, could you tell me the name of the methods I should look at?

Thanks,

David
The simplest way would be to interpolate (upsample) the signal so you get to the required resolution and then determine the frequency by looking at the zero crossings. Jitter and noise will be your biggest enemy though but if you can average the frequency of several cycles you should be able to filter out the noise. Using a narrow filter to make sure you only get the relevant frequencies of the signal will help to reduce noise. Basically a frequency meter in software.

FFT and correlation (which basically comes down to FFT) don't seem like suitable methods to me because in the end the frequency resolution will be limited to the bin size.
« Last Edit: December 14, 2019, 12:00:48 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: daqq

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16768
  • Country: us
  • DavidH
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #12 on: December 14, 2019, 02:56:55 am »
Quote
Sure you can, with a reciprocal counter (with TIC for higher resolution).

Thanks, unfortunately I'm stuck with the data sampled by the ADC. I know that it can be done using some other methods (high resolution Time to Digital converters and such or even simple timers clocked fast).

Centroid timing and transition midpoint timing time to digital converters use curve fitting to make a more precise measurement of a waveform with known characteristics.  If your signal is bandwidth limited, then sin(x)/x interpolation will also allow this.
 
The following users thanked this post: daqq

Online coppice

  • Super Contributor
  • ***
  • Posts: 8803
  • Country: gb
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #13 on: December 14, 2019, 03:04:26 am »
Quote
Sure you can, with a reciprocal counter (with TIC for higher resolution).
Thanks, unfortunately I'm stuck with the data sampled by the ADC. I know that it can be done using some other methods (high resolution Time to Digital converters and such or even simple timers clocked fast).
Quote
For sampled signals, the resolution frequency is given by the formula Fres = Fs/N where Fs is the sampling frequency and N is the number of samples. You can calculate this directly as per your signals.

essentially for a 1Msps ADC, you need to capture 1Million samples to get 1Hz resolution.
Are you sure about this? Assuming 100Hz, sampled at 1Msps, with 1M samples, the signal will look pretty differently if it's shifted by 0.1Hz. I have a gut feeling that using some kind of sine fitting you should be able to get the 0.1Hz out of there.
You can get the exact frequency of any pure sine wave using 3 perfect samples - i.e. no amplitude noise, no timing noise (i.e. timing jitter), and masses of resolution. The snag comes when you realise how incredibly sensitive to noise the three sample approach really is.
 
The following users thanked this post: daqq

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16768
  • Country: us
  • DavidH
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #14 on: December 14, 2019, 03:09:02 am »
You can get the exact frequency of any pure sine wave using 3 perfect samples - i.e. no amplitude noise, no timing noise (i.e. timing jitter), and masses of resolution. The snag comes when you realise how incredibly sensitive to noise the three sample approach really is.

Sampling noise is not bandwidth limited so it causes aliasing making the solution indeterminate.  If you use all of the samples, then the noise is integrated out increasing accuracy.
 

Online coppice

  • Super Contributor
  • ***
  • Posts: 8803
  • Country: gb
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #15 on: December 14, 2019, 03:16:20 am »
You can get the exact frequency of any pure sine wave using 3 perfect samples - i.e. no amplitude noise, no timing noise (i.e. timing jitter), and masses of resolution. The snag comes when you realise how incredibly sensitive to noise the three sample approach really is.

Sampling noise is not bandwidth limited so it causes aliasing making the solution indeterminate.  If you use all of the samples, then the noise is integrated out increasing accuracy.
I didn't say the three sample approach was the most practical. However, it is widely used in things like speech analysis. See the Teager Kaiser Energy Operator (TKEO).
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16768
  • Country: us
  • DavidH
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #16 on: December 14, 2019, 03:46:10 am »
I didn't say the three sample approach was the most practical. However, it is widely used in things like speech analysis. See the Teager Kaiser Energy Operator (TKEO).

I just meant to point out the type of algorithm to use.  In the analog domain it was common to phase lock a clean reference signal to the signal to be measured and then measure the clean reference signal at only a few points.  The continuous phase comparison did the integration.  But that is not feasible for burst measurements.
 

Online nfmax

  • Super Contributor
  • ***
  • Posts: 1564
  • Country: gb
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #17 on: December 14, 2019, 08:55:30 am »
Another approach might be to use an FFT and Hilbert transform to construct the (complex) analytic signal. Since your pulse is fairly narrow-band, the argument of this is a good approximation to the phase of the original. After unwrapping it, fit a straight line to the phase (possibly with some weighting based on amplitude or SNR, and down weighting the end regions). The slope of the fitted line is the frequency estimate.

Choice of windows and weighting functions may be important. You can also try fitting a higher order polynomial, and using its linear term as your estimate.

I have used this technique to analyse optical interferograms. The SNR was high, but we needed very high 'frequency' (actually fringe spacing) resolution.
 
The following users thanked this post: daqq

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14366
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #18 on: December 14, 2019, 10:57:35 am »
With just 200 samples I would go for the brute force least squares fit. This is rather close to the best possible suppression of noise. So the main weakness to worry about it the computational effort.  Writing the "sine" function to fit not at  A*sin(wt+phi) but as A1*sin(wt)+A2*cos(wt) the least square fit can be linearized quite well. So it does not need many iterations (maybe 2 or 3) if the starting point is good.

It kind of depends on the HW used. An a PC and for tests one could use the fitting function of a plotting program or math-lab. So one could try with real data sets what to expect.

Chances are a 100 MHz ARM based µC could to the math as fast as the data are coming in. For a similar task I reached that point with a 60 MHz Pentium CPU and a not very efficient program.
 
The following users thanked this post: daqq

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #19 on: December 14, 2019, 07:32:19 pm »
Made some bogus data, with an amplitude of +/- 75% at 10,000.0 Hz and 10,000.1 Hz. You can draw your own conclusions:

With 12-bit resolution:
Code: [Select]
-99,    632,    633
 -98,   1203,   1203
 -97,   1656,   1656
 -96,   1946,   1947
 -95,   2047,   2046
 -94,   1946,   1946
 -93,   1656,   1655
 -92,   1203,   1202
 -91,    632,    632
 -90,      0,      0
 -89,   -632,   -633
 -88,  -1203,  -1203
 -87,  -1656,  -1656
 -86,  -1946,  -1946
 -85,  -2047,  -2046
 -84,  -1946,  -1946
 -83,  -1656,  -1655
 -82,  -1203,  -1202
 -81,   -632,   -632
 -80,      0,      0
 -79,    632,    633
 -78,   1203,   1203
 -77,   1656,   1656
 -76,   1946,   1946
 -75,   2047,   2046
 -74,   1946,   1946
 -73,   1656,   1655
 -72,   1203,   1202
 -71,    632,    632
 -70,      0,      0
 -69,   -632,   -632
 -68,  -1203,  -1203
 -67,  -1656,  -1656
 -66,  -1946,  -1946
 -65,  -2047,  -2046
 -64,  -1946,  -1946
 -63,  -1656,  -1655
 -62,  -1203,  -1202
 -61,   -632,   -632
 -60,      0,      0
 -59,    632,    632
 -58,   1203,   1203
 -57,   1656,   1656
 -56,   1946,   1946
 -55,   2047,   2046
 -54,   1946,   1946
 -53,   1656,   1655
 -52,   1203,   1202
 -51,    632,    632
 -50,      0,      0
 -49,   -632,   -632
 -48,  -1203,  -1203
 -47,  -1656,  -1656
 -46,  -1946,  -1946
 -45,  -2047,  -2046
 -44,  -1946,  -1946
 -43,  -1656,  -1655
 -42,  -1203,  -1202
 -41,   -632,   -632
 -40,      0,      0
 -39,    632,    632
 -38,   1203,   1203
 -37,   1656,   1656
 -36,   1946,   1946
 -35,   2047,   2046
 -34,   1946,   1946
 -33,   1656,   1655
 -32,   1203,   1203
 -31,    632,    632
 -30,      0,      0
 -29,   -632,   -632
 -28,  -1203,  -1203
 -27,  -1656,  -1656
 -26,  -1946,  -1946
 -25,  -2047,  -2046
 -24,  -1946,  -1946
 -23,  -1656,  -1655
 -22,  -1203,  -1203
 -21,   -632,   -632
 -20,      0,      0
 -19,    632,    632
 -18,   1203,   1203
 -17,   1656,   1656
 -16,   1946,   1946
 -15,   2047,   2046
 -14,   1946,   1946
 -13,   1656,   1656
 -12,   1203,   1203
 -11,    632,    632
 -10,      0,      0
  -9,   -632,   -632
  -8,  -1203,  -1203
  -7,  -1656,  -1656
  -6,  -1946,  -1946
  -5,  -2047,  -2046
  -4,  -1946,  -1946
  -3,  -1656,  -1656
  -2,  -1203,  -1203
  -1,   -632,   -632
   0,      0,      0
   1,    632,    632
   2,   1203,   1203
   3,   1656,   1656
   4,   1946,   1946
   5,   2047,   2046
   6,   1946,   1946
   7,   1656,   1656
   8,   1203,   1203
   9,    632,    632
  10,      0,      0
  11,   -632,   -632
  12,  -1203,  -1203
  13,  -1656,  -1656
  14,  -1946,  -1946
  15,  -2047,  -2046
  16,  -1946,  -1946
  17,  -1656,  -1656
  18,  -1203,  -1203
  19,   -632,   -632
  20,      0,      0
  21,    632,    632
  22,   1203,   1203
  23,   1656,   1655
  24,   1946,   1946
  25,   2047,   2046
  26,   1946,   1946
  27,   1656,   1656
  28,   1203,   1203
  29,    632,    632
  30,      0,      0
  31,   -632,   -632
  32,  -1203,  -1203
  33,  -1656,  -1655
  34,  -1946,  -1946
  35,  -2047,  -2046
  36,  -1946,  -1946
  37,  -1656,  -1656
  38,  -1203,  -1203
  39,   -632,   -632
  40,      0,      0
  41,    632,    632
  42,   1203,   1202
  43,   1656,   1655
  44,   1946,   1946
  45,   2047,   2046
  46,   1946,   1946
  47,   1656,   1656
  48,   1203,   1203
  49,    632,    632
  50,      0,      0
  51,   -632,   -632
  52,  -1203,  -1202
  53,  -1656,  -1655
  54,  -1946,  -1946
  55,  -2047,  -2046
  56,  -1946,  -1946
  57,  -1656,  -1656
  58,  -1203,  -1203
  59,   -632,   -632
  60,      0,      0
  61,    632,    632
  62,   1203,   1202
  63,   1656,   1655
  64,   1946,   1946
  65,   2047,   2046
  66,   1946,   1946
  67,   1656,   1656
  68,   1203,   1203
  69,    632,    632
  70,      0,      0
  71,   -632,   -632
  72,  -1203,  -1202
  73,  -1656,  -1655
  74,  -1946,  -1946
  75,  -2047,  -2046
  76,  -1946,  -1946
  77,  -1656,  -1656
  78,  -1203,  -1203
  79,   -632,   -633
  80,      0,      0
  81,    632,    632
  82,   1203,   1202
  83,   1656,   1655
  84,   1946,   1946
  85,   2047,   2046
  86,   1946,   1946
  87,   1656,   1656
  88,   1203,   1203
  89,    632,    633
  90,      0,      0
  91,   -632,   -632
  92,  -1203,  -1202
  93,  -1656,  -1655
  94,  -1946,  -1946
  95,  -2047,  -2046
  96,  -1946,  -1947
  97,  -1656,  -1656
  98,  -1203,  -1203
  99,   -632,   -633
 100,      0,      0

With 14 bits:
Code: [Select]
-99,   3797,   3800
 -98,   7222,   7225
 -97,   9941,   9943
 -96,  11686,  11687
 -95,  12288,  12287
 -94,  11686,  11685
 -93,   9941,   9939
 -92,   7222,   7219
 -91,   3797,   3793
 -90,      0,     -3
 -89,  -3797,  -3800
 -88,  -7222,  -7225
 -87,  -9941,  -9943
 -86, -11686, -11687
 -85, -12288, -12287
 -84, -11686, -11685
 -83,  -9941,  -9939
 -82,  -7222,  -7220
 -81,  -3797,  -3794
 -80,      0,      3
 -79,   3797,   3800
 -78,   7222,   7225
 -77,   9941,   9942
 -76,  11686,  11687
 -75,  12288,  12287
 -74,  11686,  11685
 -73,   9941,   9939
 -72,   7222,   7220
 -71,   3797,   3794
 -70,      0,     -2
 -69,  -3797,  -3799
 -68,  -7222,  -7224
 -67,  -9941,  -9942
 -66, -11686, -11687
 -65, -12288, -12287
 -64, -11686, -11685
 -63,  -9941,  -9939
 -62,  -7222,  -7220
 -61,  -3797,  -3794
 -60,      0,      2
 -59,   3797,   3799
 -58,   7222,   7224
 -57,   9941,   9942
 -56,  11686,  11687
 -55,  12288,  12287
 -54,  11686,  11685
 -53,   9941,   9939
 -52,   7222,   7221
 -51,   3797,   3795
 -50,      0,     -1
 -49,  -3797,  -3798
 -48,  -7222,  -7224
 -47,  -9941,  -9942
 -46, -11686, -11687
 -45, -12288, -12287
 -44, -11686, -11686
 -43,  -9941,  -9940
 -42,  -7222,  -7221
 -41,  -3797,  -3795
 -40,      0,      1
 -39,   3797,   3798
 -38,   7222,   7223
 -37,   9941,   9942
 -36,  11686,  11687
 -35,  12288,  12287
 -34,  11686,  11686
 -33,   9941,   9940
 -32,   7222,   7221
 -31,   3797,   3796
 -30,      0,     -1
 -29,  -3797,  -3798
 -28,  -7222,  -7223
 -27,  -9941,  -9941
 -26, -11686, -11686
 -25, -12288, -12287
 -24, -11686, -11686
 -23,  -9941,  -9940
 -22,  -7222,  -7222
 -21,  -3797,  -3796
 -20,      0,      0
 -19,   3797,   3797
 -18,   7222,   7223
 -17,   9941,   9941
 -16,  11686,  11686
 -15,  12288,  12287
 -14,  11686,  11686
 -13,   9941,   9940
 -12,   7222,   7222
 -11,   3797,   3796
 -10,      0,      0
  -9,  -3797,  -3797
  -8,  -7222,  -7222
  -7,  -9941,  -9941
  -6, -11686, -11686
  -5, -12288, -12287
  -4, -11686, -11686
  -3,  -9941,  -9941
  -2,  -7222,  -7222
  -1,  -3797,  -3797
   0,      0,      0
   1,   3797,   3797
   2,   7222,   7222
   3,   9941,   9941
   4,  11686,  11686
   5,  12288,  12287
   6,  11686,  11686
   7,   9941,   9941
   8,   7222,   7222
   9,   3797,   3797
  10,      0,      0
  11,  -3797,  -3796
  12,  -7222,  -7222
  13,  -9941,  -9940
  14, -11686, -11686
  15, -12288, -12287
  16, -11686, -11686
  17,  -9941,  -9941
  18,  -7222,  -7223
  19,  -3797,  -3797
  20,      0,      0
  21,   3797,   3796
  22,   7222,   7222
  23,   9941,   9940
  24,  11686,  11686
  25,  12288,  12287
  26,  11686,  11686
  27,   9941,   9941
  28,   7222,   7223
  29,   3797,   3798
  30,      0,      1
  31,  -3797,  -3796
  32,  -7222,  -7221
  33,  -9941,  -9940
  34, -11686, -11686
  35, -12288, -12287
  36, -11686, -11687
  37,  -9941,  -9942
  38,  -7222,  -7223
  39,  -3797,  -3798
  40,      0,     -1
  41,   3797,   3795
  42,   7222,   7221
  43,   9941,   9940
  44,  11686,  11686
  45,  12288,  12287
  46,  11686,  11687
  47,   9941,   9942
  48,   7222,   7224
  49,   3797,   3798
  50,      0,      1
  51,  -3797,  -3795
  52,  -7222,  -7221
  53,  -9941,  -9939
  54, -11686, -11685
  55, -12288, -12287
  56, -11686, -11687
  57,  -9941,  -9942
  58,  -7222,  -7224
  59,  -3797,  -3799
  60,      0,     -2
  61,   3797,   3794
  62,   7222,   7220
  63,   9941,   9939
  64,  11686,  11685
  65,  12288,  12287
  66,  11686,  11687
  67,   9941,   9942
  68,   7222,   7224
  69,   3797,   3799
  70,      0,      2
  71,  -3797,  -3794
  72,  -7222,  -7220
  73,  -9941,  -9939
  74, -11686, -11685
  75, -12288, -12287
  76, -11686, -11687
  77,  -9941,  -9942
  78,  -7222,  -7225
  79,  -3797,  -3800
  80,      0,     -3
  81,   3797,   3794
  82,   7222,   7220
  83,   9941,   9939
  84,  11686,  11685
  85,  12288,  12287
  86,  11686,  11687
  87,   9941,   9943
  88,   7222,   7225
  89,   3797,   3800
  90,      0,      3
  91,  -3797,  -3793
  92,  -7222,  -7219
  93,  -9941,  -9939
  94, -11686, -11685
  95, -12288, -12287
  96, -11686, -11687
  97,  -9941,  -9943
  98,  -7222,  -7225
  99,  -3797,  -3800
 100,      0,     -3
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 ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #20 on: December 14, 2019, 07:34:12 pm »
In case of pure sine - normalize amplitude and convert it to polar form. Knowing phasor rotation speed (angular velocity) it is easy to calculate frequency (ω = 2πƒ). In such case accuracy depends on SNR of signal and ADC. It is possible to measure frequency even with just two consecutive samples - using very, very accurate ADC.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6746
  • Country: nl
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #21 on: December 14, 2019, 09:15:15 pm »
You can't accurately know amplitude until you accurately know frequency.
« Last Edit: December 14, 2019, 09:17:02 pm by Marco »
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #22 on: December 14, 2019, 09:21:22 pm »
Would it be possible to create a sine wave so that the created sine wave would be the best fit to the captured samples? If that would be possible, we could also get the best estimate to the sampled sine wave frequency.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #23 on: December 14, 2019, 09:49:33 pm »
Maybe something more practical.

Apply a bandpass DSP filter (to get rid of as much out of band noise as you can).

Interpolate zero crossing between samples.

Period is 2*(LastZeroCrossTime-FirstZeroCrossTime) /(NumberOfZeroCrossings-1)

Frequency is 1/period.

Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 
The following users thanked this post: nctnico

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14366
  • Country: de
Re: Signal processing - getting exact frequency from short ADC sample
« Reply #24 on: December 14, 2019, 10:00:57 pm »
Would it be possible to create a sine wave so that the created sine wave would be the best fit to the captured samples? If that would be possible, we could also get the best estimate to the sampled sine wave frequency.
This is possible, e.g. with a program like Gnuplot. Here the output for the 12 Bit data given by Hamster_NZ. The Program also calculates an estimated error. Due to the likely exact integer amplitude chosen the error estimate may be a little (some 20-50%) optimistic, as the quantization error may be below typical. This would suggest some 0.5 ppm possible frequency (some 0.005 Hz for the 10 kHz example) resolution from perfect 12 Bit data.

Code: [Select]
gnuplot> fit a*sin(b*x)+c*cos(b*x) 'test12bit.dat'  us 1:2 via a,b,c 
.....
Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = 2046.56          +/- 0.0326       (0.001593%)
b               = 0.314159         +/- 2.755e-007   (8.77e-005%)
c               = 2.74857e-005     +/- 0.03258      (1.185e+005%)

correlation matrix of the fit parameters:
                a      b      c     
a               1.000
b               0.036  1.000
c              -0.001 -0.017  1.000


gnuplot> fit a*sin(b*x)+c*cos(b*x) 'test12bit.dat'  us 1:3 via a,b,c 
iter      chisq       delta/lim  lambda   a             b             c           
   0 4.1947679263e+01  0.00e+00 1.52e+04  2.046557e+03  3.141593e-01  2.748573e-05
   1 2.0589137226e+01 -1.04e+05 1.52e+03  2.046317e+03  3.141567e-01  2.748573e-05
   2 1.8897496910e+01 -8.95e+03 1.52e+02  2.046187e+03  3.141567e-01  2.748573e-05
   3 1.8897452147e+01 -2.37e-01 1.52e+01  2.046186e+03  3.141567e-01  2.748573e-05
iter      chisq       delta/lim  lambda   a             b             c           

After 3 iterations the fit converged.
final sum of squares of residuals : 18.8975
rel. change during last iteration : -2.36876e-006

degrees of freedom    (FIT_NDF)                        : 197
rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 0.309719
variance of residuals (reduced chisquare) = WSSR/ndf   : 0.0959262

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = 2046.19          +/- 0.03099      (0.001515%)
b               = 0.314157         +/- 2.62e-007    (8.339e-005%)
c               = 2.74857e-005     +/- 0.03098      (1.127e+005%)

correlation matrix of the fit parameters:
                a      b      c     
a               1.000
b               0.036  1.000
c              -0.001 -0.017  1.000
gnuplot>

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf