EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Signal strength at some fixed frequency

Started by David Ashley October 17, 2006
Can someone point me to a simple algorithm to compute
the signal strength at some frequency? Say I've got 1024
samples, 16 bit signed values, at 44100 hz, and I want
to know how much of 440 hz is present in the signal.

Thanks--
Dave

-- 
David Ashley                http://www.xdr.com/dash
Embedded linux, device drivers, system architecture
David Ashley wrote:

> Can someone point me to a simple algorithm to compute > the signal strength at some frequency? Say I've got 1024 > samples, 16 bit signed values, at 44100 hz, and I want > to know how much of 440 hz is present in the signal. > > Thanks-- > Dave >
You can do it by correlation -- multiply your signal by sine and cosine waves at 440Hz, add the results, then find the RMS of those two numbers. Or you can do it using the Goertzel algorithm -- it's a favorite of CS types, it does the job, but it has lots of subtle details to it that most cookbook solutions overlook. OTOH, there are cookbook solutions out there... -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html
On Tue, 17 Oct 2006 19:33:13 -0700, David Ashley
<dash@nowhere.net.dont.email.me> wrote:

>Can someone point me to a simple algorithm to compute >the signal strength at some frequency? Say I've got 1024 >samples, 16 bit signed values, at 44100 hz, and I want >to know how much of 440 hz is present in the signal.
With such small number of samples, you just get the amount of signal in the neighbourhood of 440 Hz, perhaps sufficient for some "real time analyzer" but definitively not for instrument tuning. Paul
"Paul Keinanen" <keinanen@sci.fi> wrote in message 
news:jdnbj296cljmvoklamioj6b03q6s1cgc7s@4ax.com...
> On Tue, 17 Oct 2006 19:33:13 -0700, David Ashley > <dash@nowhere.net.dont.email.me> wrote: > >>Can someone point me to a simple algorithm to compute >>the signal strength at some frequency? Say I've got 1024 >>samples, 16 bit signed values, at 44100 hz, and I want >>to know how much of 440 hz is present in the signal. > > With such small number of samples, you just get the amount of signal > in the neighbourhood of 440 Hz, perhaps sufficient for some "real time > analyzer" but definitively not for instrument tuning. > > Paul >
Compute the correlation with a 440 Hz sine wave.
Tim Wescott wrote:
> David Ashley wrote: > >> Can someone point me to a simple algorithm to compute >> the signal strength at some frequency? Say I've got 1024 >> samples, 16 bit signed values, at 44100 hz, and I want >> to know how much of 440 hz is present in the signal. >> >> Thanks-- >> Dave >> > You can do it by correlation -- multiply your signal by sine and cosine > waves at 440Hz, add the results, then find the RMS of those two numbers. > > Or you can do it using the Goertzel algorithm -- it's a favorite of CS > types, it does the job, but it has lots of subtle details to it that > most cookbook solutions overlook. OTOH, there are cookbook solutions > out there... >
I tried Goertzel and the results look promising. I want to use integer math but the Goertzel sample code I got from Wikipedia uses doubles, and the numbers balloon up. One tunable was the number of samples used in the calculation. Thanks-- Dave -- David Ashley http://www.xdr.com/dash Embedded linux, device drivers, system architecture
It may not be that simple. You will see truncation and leakage effect.
Then you start to think about the window, then you need more than one
spectrum line to calculate the overall rms.

If he wants to achieve an estimation with high accuracy, I have not
seen a simple answer yet.

D.S.


On Oct 17, 10:33 pm, David Ashley <d...@nowhere.net.dont.email.me>
wrote:
> Can someone point me to a simple algorithm to compute > the signal strength at some frequency? Say I've got 1024 > samples, 16 bit signed values, at 44100 hz, and I want > to know how much of 440 hz is present in the signal. > > Thanks-- > Dave > > -- > David Ashley http://www.xdr.com/dash > Embedded linux, device drivers, system architecture
Tim Wescott has the right idea. It's also called synchronous demodulation. It simple and works quite well. gm
I recall an article in Circuit Cellar where they implemented the
Goertzel on an 8 bit micro without using floating point math. Since the
number of frequencies they were looking for was limited (as in your
case) they "pre-calculated" some of the operations needed to compute
the magnitude that you're looking for. They also did some
approximations to simplify the math. Search circuit cellars website. It
may work for your needs.

-Ed Rivas


> I tried Goertzel and the results look promising. I want to use > integer math but the Goertzel sample code I got from > Wikipedia uses doubles, and the numbers balloon up. One > tunable was the number of samples used in the calculation. > > Thanks-- > Dave > > > -- > David Ashley http://www.xdr.com/dash > Embedded linux, device drivers, system architecture
rivas.ed wrote:
> I recall an article in Circuit Cellar where they implemented the > Goertzel on an 8 bit micro without using floating point math. Since the > number of frequencies they were looking for was limited (as in your > case) they "pre-calculated" some of the operations needed to compute > the magnitude that you're looking for. They also did some > approximations to simplify the math. Search circuit cellars website. It > may work for your needs. > > -Ed Rivas
I did find a code snippet on CC related to a design contest, I think it was a complete phone answering machine. It used Goertzel for the tone recognition, probably for data entry. There was a small function referred to but it wasn't complete. It was obviously integer math but seemed iffy. One section showed ">>15" and another ">> AMP_BITS". But the code to set up the coefficients and the definition of AMP_BITS wasn't included. I figured I'd just play around with it when I next get a chance. Thanks-- -Dave -- David Ashley http://www.xdr.com/dash Embedded linux, device drivers, system architecture
Tim Wescott <tim@seemywebsite.com> wrote:
> David Ashley wrote: > >> Can someone point me to a simple algorithm to compute >> the signal strength at some frequency? Say I've got 1024 >> samples, 16 bit signed values, at 44100 hz, and I want >> to know how much of 440 hz is present in the signal. >> >> Thanks-- >> Dave >> > You can do it by correlation -- multiply your signal by sine and cosine > waves at 440Hz, add the results, then find the RMS of those two numbers. > > Or you can do it using the Goertzel algorithm -- it's a favorite of CS > types, it does the job, but it has lots of subtle details to it that > most cookbook solutions overlook. OTOH, there are cookbook solutions > out there...
Which makes me wonder: does anybody have recomendations on an allround DSP cookbook for embedded programmers, especially the non-mathematicians? I'm thinking of something describing the dirty details of sampling theory (Tim Wescott's "what Nyquist didn't say"!), introduction to FIR/IIR filters and other alternatives, with practical guidlines on implemententation, also on smaller CPU's without FPU hardware, and 'tricks' from the more experienced in the field. The 'hackers delight' version about digital signal processing ? -- :wq ^X^Cy^K^X^C^C^C^C

The 2024 Embedded Online Conference