DSPRelated.com
Forums

What is "bandwidth" of Goertzel algorithm?

Started by Richard Owlett November 15, 2007
Looking at Wikipedia article on Goertzel algorithm I thought I might be 
able to use it as a quick and dirty filter.

I'm interested in looking at formants.
Looking at the spectra of my specific test case, I'd want something from 
10% of center to 1/3 octave but being>= 20db down an octave away.


On Nov 15, 8:48 am, Richard Owlett <rowl...@atlascomm.net> wrote:
> Looking at Wikipedia article on Goertzel algorithm I thought I might be > able to use it as a quick and dirty filter. > > I'm interested in looking at formants. > Looking at the spectra of my specific test case, I'd want something from > 10% of center to 1/3 octave but being>= 20db down an octave away.
Hello Richard, I answered this one a while back see http://groups.google.com/group/comp.dsp/browse_thread/thread/688069085a5312fe/20e570f08a3ffe88?hl=en&lnk=st&q=%2Bcomp.dsp+%2Bclay+%2Bgoertzel+%2Bbandwidth#20e570f08a3ffe88 for details. IHTH, Clay
On Thu, 15 Nov 2007 07:48:26 -0600, Richard Owlett wrote:

> Looking at Wikipedia article on Goertzel algorithm I thought I might be > able to use it as a quick and dirty filter. > > I'm interested in looking at formants. > Looking at the spectra of my specific test case, I'd want something from > 10% of center to 1/3 octave but being>= 20db down an octave away.
To find the pass characteristics of the Goertzel algorithm, take the Fourier transform of the impulse response of the kernel, truncated to the length of the sample you're going to take. You'll find that what you get is a sinc function that's centered around your desired frequency. You'll also find that response added to a sinc function that's centered around the negative of your desired frequency, but if you take the Goertzel for many cycles of the tone then that second response won't confound your answers too much. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
On Nov 15, 7:45 am, Clay <phys...@bellsouth.net> wrote:
> On Nov 15, 8:48 am, Richard Owlett <rowl...@atlascomm.net> wrote: > > > Looking at Wikipedia article on Goertzel algorithm I thought I might be > > able to use it as a quick and dirty filter. > > > I'm interested in looking at formants. > > Looking at the spectra of my specific test case, I'd want something from > > 10% of center to 1/3 octave but being>= 20db down an octave away. > > Hello Richard, > > I answered this one a while back see > > http://groups.google.com/group/comp.dsp/browse_thread/thread/68806908... > > for details.
Interesting... In the above referenced thread, for the gain, Clay writes:
> X(f) = (1/N)*sin(pi*f*N/F)/sin(pi*f/F)
and Tim writes:
> H(theta) = sin((q0 - theta) * N/2) / (q0 - theta) + > sin((q0 + theta) * N/2) / (q0 + theta)
and neither seems to reference the starting or ending phase of the Goertzel filter's impulse response, which should make some difference if the filter's frequency is not exactly periodic within N samples. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
On Nov 15, 1:26 pm, "Ron N." <rhnlo...@yahoo.com> wrote:
> On Nov 15, 7:45 am, Clay <phys...@bellsouth.net> wrote: > > > > > On Nov 15, 8:48 am, Richard Owlett <rowl...@atlascomm.net> wrote: > > > > Looking at Wikipedia article on Goertzel algorithm I thought I might be > > > able to use it as a quick and dirty filter. > > > > I'm interested in looking at formants. > > > Looking at the spectra of my specific test case, I'd want something from > > > 10% of center to 1/3 octave but being>= 20db down an octave away. > > > Hello Richard, > > > I answered this one a while back see > > >http://groups.google.com/group/comp.dsp/browse_thread/thread/68806908... > > > for details. > > Interesting... > In the above referenced thread, for the gain, Clay writes: > > > X(f) = (1/N)*sin(pi*f*N/F)/sin(pi*f/F) > and Tim writes: > > H(theta) = sin((q0 - theta) * N/2) / (q0 - theta) + > > sin((q0 + theta) * N/2) / (q0 + theta) > > and neither seems to reference the starting or ending > phase of the Goertzel filter's impulse response, which > should make some difference if the filter's frequency > is not exactly periodic within N samples.
I'll retract this last statement for Tim's formulation, since whether or not the zeros of the sine or Sinc functions overlap seems to contain information about any fractional remainders of a period.
> > IMHO. YMMV. > -- > rhn A.T nicholson d.0.t C-o-M
On Nov 15, 4:38 pm, "Ron N." <rhnlo...@yahoo.com> wrote:
> On Nov 15, 1:26 pm, "Ron N." <rhnlo...@yahoo.com> wrote: > > > > > > > On Nov 15, 7:45 am, Clay <phys...@bellsouth.net> wrote: > > > > On Nov 15, 8:48 am, Richard Owlett <rowl...@atlascomm.net> wrote: > > > > > Looking at Wikipedia article on Goertzel algorithm I thought I might be > > > > able to use it as a quick and dirty filter. > > > > > I'm interested in looking at formants. > > > > Looking at the spectra of my specific test case, I'd want something from > > > > 10% of center to 1/3 octave but being>= 20db down an octave away. > > > > Hello Richard, > > > > I answered this one a while back see > > > >http://groups.google.com/group/comp.dsp/browse_thread/thread/68806908... > > > > for details. > > > Interesting... > > In the above referenced thread, for the gain, Clay writes: > > > > X(f) = (1/N)*sin(pi*f*N/F)/sin(pi*f/F) > > and Tim writes: > > > H(theta) = sin((q0 - theta) * N/2) / (q0 - theta) + > > > sin((q0 + theta) * N/2) / (q0 + theta) > > > and neither seems to reference the starting or ending > > phase of the Goertzel filter's impulse response, which > > should make some difference if the filter's frequency > > is not exactly periodic within N samples. > > I'll retract this last statement for Tim's formulation, > since whether or not the zeros of the sine or Sinc functions > overlap seems to contain information about any fractional > remainders of a period. > > > > > > > IMHO. YMMV. > > -- > > rhn A.T nicholson d.0.t C-o-M- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
Hello Ron, A phase correction term can be added to make it exact, but if one is looking at least several cycles and the frequency error is less than half of a bin spacing, I've found the relative error for this simple formula due to phase to be under 1%. This should be good enough for most applications. Clay
On Nov 15, 5:48 am, Richard Owlett <rowl...@atlascomm.net> wrote:
> Looking at Wikipedia article on Goertzel algorithm I thought I might be > able to use it as a quick and dirty filter. > > I'm interested in looking at formants. > Looking at the spectra of my specific test case, I'd want something from > 10% of center to 1/3 octave but being>= 20db down an octave away.
The Goertzel algorithm produces roughly the same thing as the magnitude from 1-bin of a DFT/FFT. The bandwidth will vary inversely proportional to the length N (with the bin spacing being fs/N). But the window applied (or lack thereof) is the real issue for your bandwidth requirements. If you don't window your data (that's the same thing as a rectangular window), the 1st side lobe in the frequency response is only about 13 db down. If you want > 20 db down without a window, you will have to go more than 3.5 bins away from your Goertzel bin center. Or you could window your data pre-Goertzel. For the raw 1-bit DFT or Goertzel filter, I get this frequency response: f0 = Goertzel or bin center frequency sr = sample rate n is the DFT or filter length (f-f0)/sr = bin offset H(f) = sin(n * pi*(f-f0)/sr) / (n * sin(pi*(f-f0)/sr)) +- correction_factor The correction_factor is sin(n * pi*(f+f0)/sr) / (n * sin(pi*(f+f0)/sr)) The correction_factor is added if the data is an even function in the window, subtracted if the data is an odd function in the window, and some ratio in-between for data that has a mix of evenness/oddness. So the phase of the data, relative to the window center, does make a difference. This is due to fact that the negative frequency Sinc convolution is the the complex conjugate of the positive frequency Sinc convolution for real data. The correction factor is "small" if the bin number (f0/sr) is "big", and thus usually ignored, as Clay said earlier in this thread. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Ron N. wrote:

> On Nov 15, 5:48 am, Richard Owlett <rowl...@atlascomm.net> wrote: > >>Looking at Wikipedia article on Goertzel algorithm I thought I might be >>able to use it as a quick and dirty filter. >> >>I'm interested in looking at formants. >>Looking at the spectra of my specific test case, I'd want something from >>10% of center to 1/3 octave but being>= 20db down an octave away. > > > The Goertzel algorithm produces roughly the same thing > as the magnitude from 1-bin of a DFT/FFT. The bandwidth > will vary inversely proportional to the length N > (with the bin spacing being fs/N). > > But the window applied (or lack thereof) is the real > issue for your bandwidth requirements. > > If you don't window your data (that's the same thing as > a rectangular window), the 1st side lobe in the frequency > response is only about 13 db down. If you want > 20 db > down without a window, you will have to go more than > 3.5 bins away from your Goertzel bin center. Or you > could window your data pre-Goertzel. > > For the raw 1-bit DFT or Goertzel filter, I get this > frequency response: > > f0 = Goertzel or bin center frequency > sr = sample rate > n is the DFT or filter length > (f-f0)/sr = bin offset > > H(f) = sin(n * pi*(f-f0)/sr) / (n * sin(pi*(f-f0)/sr)) > +- correction_factor > > The correction_factor is > sin(n * pi*(f+f0)/sr) / (n * sin(pi*(f+f0)/sr)) > > The correction_factor is added if the data is an even > function in the window, subtracted if the data is an odd > function in the window, and some ratio in-between for data > that has a mix of evenness/oddness. So the phase of the > data, relative to the window center, does make a difference. > This is due to fact that the negative frequency Sinc > convolution is the the complex conjugate of the positive > frequency Sinc convolution for real data. > > The correction factor is "small" if the bin number > (f0/sr) is "big", and thus usually ignored, as Clay > said earlier in this thread. > > > > IMHO. YMMV. >
MMDV -- My Mileage *DOES* Vary :) Actually I get more mileage from your answer than you might expect. 1. You saved me the arithmetic of applying the formula. Actually +-4 bins for 20db down is a nice match for my problem. Judicious choice of window width can make it a good match. 2. It also gave me an idea idea on how to apply something Tim Wescott said in my related thread "Am I reinventing Goertzel etc?"
On Nov 16, 6:01 pm, "Ron N." <rhnlo...@yahoo.com> wrote:
> On Nov 15, 5:48 am, Richard Owlett <rowl...@atlascomm.net> wrote: > > Looking at Wikipedia article on Goertzel algorithm I thought > > I might be able to use it as a quick and dirty filter.
...
> The Goertzel algorithm produces roughly the same thing > as the magnitude from 1-bin of a DFT/FFT. The bandwidth > will vary inversely proportional to the length N > (with the bin spacing being fs/N).
...
> For the raw 1-bit DFT or Goertzel filter, I get this > frequency response: > > f0 = Goertzel or bin center frequency > sr = sample rate > n is the DFT or filter length > (f-f0)/sr = bin offset > > H(f) = sin(n * pi*(f-f0)/sr) / (n * sin(pi*(f-f0)/sr)) > +- correction_factor > > The correction_factor is > sin(n * pi*(f+f0)/sr) / (n * sin(pi*(f+f0)/sr)) > > The correction_factor is added if the data is an even > function in the window, subtracted if the data is an odd > function in the window, and some ratio in-between for data > that has a mix of evenness/oddness. So the phase of the > data, relative to the window center, does make a difference. > This is due to fact that the negative frequency Sinc > convolution is the the complex conjugate of the positive > frequency Sinc convolution for real data.
Just to complete the above frequency response equation, if the phase ph(f) of the input spectrum with respect to the center of the rectangular window is known, then you can correct the frequency response using the vector sum: s1 = sin(n * pi*(f-f0)/sr) / (n * sin(pi*(f-f0)/sr)) s2 = sin(n * pi*(f+f0)/sr) / (n * sin(pi*(f+f0)/sr)) H(f) = (s1^2 + s2^2 + 2*s1*s2*cos(2 * ph(f)) This equation seems to work even if neither f or f0 is periodic in a window of length n. That's turns out to be another difference between a 1-bin DFT and Goertzel. A DFT/FFT only calculates correlations against periodic sinusoids in the DFT aperature. A Goertzel filter can be used for correlation against any frequency, irrespective of window length or periodicity.
> The correction factor is "small" if the bin number > (f0/sr) is "big", and thus usually ignored, as Clay > said earlier in this thread.
Also, n * sin(w) is close to n * w for very small w, giving the standard Sinc formulation.
> IMHO. YMMV. > -- > rhn A.T nicholson d.0.t C-o-M