DSPRelated.com
Forums

Some Goertzel questions

Started by phuture_project June 23, 2004
.... 
> Q3 : If i use a classic FFT, how can i get the magnitude at 9 kHz? I > guess that if Fs (sampling frequency) is 140 kHz for example and if i > chose N=256, the FFT will compute the real and imaginary part of the > signal for each frequency between 0 and Fs/2, with a space between > these frequencies of Fs/2N=273.438 Hz. Am i wrong? If i'm right, i > guess the results are saved on a table et so that it's possible to > find in which position the results of the about 9 kHz is. And if i > succeed in finding the real and imaginary parts i can determine the > magnitude. Is this right or wrong? > I looked at the functions given by TI in dsplib. There is one called > RFFT256.asm. I thought i could use it, but i can't see how i can find > the results of the FFT. Are they put in the same table in which the > input samples were saved before the FFT? >
I recommend using the chirp-z transform over a narrow band that bounds the 9KHz target frequency (say, 8-10KHz). Using a 256 point transform you will get better than 10Hz resolution.
"Tim Wescott" <tim@wescottnospamdesign.com> wrote in message
news:10djo9npchmag4a@corp.supernews.com...
> Jon Harris wrote: > > > "Tim Wescott" <tim@wescottnospamdesign.com> wrote in message > > news:10djhl69rs3hlbb@corp.supernews.com... > > > > At any rate, I've found 32-bit floating point implemented with 40-bit > > accumulators (SHARC) to be quite adequate for the audio tasks I've been
using it
> > for. I would imagine that it would be more than enough for a simple
Goertzel
> > algorithm on audio data (which is probably only has 16 or at most 20 useful
bits
> > to begin with). > > > > > Probably because you're doing all FIR filters. IIR filters are very > sensitive to truncation, particularly if they are casually written (such > as the Goertzel examples that I've found that use the controller > canonical form). Thinking 24 (ok, ok -- 25) bits is enough is a common > pitfall, and one I've dug myself out of numerous times.
Actually, I quite a few IIR filters. But you are right that direct forms with "extreme" coefficients do not work well even with 32-bit IEEE FP. Storing the feedback elements using the 40-bit precision helped somewhat, but switching to another filter form was the ultimate answer. Getting back to the original topic, when I implemented the Goertzel algorithm, I found 32-bit IEEE FP to be sufficient.
On Wed, 23 Jun 2004 05:03:16 -0700, phuture_project wrote:

> My aim is to determine the magnitude of an analog incoming signal at 9 > kHz. This incoming signal is made of several frequencies, let's say from 0
shouldn't the magintude of the complex inner product of your signal with just cos()+isin() [cos() and sin() with the appropriate frequency = 9khz] be what you want? sorry, complete dsp newbie here.. So don't do a full FT, but just the inner product with the appropriate cos+isin... flo -- Palimm Palimm!
florian schmidt wrote:

> On Wed, 23 Jun 2004 05:03:16 -0700, phuture_project wrote: > > >>My aim is to determine the magnitude of an analog incoming signal at 9 >>kHz. This incoming signal is made of several frequencies, let's say from 0 > > > shouldn't the magintude of the complex inner product of your signal with > just cos()+isin() [cos() and sin() with the appropriate frequency = 9khz] > be what you want? > > sorry, complete dsp newbie here.. So don't do a full FT, but just the > inner product with the appropriate cos+isin... > > flo >
Thats basically what the Goertzel algorithm does, it just uses an IIR to do it. And yes, convolving with sin and cos would do the trick, and you could even apply some interesting windows to it to control your passband. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Hi guys,

Thanks for all your answers. Apparently it was the occasion to open a
debate! (floating point).

Hope you don't mind but i still have questions.

Jerry wrote:
>In order to measure any quantity, you need to decide how it is to be >defined in your case. In the case of magnitude, what you have is a >number. The way that number relates to the voltage you want to
measure
>depends on both hardware and software. The sensitivity of the ADC and >gain before it is the hardware part. What your program does with the >numbers that come from it is the software part. These can be lumped >together into a single calibration step of relating the final numbers
to
>a known voltage that causes it. A sine that goes from 0.5 V to 2 V
has a
>DC offset of 1.25 V. That is the amount which, if subtracted from it, >would make it symmetrical about zero. The amplitude (a more specific >term than magnitude*) is half the peak-to-peak value, or .75 V.
The ADC i use is the AD7827 from AD. It's an 8 bit one. The analog input stands signals from 0 to 2,5V. So when i read a sample value, i guess the corresponding voltage is defined by : (sample_value*2,5)/256. I think that's right since it gives me good results. So here is my "sample and goertzel loop" : do { Q1=0; Q2=0; for(j=0;j<N;j++) { *(volatile unsigned int *)0x0007 &=0xDFFF; /* bit XF=0 => CONVST input (AD7827)=0=>acquisition start */ *(volatile unsigned int *)0x0007 |=0x2000; /* bit XF=1 => CONVST input(AD7827)=1 */ /* Clock signal generation */ McBSP0_write(); /* sample read and save */ t[j]=McBSP0_read(); CalculQ(); /* compute Q0,Q1 and Q2 */ } magnitude=Calculmagnitude(); /* magnitude determination */ } while(1); In CalculQ() i do the following things : void CalculQ() { tension=(t[j]*2.5)/256; Q0=coeff*Q1-Q2+tension; Q2=Q1; Q1=Q0; } So i first transform the value given by the ADC into the corrersponding voltage. Is this good or not? Jerry wrote:
>The amplitude (a more specific term than magnitude*)
I know about offset and amplitude. But as the documentation i read about the Goertzel algorithm says the result one gets is the magnitude of the signal i wondered what is the magnitude of a sine. Is the magnitude the absolute value of the amplitude? In this case the magnitude is the amplitude, isn't it? Jerry wrote:
>Unless the signal that interests you has a >very stable and known frequency, you need to pay attention to the >effective bandwidth of the filter.
Excuse me but i can't see what is the bandwith of the filter. I mean i know what it is but i can't see what is its value here? The frequency of the sine looks stable. It's really 9 kHz. As far as floating-point numbers are concerned, unfortunately my DSP is a fixed-point one. So i guess i can't use floating point numbers. Is this right? To answer to another question : i use the form Q1^2+Q2^2-Q1*Q2*coeff. Another and last question : when we compute the terms cosine (cos w) and sine (sin w) is w in radians or degree? Is it important? Anyway thanks for your answers.
phuture_project wrote:

   ...

> The ADC i use is the AD7827 from AD. It's an 8 bit one. The analog > input stands signals from 0 to 2,5V. So when i read a sample value, i > guess the corresponding voltage is defined by : > (sample_value*2,5)/256. I think that's right since it gives me good > results.
8-bit signed numbers range from -128 20 +127 Even if the ADC doesn't directly measure negative quantities such as you find in signals with no DC offset, the overall circuit probably does. You can think of what you read as a number that represents the voltage AT THE INPUT TO THE A/D, the scale being 2.5/128 or 20/1024; about 20 mv steps. ...
> So i first transform the value given by the ADC into the > corrersponding voltage. Is this good or not?
There's no need to do that at this point. Working with the numbers as read is fine.
> I know about offset and amplitude. But as the documentation i read > about the Goertzel algorithm says the result one gets is the magnitude > of the signal i wondered what is the magnitude of a sine. Is the > magnitude the absolute value of the amplitude? In this case the > magnitude is the amplitude, isn't it?
We all talk about magnitude, it being a generalized unsigned size. Generally, it's the same as amplitude, being the length of a phasor, sqrt(Re^2 + Im^2). From an oscilloscope, we often read twice that; peak to peak. In power work (yes, DSPs control motors and power lines) we use RMS, which for single sinusoids is .707*amplitude.
>>Unless the signal that interests you has a >>very stable and known frequency, you need to pay attention to the >>effective bandwidth of the filter. > > > Excuse me but i can't see what is the bandwith of the filter. I mean i > know what it is but i can't see what is its value here? > The frequency of the sine looks stable. It's really 9 kHz.
You don't need to worry about bandwidth if the frequency is stable. With an FFT, you do need to chose the sample rate so that 9000 Hz is exactly a bin center. With Goertzel, you don't. See a discussion at http://groups.google.com/groups?q=%22goertzel+algorithm%22+fractional+k
> As far as floating-point numbers are concerned, unfortunately my DSP > is a fixed-point one. So i guess i can't use floating point numbers. > Is this right?
You don't need to use floating point. You do need to use fractional fixed point. Somewhere on Rice University's web site -- I've lost the link -- there is code efficient enough to run on an 11 MHz 8032.
> To answer to another question : i use the form Q1^2+Q2^2-Q1*Q2*coeff.
What was the question?
> Another and last question : when we compute the terms cosine (cos w) > and sine (sin w) is w in radians or degree? Is it important?
You can compute in mils if you choose to (although I can't imagine why you would), or in fractions of a circle (which is computationally convenient if the denominators are powers of two).
> Anyway thanks for your answers.
You're welcome. I hope they're right and I hope they help. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Hi Jerry,

> 8-bit signed numbers range from -128 20 +127 Even if the ADC doesn't > directly measure negative quantities such as you find in signals with no > DC offset, the overall circuit probably does. You can think of what you > read as a number that represents the voltage AT THE INPUT TO THE A/D, > the scale being 2.5/128 or 20/1024; about 20 mv steps.
I don't really understand what you say. For me as the input of the ADC must be between 0 and 2,5 V and as it's an 8 bit ADC, 0V will give 0000b and 2,5V will give 1111b. The resolution will be (2,5 - 0)/(2^8)=0.009766 V. So when i read in the ADC output the value 180, i think it corresponds to a voltage of about 180*0.009766V=1,75781. I don't understand why you 're talking about signed numbers. I know the input signal isn't negative so i use unsigned numbers. Could you explain your point of view?
> We all talk about magnitude, it being a generalized unsigned size. > Generally, it's the same as amplitude, being the length of a phasor, > sqrt(Re^2 + Im^2). From an oscilloscope, we often read twice that; peak > to peak. In power work (yes, DSPs control motors and power lines) we use > RMS, which for single sinusoids is .707*amplitude.
ok!
> You don't need to worry about bandwidth if the frequency is stable. With > an FFT, you do need to chose the sample rate so that 9000 Hz is exactly > a bin center. With Goertzel, you don't. See a discussion at > http://groups.google.com/groups?q=%22goertzel+algorithm%22+fractional+k
The frequency looks stable. But i still have varying results! I try to vary the frequency of the signal but the result keeps on varying. I've got a question about k : what is its use? Sorry for this idiot question but as we have the following equations: k=(N*target_frequency)/F_sample omega=(2*Pi*k)/N I guess that : omega=(2*Pi*N*target_frequency)/(F_sample*N) Ans so : omega=(2*Pi*target_frequency)/F_sample If we modify N, k is modified but omega isn't! And as we don't need k for other calculations, k is used for nothing! Maybe i'm too tired and i alk nonsense, but am i wrong?
> You don't need to use floating point. You do need to use fractional > fixed point. Somewhere on Rice University's web site -- I've lost the > link -- there is code efficient enough to run on an 11 MHz 8032.
What is fractional fixed point? In fact in my program i use float numbers. Thanks for the link, i will study it as soon as possible.
> > To answer to another question : i use the form Q1^2+Q2^2-Q1*Q2*coeff. > > What was the question?
I don't remember now. It's not important in fact. It wasn't one of your question. As my prog doesn't work, I've just tried the prog given by Kevin Banks in http://www.embedded.com/story/OEG20020819S0057. First i thought it works. But i've noticed one thing : when we increase N the final result increases too. I can understand it, i think the reason is that as N is bigger the calculations are made more times (oups i don't think this sentence is right in english!). But it disturbs me : normally we should obtain the same result since it deals with the magnitude of the signal. This magnitude doesn't depend on N?! Could you explain me why this fact happens? Maybe I'm too tired again! That's all for the moment!
> You're welcome. I hope they're right and I hope they help. > Jerry
It helps. Thanks again.
phuture_project wrote:

> Hi Jerry, > > >>8-bit signed numbers range from -128 20 +127 Even if the ADC doesn't >>directly measure negative quantities such as you find in signals with no >>DC offset, the overall circuit probably does. You can think of what you >>read as a number that represents the voltage AT THE INPUT TO THE A/D, >>the scale being 2.5/128 or 20/1024; about 20 mv steps. > > > I don't really understand what you say. For me as the input of the ADC > must be between 0 and 2,5 V and as it's an 8 bit ADC, 0V will give > 0000b and 2,5V will give 1111b. The resolution will be (2,5 - > 0)/(2^8)=0.009766 V. So when i read in the ADC output the value 180, i > think it corresponds to a voltage of about 180*0.009766V=1,75781. I > don't understand why you 're talking about signed numbers. I know the > input signal isn't negative so i use unsigned numbers. Could you > explain your point of view?
I'm embarrassed at having overlooked the obvious at first. At least I made my assumption explicit: the measurements are bipolar, and the numbers must be made to match. Sinusoids have positive and negative values. Circuits with only positive power supplies have difficulty dealing with negative inputs. In your case, this conflict is resolved adding an offset of 1.25 V (half of full scale) to the signal before it reaches the input of the A/D. For the numbers to represent the actual signal, you have to remove the offset with software. You can subtract 0x100 or you can invert the most significant bit (XOR with 0x100), thereby converting it to a sign bit. It's not obvious that an offset can affect the output of a bandpass filter. Nevertheless, it's possible that using offset quantities for your analysis generates overflows that cause your erratic results. Fix that much before you go on to the next issue. Thare are plenty of helpful souls here who can discuss the innards of a Goertzel far better than I. ... Jerry -- A professional has already made all the mistakes, and has learned how to avoid most of them and fix the rest. I haven't made enough mistakes yet. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins wrote :
  ...

Thank you!
Nobody wants to help me anymore??