Forums

Bin center of the Goertzel

Started by Thomas Magma June 2, 2008
Hi,

According to this article in Embedded.com 
http://www.embedded.com/story/OEG20020819S0057 'you want the target 
frequencies to be integer multiples of sample_rate/N' so the frequencies are 
centered in their respective bins. Is this correct? Seems to me that if you 
are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, 
then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, 
50-75KHz etc.. and your target frequency falls in between two bins, not 
centered.

Am I missing something?

Thomas


Thomas Magma wrote:
> Hi, > > According to this article in Embedded.com > http://www.embedded.com/story/OEG20020819S0057 'you want the target > frequencies to be integer multiples of sample_rate/N' so the frequencies are > centered in their respective bins. Is this correct? Seems to me that if you > are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, > then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, > 50-75KHz etc.. and your target frequency falls in between two bins, not > centered. > > Am I missing something? > > Thomas > >
Yes. The 'bins' that you get from an FFT are centered around their nominal frequencies, so in your case the '0Hz' bin more or less measures from -12.5kHz to +12.5kHz, the '25kHz' bin extends more or less from 12.5kHz to 37.5kHz, etc. So a 75kHz signal will be nicely centered in the 75kHz bin. Note that while the Goertzel may have, at one time, been the most efficient way of doing this task, many people find it more efficient to do a single-bin DFT, i.e. just multiply your signal by sin(75kHz) and cos(75kHz), sum up the two resulting signals, and measure the amplitude of the result. In some cases you can even do an adequate job of this using square waves for your 'sin' and 'cos', which can be a great resource saver on a small processor with a cruddy multiply. Note also that many people will find the 'modulate and sum' approach more understandable, which means that if your code has to be maintained by others you'll make life easier for them, which will usually rebound favorably on you. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
On Jun 2, 10:23 am, "Thomas Magma" <somewh...@overtherainbow.com>
wrote:
> Hi, > > According to this article in Embedded.comhttp://www.embedded.com/story/OEG20020819S0057'you want the target > frequencies to be integer multiples of sample_rate/N' so the frequencies are > centered in their respective bins. Is this correct? Seems to me that if you > are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, > then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, > 50-75KHz etc.. and your target frequency falls in between two bins, not > centered. > > Am I missing something? > > Thomas
Thomas The bins are centered at 0 kHz, 25 kHz, 50 kHz. If by bin width you mean the mainlobe region where a particular bin has greater response than the neighboring bins, the bins are -12.5 to 12.5 kHz, 12.5 to 37.5 kHz, 37.5 kHz to 62.5 kHz, etc. Dale B. Dalrymple
> Yes. > > The 'bins' that you get from an FFT are centered around their nominal > frequencies, so in your case the '0Hz' bin more or less measures > from -12.5kHz to +12.5kHz, the '25kHz' bin extends more or less from > 12.5kHz to 37.5kHz, etc. So a 75kHz signal will be nicely centered in the > 75kHz bin. > > Note that while the Goertzel may have, at one time, been the most > efficient way of doing this task, many people find it more efficient to do > a single-bin DFT, i.e. just multiply your signal by sin(75kHz) and > cos(75kHz), sum up the two resulting signals, and measure the amplitude of > the result. In some cases you can even do an adequate job of this using > square waves for your 'sin' and 'cos', which can be a great resource saver > on a small processor with a cruddy multiply. > > Note also that many people will find the 'modulate and sum' approach more > understandable, which means that if your code has to be maintained by > others you'll make life easier for them, which will usually rebound > favorably on you. > > --
Thanks and thanks Tim. I'm using a a DSPic running at 40 MIPS so I'd probaly be alright just using the DFT with a sinusoidal look-up. I 've never tried using square waves before, but it probably wouldn't work in my case since I'm also interested in phase information. However I can totally see the advantage of being able to fully understand the algorithm compared to using the Goertzel. Thomas
On Jun 2, 11:09 am, dbd <d...@ieee.org> wrote:
> On Jun 2, 10:23 am, "Thomas Magma" <somewh...@overtherainbow.com> > wrote: > > > Hi, > > > According to this article in Embedded.comhttp://www.embedded.com/story/OEG20020819S0057'youwant the target > > frequencies to be integer multiples of sample_rate/N' so the frequencies are > > centered in their respective bins. Is this correct? Seems to me that if you > > are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, > > then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, > > 50-75KHz etc.. and your target frequency falls in between two bins, not > > centered. > > > Am I missing something? > > > Thomas > > Thomas > > The bins are centered at 0 kHz, 25 kHz, 50 kHz. If by bin width you > mean the mainlobe region where a particular bin has greater response > than the neighboring bins, the bins are -12.5 to 12.5 kHz, 12.5 to > 37.5 kHz, 37.5 kHz to 62.5 kHz, etc.
Minor detail: Tim stated it better when he said this was "more or less" the bin response. Except for the 0th bin and the bins near Fs/4, the "leakage" from the negative frequency image will distort the symmetry of response curve for a rectangular windowed 1-bin DFT or Goertzel filter, so mainlobe for the low bins (other than the 0th) won't be exactly centered. The negative image leakage is also dependent on phase, which needs to be taken into account if one wants to use a more optimal interpolation kernel. . IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M http://www.nicholson.com/rhn/dsp.html
Thomas Magma wrote:
>> Yes. >> >> The 'bins' that you get from an FFT are centered around their nominal >> frequencies, so in your case the '0Hz' bin more or less measures >> from -12.5kHz to +12.5kHz, the '25kHz' bin extends more or less from >> 12.5kHz to 37.5kHz, etc. So a 75kHz signal will be nicely centered in the >> 75kHz bin. >> >> Note that while the Goertzel may have, at one time, been the most >> efficient way of doing this task, many people find it more efficient to do >> a single-bin DFT, i.e. just multiply your signal by sin(75kHz) and >> cos(75kHz), sum up the two resulting signals, and measure the amplitude of >> the result. In some cases you can even do an adequate job of this using >> square waves for your 'sin' and 'cos', which can be a great resource saver >> on a small processor with a cruddy multiply. >> >> Note also that many people will find the 'modulate and sum' approach more >> understandable, which means that if your code has to be maintained by >> others you'll make life easier for them, which will usually rebound >> favorably on you. >> >> -- > > Thanks and thanks Tim. I'm using a a DSPic running at 40 MIPS so I'd probaly > be alright just using the DFT with a sinusoidal look-up. I 've never tried > using square waves before, but it probably wouldn't work in my case since > I'm also interested in phase information. However I can totally see the > advantage of being able to fully understand the algorithm compared to using > the Goertzel. > > Thomas > >
If you have a DSP part that has a good fast MAC operation (and you use it) there is absolutely no point in doing the square-wave thing. Little 8-bit processors will do a bit-check-and-branch a lot faster than a multiply, so you do the square wave algorithm using logic to either add or subtract your signal from an accumulator. With a DSP you just do a big vector dot-product using the MAC and your answer falls into your lap. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Ron N wrote:
> On Jun 2, 11:09 am, dbd <d...@ieee.org> wrote: >> On Jun 2, 10:23 am, "Thomas Magma" <somewh...@overtherainbow.com> >> wrote: >> >>> Hi, >>> According to this article in Embedded.comhttp://www.embedded.com/story/OEG20020819S0057'youwant the target >>> frequencies to be integer multiples of sample_rate/N' so the frequencies are >>> centered in their respective bins. Is this correct? Seems to me that if you >>> are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, >>> then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, >>> 50-75KHz etc.. and your target frequency falls in between two bins, not >>> centered. >>> Am I missing something? >>> Thomas >> Thomas >> >> The bins are centered at 0 kHz, 25 kHz, 50 kHz. If by bin width you >> mean the mainlobe region where a particular bin has greater response >> than the neighboring bins, the bins are -12.5 to 12.5 kHz, 12.5 to >> 37.5 kHz, 37.5 kHz to 62.5 kHz, etc. > > Minor detail: > > Tim stated it better when he said this was "more or less" the > bin response. Except for the 0th bin and the bins near Fs/4, > the "leakage" from the negative frequency image will distort > the symmetry of response curve for a rectangular windowed > 1-bin DFT or Goertzel filter, so mainlobe for the low bins > (other than the 0th) won't be exactly centered. The negative > image leakage is also dependent on phase, which needs to be > taken into account if one wants to use a more optimal > interpolation kernel. >
_And_ the 0Hz bin will get _some_ energy from just about any sinusoid that's not exactly centered on another bin -- and if you use non-rectangular windowing (which smears things out, in return for other benefits) you'll even lose the immunity from the tones centered right on the other bins (at least in the general case). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
On Mon, 02 Jun 2008 17:23:20 GMT, "Thomas Magma"
<somewhere@overtherainbow.com> wrote:

>Hi, > >According to this article in Embedded.com >http://www.embedded.com/story/OEG20020819S0057 'you want the target >frequencies to be integer multiples of sample_rate/N' so the frequencies are >centered in their respective bins. Is this correct? Seems to me that if you >are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, >then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, >50-75KHz etc.. and your target frequency falls in between two bins, not >centered. > >Am I missing something? > >Thomas
Hi Thomas, In K. Banks article, it seems to me that he's restricting his variable "k" to be an integer. Doing that means the Goertzel network will produce results identical to an FFT. However, the Goertzel network's behavior still allows you to detect spectral energy even if the variable "k" is not an integer. So, .... you can use a value of "k" that centers the network's sin(x)/x freq response at any freq you desire (below Fs/2 of course). Good Luck, [-Rick-]
On Thu, 05 Jun 2008 05:47:46 -0700, Rick Lyons
<R.Lyons@_BOGUS_ieee.org> wrote:

>On Mon, 02 Jun 2008 17:23:20 GMT, "Thomas Magma" ><somewhere@overtherainbow.com> wrote: > >>Hi, >> >>According to this article in Embedded.com >>http://www.embedded.com/story/OEG20020819S0057 'you want the target >>frequencies to be integer multiples of sample_rate/N' so the frequencies are >>centered in their respective bins. Is this correct? Seems to me that if you >>are trying to detect say 75KHz with a sample rate of 875000KHz and N = 35, >>then your bins are 25000KHz wide. So the bins are 0-25KHz, 25-50KHz, >>50-75KHz etc.. and your target frequency falls in between two bins, not >>centered. >> >>Am I missing something? >> >>Thomas > >Hi Thomas, > In K. Banks article, it seems to me that >he's restricting his variable "k" to be an >integer. Doing that means the Goertzel network >will produce results identical to an FFT. >However, the Goertzel network's behavior still >allows you to detect spectral energy even if the >variable "k" is not an integer. > >So, .... you can use a value of "k" that >centers the network's sin(x)/x freq response >at any freq you desire (below Fs/2 of course). > >Good Luck, >[-Rick-]
Oops! Poor wording on my part. Please replace the above words "Goertzel network" with "Goertzel algorithm". [-Rick-]