DSPRelated.com
Forums

Goertzel, signal conditioning and special coefficients

Started by peterk December 5, 2006
Hello,

  I am designing my first digital filter (for an msp430F2012).
  I am trying to detect an 8,192kHz audio signal and I have some 
  questions that I hope somebody will help me with.

  First, it's a 10 bit ADC with an output in the range 
  0x0000 to 0x03FF. The input voltages are centered around 
  0.75 volts and swing nicely around the 0.75 volts.
  The ADC reading is close to 0x0200 at 0.75 volts.
 
  I have some flexibility in the sampling rate
  but would prefer it to be a divisible of 32.768 kHz, i.e.
  32768/X (X=1,2,4..). My current sampling frequency is 32.768kHz.

  I have been using the algorith described in Kevin Bank's article
  from embedded.com of August/2002  
http://www.embedded.com//showArticle.jhtml?articleID=9900722
  (430 assembler, not C).

   I have:
   block size (N) = 32
     k accordingly should be
     k=(int)(0.5 + ((N * 8192)/32768))k= 0.5 + 8
   which gives k= 8
   w then becomes
     w = (2*PI/N)*k = 1.5707963267948966192313216916398
   cosine = cos(w) = 0
   and coeff
   coeff = 2 * cosine = 0


  For each sample the described algorithm calls for performing
   Q0 = coeff * Q1 - Q2 + sample
   Q2 = Q1
   Q1 = Q0 


OK, I hope you are still there (I am getting to my questions now).

1) As for the ADC sample readings. Should these be signed and perhaps
   offset compensated before being used in the algorithm? I.E. should
   reading 0x0200 become 0x0000 and all readings have 0x0200 subtracted?
   Or can I perhaps use them as is?
2)  As for the "Q0 = coeff * Q1 - Q2 + sample" of the algorithm, could
   that (RELLY?) reduce to "Q0 = -Q2 + sample" (since my coeff = 0)?

3) yes, block size (32) is very small. I know that it gives a wide
   bandwidth (32,768/32  ~ about 1K). Assuming a realtively strong 
   signal, i.e. an 8kHz signal of a substantially higher amplitude
   than any noise source, would this block size be sufficient?
   Well it can't really be larger (for reasons of battery economy)
   and negative answers will not be appreciated. (;-]) 


I have been wondering if Goertzel depends on some degree of
synchronization between the sampling rate frequency and the frequency
that you wish to detect. As an example you could  consider the case
where the sampling frequency is 2x the detection frequency. Theoretically
the sampling could occur exactly at the zero crossings of the
detection frequency. Looking at the algorithm I can't see why it
would not miss that.


thanks a lot for yout time!
  Peterk




On Tue, 05 Dec 2006 05:14:56 -0600, "peterk" <pkobl@hotmail.com>
wrote:

>Hello,
Hello Peterk,
> > I am designing my first digital filter (for an msp430F2012). > I am trying to detect an 8,192kHz audio signal and I have some > questions that I hope somebody will help me with. > > First, it's a 10 bit ADC with an output in the range > 0x0000 to 0x03FF. The input voltages are centered around > 0.75 volts and swing nicely around the 0.75 volts. > The ADC reading is close to 0x0200 at 0.75 volts. > > I have some flexibility in the sampling rate > but would prefer it to be a divisible of 32.768 kHz, i.e. > 32768/X (X=1,2,4..). My current sampling frequency is 32.768kHz.
Ah ha, you have a somewhat special case here. Your filter is centered at Fs/4 !!! (Fs is the sampling freq.)
> > I have been using the algorith described in Kevin Bank's article > from embedded.com of August/2002 >http://www.embedded.com//showArticle.jhtml?articleID=9900722 > (430 assembler, not C). > > I have: > block size (N) = 32 > k accordingly should be > k=(int)(0.5 + ((N * 8192)/32768))k= 0.5 + 8 > which gives k= 8 > w then becomes > w = (2*PI/N)*k = 1.5707963267948966192313216916398 > cosine = cos(w) = 0 > and coeff > coeff = 2 * cosine = 0
Your coeff=0 because your filter is centered at Fs/4.
> > For each sample the described algorithm calls for performing > Q0 = coeff * Q1 - Q2 + sample > Q2 = Q1 > Q1 = Q0 > >OK, I hope you are still there (I am getting to my questions now). > >1) As for the ADC sample readings. Should these be signed and perhaps > offset compensated before being used in the algorithm? I.E. should > reading 0x0200 become 0x0000 and all readings have 0x0200 subtracted? > Or can I perhaps use them as is? >2) As for the "Q0 = coeff * Q1 - Q2 + sample" of the algorithm, could > that (RELLY?) reduce to "Q0 = -Q2 + sample" (since my coeff = 0)?
Yes, because your filter is centered at Fs/4.
> >3) yes, block size (32) is very small. I know that it gives a wide > bandwidth (32,768/32 ~ about 1K). Assuming a realtively strong > signal, i.e. an 8kHz signal of a substantially higher amplitude > than any noise source, would this block size be sufficient? > Well it can't really be larger (for reasons of battery economy) > and negative answers will not be appreciated. (;-])
Peterk, I'm a little suspicious of the article's description of the Goertzel algorithm. The author uses VERY non-standard notation for his discrete sequences, all the time while giving no block diagram of the process. As such, as a reader I'm forced to makes guesses at what I think is his process. OK, with that said, I was puzzled when I read: "After running the per-sample equations N times, it's time to see if the tone is present or not. real = (Q1 - Q2 * cosine) imag = (Q2 * sine) ........" Shouldn't that be: real = (Q0 - Q1 * cosine) imag = (Q1 * sine) ........" ?? I certainly could be wrong.
>I have been wondering if Goertzel depends on some degree of >synchronization between the sampling rate frequency and the frequency >that you wish to detect.
Not that I know of. It's a common misconception that variable "k" must be an integer. As it turns out, the Goertzel algo works just fine for non-integer values of "k".
>As an example you could consider the case >where the sampling frequency is 2x the detection frequency. Theoretically >the sampling could occur exactly at the zero crossings of the >detection frequency. Looking at the algorithm I can't see why it >would not miss that.
Am not exactly sure what you're saying here, but if k = N/2, then your filter is centered at Fs/2. And that is another "special case". I'm afraid to say (off the top of my head) any more about that special scenario. The best place I can direct you are two articles in the IEEE Signal Processing Magazine: (1) Page 74 of the March 2003 issue, and (2) page 110 of the jan. 2004 issue. (It's best if you read both articles.) Or else ya' might have a look at: http://www.numerix-dsp.com/goertzel.html http://cnx.org/content/m12024/latest/
> >thanks a lot for yout time! > Peterk
Good Luck, [-Rick-]
> I have been wondering if Goertzel depends on some degree of > synchronization between the sampling rate frequency and the frequency > that you wish to detect. As an example you could consider the case > where the sampling frequency is 2x the detection frequency. Theoretically > the sampling could occur exactly at the zero crossings of the > detection frequency. Looking at the algorithm I can't see why it > would not miss that.
You're right; that's one reason why you shouldn't in any real implementation sample at the Nyquist rate. The underlying concept behind the Goertzel algorithm is that it is just an efficient way to compute a small number of DFT points without doing a full-blown FFT. For instance, if you have a block of 1024 samples and compute its FFT, you generate 1024 frequency bins at the output. If you only have a few frequencies of interest, then you can use the Goertzel algorithm to perform the same calculation, only with less computational complexity. You can use the Goertzel algorithm to generate, say, 4 bins for specific frequencies faster than you could calculate an FFT on the entire block. So, you should expect the same characteristics in the Goertzel output as you would expect from a DFT. Jason
thanks for helping, Rick

>Ah ha, you have a somewhat special case >here. Your filter is centered at Fs/4 !!! >(Fs is the sampling freq.) >
so I can't use this algorithm (because Ft=Fs/4)? or is the algorithm still OK? regards, Peterk
On Wed, 06 Dec 2006 09:27:55 -0600, "peterk" <pkobl@hotmail.com>
wrote:

> >thanks for helping, Rick > >>Ah ha, you have a somewhat special case >>here. Your filter is centered at Fs/4 !!! >>(Fs is the sampling freq.) >> > >so I can't use this algorithm (because Ft=Fs/4)? >or is the algorithm still OK? > >regards, > Peterk
Hi, Sorry for the delayed reply. Yes, the Goertzel algo still works when your filter is centered at Fs/4. Goos Luck, [-Rick-]