# Goertzel Algorithm using undersampling ?

Started by August 7, 2014
```Hi guys,
https://courses.cs.washington.edu/courses/cse466/12au/calendar/Goertzel-EETimes.pdf
I thought you could help me a bit now.
I'm building laser rangefinder which use FFT to calculate distance. Firstly
I thought I need to implement FFT in code and then look for highest bin in
the spectrum to calculate it's phase ( will have 2 signals - one from sine
generator and other from diode detector and will compare it's phases to
calculate the distance, knowing sine wave length).
But then I found the Goertzel Algorithm. This could give me much more
easier code and save hardvare resources.
The problem is that my sine wave will be about 15MHz and the sampling rate
will be about 1MHz or even lower.
Are you familiar with Goertzel Algorithm using undersampling ? Is this
possible? If yes then maybe you could tell me what changes I need to apply
in the code presented in the arcitle
I really don't know how to move further in my project. Implementing FFT for
2k samples on atmega or xmega is very problematic. If the Goertzel could
work in undersampling that would be great for me.
Regards,
Mariusz

_____________________________
Posted through www.DSPRelated.com
```
```On Thu, 07 Aug 2014 10:47:51 -0500, "MariuszR" <101025@dsprelated>
wrote:

>Hi guys,
>https://courses.cs.washington.edu/courses/cse466/12au/calendar/Goertzel-EETimes.pdf
>I thought you could help me a bit now.
>I'm building laser rangefinder which use FFT to calculate distance. Firstly
>I thought I need to implement FFT in code and then look for highest bin in
>the spectrum to calculate it's phase ( will have 2 signals - one from sine
>generator and other from diode detector and will compare it's phases to
>calculate the distance, knowing sine wave length).
>But then I found the Goertzel Algorithm. This could give me much more
>easier code and save hardvare resources.
>The problem is that my sine wave will be about 15MHz and the sampling rate
>will be about 1MHz or even lower.
>Are you familiar with Goertzel Algorithm using undersampling ? Is this
>possible? If yes then maybe you could tell me what changes I need to apply
>in the code presented in the arcitle
>I really don't know how to move further in my project. Implementing FFT for
>2k samples on atmega or xmega is very problematic. If the Goertzel could
>work in undersampling that would be great for me.
>Regards,
>Mariusz

Hello Mariusz,
If you have an analog sinewave in the neighborhood
of 15 Mhz and you sample it at a sample rate of 1 MHz,
"alaising" will occur and the sinewave will exist (will
be present) in your sampled signal.  The question is,
"What will be the frequency of the original 15 MHz
analog sinewave *after* sampling and aliasing occurs?"

If, after aliasing, your 15 MHz sinewave appears at a
frequency of, say, 255 kHz in your sampled sequence,
then set your Goertzel coefficients' values so that
the Goertzel filter's center frequency is 255 kHz.

It seems to me that you should be able to use the Goertzel
algorithm on an undersampled (aliased) input sequence,
applied to your A/D converter.  That analog A/D input
signal will have some measurable spectral energy.
And *ALL* of that spectral energy will appear (will
exist) in your sampled discete signal, "folded"
back-and-forth (aliased), in the freq range of zero
to one half of one MHz (500 kHz). It seems to me that
you should perform analog bandpass filtering of your
detector's analog output signal, to eliminate as much
analog spectral energy above and below your sinewave's
frequency, before applying that analog signal to

Then again, maybe no analog filtering will be necessary
if the value for 'N' in your Goertzel filter is large
enough.  Who knows.  Anyway, just my thoughts.

[-Rick-]
```
```On Thu, 07 Aug 2014 10:47:51 -0500, MariuszR wrote:

> Hi guys,
> I have recently read an great article about Goertzel Algorithm at
> https://courses.cs.washington.edu/courses/cse466/12au/calendar/Goertzel-
EETimes.pdf
> I thought you could help me a bit now.
> I'm building laser rangefinder which use FFT to calculate distance.
> Firstly I thought I need to implement FFT in code and then look for
> highest bin in the spectrum to calculate it's phase ( will have 2
> signals - one from sine generator and other from diode detector and will
> compare it's phases to calculate the distance, knowing sine wave
> length).
> But then I found the Goertzel Algorithm. This could give me much more
> easier code and save hardvare resources.
> The problem is that my sine wave will be about 15MHz and the sampling
> rate will be about 1MHz or even lower.
> Are you familiar with Goertzel Algorithm using undersampling ? Is this
> possible? If yes then maybe you could tell me what changes I need to
> apply in the code presented in the arcitle
> I really don't know how to move further in my project. Implementing FFT
> for 2k samples on atmega or xmega is very problematic. If the Goertzel
> could work in undersampling that would be great for me.
> Thank you in advance :)

The Goertzel algorithm should work as well as the FFT (although slower
than a complete FFT) after sampling.

You really need to ask two questions: first, will the sampling process
preserves the information you need, and second, will the Goertzel be
adequate to analyze the sampled data.

The Goertzel will work if you expect to need to just look for one tone.
If you really need to know about the whole spectrum, then the FFT will be
faster.

You'll find a short discussion of the sampling issue here:

http://wescottdesign.com/articles/Sampling/sampling.pdf

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
```