Electronics > Projects, Designs, and Technical Stuff
Signal processing - getting exact frequency from short ADC sample
ogden:
--- Quote from: coppice on December 16, 2019, 12:07:01 am ---
--- Quote from: ogden on December 16, 2019, 12:05:22 am ---
--- Quote from: coppice on December 15, 2019, 11:59:10 pm ---Calculating mains power frequency is easy.
--- End quote ---
Actually math is same for all sine waveforms no matter they are mains power or other kind of "signals".
--- End quote ---
Perhaps you should have read what I wrote.
--- End quote ---
Perhaps you shall explain what you mean by saying so.
coppice:
--- Quote from: ogden on December 16, 2019, 12:11:09 am ---
--- Quote from: coppice on December 16, 2019, 12:07:01 am ---
--- Quote from: ogden on December 16, 2019, 12:05:22 am ---
--- Quote from: coppice on December 15, 2019, 11:59:10 pm ---Calculating mains power frequency is easy.
--- End quote ---
Actually math is same for all sine waveforms no matter they are mains power or other kind of "signals".
--- End quote ---
Perhaps you should have read what I wrote.
--- End quote ---
Perhaps you shall explain what you mean by saying so.
--- End quote ---
Let me expand on what I said. If you just use zero crossings on the voltage waveform to estimate the mains frequency you will have problems when people use certain equipment, like arc welders. You can apply a glitch suppression algorithm to clean up the fast transitions caused by equipment like that, which can have a huge amplitude, and very fast edges. Then, applying a zero crossing detector is a robust mechanism for measuring the mains frequency. The voltage waveform might have 30% to 40% THD under some conditions, but you just don't see extra zeros crossing in real world conditions. Try that with the current waveform, and you will have trouble. The current waveform is frequently so distorted it does show zero crossings at one of the harmonic frequencies. So, if you specifically need to extract the frequency from the current waveform you will need to use other techniques.
Berni:
--- Quote from: coppice on December 16, 2019, 12:21:26 am ---Let me expand on what I said. If you just use zero crossings on the voltage waveform to estimate the mains frequency you will have problems when people use certain equipment, like arc welders. You can apply a glitch suppression algorithm to clean up the fast transitions caused by equipment like that, which can have a huge amplitude, and very fast edges. Then, applying a zero crossing detector is a robust mechanism for measuring the mains frequency. The voltage waveform might have 30% to 40% THD under some conditions, but you just don't see extra zeros crossing in real world conditions. Try that with the current waveform, and you will have trouble. The current waveform is frequently so distorted it does show zero crossings at one of the harmonic frequencies. So, if you specifically need to extract the frequency from the current waveform you will need to use other techniques.
--- End quote ---
Easy way to solve that is to run the signal trough a bandpass FIR/IIR filter to remove signals out of the band of interest, leaving you with just the sine wave you want.
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.
Another advantage to mixer downconversion is that the sample rates can be quickly reduced. The only thing that runs at the full 1 MSPS is the mixer it self (This involves two multiply operations against a sine table and a sum to advance the table) after that the signal is low bandwith (100Hz) so you can use averaging (or a proper FIR downsampler if you like to be fancy) to drop the samplerate to something like 1KHz for all the rest of the processing, this downsampling step also filters out any out of band noise.
At this point there are two 90 degree out of phase 100Hz sinewaves coming out of this. This allows you to convert them to polar form from just looking at one sample. The polar magnitude being the sine wave size and the phase being distance to doppler target. You can then unroll phase between any two samples and get the distance the doppler target has moved between those two points in time, divide that by time to get the average speed within that chosen window of time (Note this window can be placed anywhere along the stream of data)
If your radar/sonar is picking up multiple doppler targets then this step is a bit more complicated because there will be multiple sinewaves in this downconverted signal. Here you might use complex input FFT to seperate them out, pick out the targets, then inverse FFT them back into a time domain signal to process same as before. This creates a sort of tracking bandpass filter for each target. This part is computationally heavy but thanks to the prior work this only needs to run at a sample rate of 1KHz so actually does not need a lot of processing power.
daqq:
Wow. Thanks guys for the amazing replies, I'm still reading through them in detail.
I'll try simulating the signal in Octave (open source matlab equivalent) and play around with it some more based on everyones advice.
--- Quote ---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.
--- End quote ---
That's an interesting approach. I'll try that, though I'm not sure how to apply the filter to the 'edges' of the sample window.
--- Quote ---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.
--- End quote ---
It is bandwidth limited, yeah.
I'll have to study upon the whole interpolation math.
--- Quote ---A general nonlinear least square fit takes quite some time. However specialized to estimating DC offset, amplitude, phase and frequency the computations are not that bad anymore.
--- End quote ---
At the moment there's no real limit on the processing power, it's just in the guessing and estimating stage, whether or not it's possible at all.
Berni: Thanks for the mixer idea, I've been thinking about it, but with such a small time frame, the more I downconvert (mix it with a high frequency getting the frequency difference), the less 'full sines' I get? Basically, if my window 2ms (200 samples) and I downconvert from 10kHz to, say, 100Hz, then, during the 2ms I don't even get one full sine.
Thanks again everyone, I'll play around with it more during the week.
hamster_nz:
Not sure if you are aware of the Hilbert Transform? https://en.wikipedia.org/wiki/Hilbert_transform
With it you can take an 'real' signal, and convert it into an I+Q signal.
What might be interesting about it is that you don't need to apply it to each point.
You can cut the dataset in to two halves (points 0-99 and points 100-199), then convert ONLY points 50 and 150 into I+Q (based on, then look at the phase difference between them - and see how much the phase has changed over the 100 samples. This isn't a bad as it seems, as if you are to run a FIR or IIR filter over your data to remove noise, you will end up truncating your data (for a FIR filter) or have to wait for the IIR filter to settle down.
One of the interesting properties (well at least to me) of the Hilbert Transform is that you can incorporate a bandpass filter at the same time, so that might be a win too.
Doing this means you don't have to worry about 'zero crossings' or anything like that - you get to pick the points you want to look at the phase of, rather than waiting for zero crossings where you know the phase is one of two values.
It also hints (at least to me), that if I had the choice of 2ms of data or 8ms of data at 1/4th the sample rate, I would take the 8ms of data as any phase difference will be 4x as great, and it is far less work to bandpass filter the frequencies of interest.
PS. If interested, you could convince me to code up a demo...
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version