Reply by Shawn Steenhagen February 23, 20042004-02-23
It wasn't clear in the original post if Atri was trying to detect any signal
which contains some energy at 4.5KHz or a signal which is contains only (or
mostly) energy at 4.5 KHz.  A lot of music (and perhaps some speech) will
contain some energy at 4.5Khz, even loud white noise will contain energy at
4.5KHz, if you are trying to detect a signal that is mostly or entirely a
4.5KHz tone and nothing else you will also need to observe the energy in the
rest of the spectra.

The goertzl algorithm is an excellent choice for this problem, but the
detection logic may need to use similar things done in the DTMF decoders in
order to not be fooled by normal signals encountered.  A simple approach is
to compare the energy of the goertzl output to the energy of the entire
signal.  In a signal that is mostly a tone, these will be similar.

-Shawn Steenhagen

"Maurice Givens" <maurice.givens@ieee.org> wrote in message
news:eb93cce8.0402200828.3529a9fd@posting.google.com...
> Atri Mandal <mandala@ics.uci.edu> wrote in message
news:<40359D7A.12B15FED@ics.uci.edu>...
> > Hi, > > I am writing an application to detect a particular frequency(viz. 4.5 > > Khz) in an input audio signal. I have written the code to capture the > > sound using a microphone; but I have to properly design a digital filter > > which will return TRUE as soon as it detects sound of this frequency in > > the input signal. Also my project demands that I have to detect the > > signal by looking at a very small number of samples e.g. 44. So I will > > apply the digital filter on a window of 44 samples of the input signal > > repeatedly till I get a high response indicating that I have got the > > reqd. frequency. > > > > I know DFT/FFT is an option but are there any better algorithms I can > > use for my project. Please suggest the best algorithm that will do my > > work. I am writing the code in C++ so if anyone can point me to existing > > code on the net that will be really helpful. > > > > Thanks, > > Atri. > > > Here is Matlab code for the Goertzel algm if you just need a > TRUE/FLASE indication. Set a threshold, and if y is greater than the > threshold, then the frequency is detected. > > x = input vector > f = frequency desired > N = number of samples to test over > Fs = sample frequency > > function y = goert(x,f,N,Fs) > > k = fix(0.5 + N*f/Fs); > w = (2*pi/N)*k; > coeff = 2 * cos(w); > Q1 = 0; > Q2 = 0; > for j = 1:N > Q0 = coeff * Q1 - Q2 + x(j); > Q2 = Q1; > Q1 = Q0; > end > y = sqrt(Q1^2 + Q2^2 - Q1 * Q2 * coeff); > > > > Here is code to test the alghm. Plot F aganist y to see the detector > output as a function of frequency. > > fdet is the frequency desired > N = number of samples to test over > Fs = sample frequency > > > function [F,y] = testgoert(fdet,N,Fs) > > t = 0:1/Fs:((1/Fs)*N - (1/Fs)); > k = 1; > for f = fix(fdet/2:(fdet/2)/15:fdet*2) > x = sin(2*pi*f*t); > y(k) = goert(x,fdet,N,Fs); > F(k) = f; > k = k + 1; > end > y = y(:); > F = F(:); > > > Maurice Givens
Reply by Maurice Givens February 23, 20042004-02-23
Atri Mandal <mandala@ics.uci.edu> wrote in message news:<40381039.7751AD38@ics.uci.edu>...
> Hi Maurice, > Thanks for the code for Goertzel algorithm. It's amazing !!!! > But I could not make out why this algo should work .. if you have time > can you please give me a brief explanation as to how this thing works ? > > Thanks, > Atri. > >
It's based on the computation of the kth coefficient of the DFT using a 2nd-order filter. I suggest a Google search. Mauricxe Givens
Reply by Bob Cain February 23, 20042004-02-23
Peter J. Kootsookos wrote:

> Bob Cain <arcane@arcanemethods.com> writes: > > >>Maurice Givens wrote: >> >> >>>y = y(:); >>>F = F(:); >>> >>> >> >>Thanks, Maurice. What do the above two lines do? > > > If it's matlab, they turn y and F into column vectors. e.g. if y is > N x M, then y(:) is NM x 1.
Ah, what APL calls the ravel operation. I've wondered for years how to do that in Matlab and was sorta hoping that's what it meant when I saw it. Thanks, Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein
Reply by Peter J. Kootsookos February 22, 20042004-02-22
Bob Cain <arcane@arcanemethods.com> writes:

> Maurice Givens wrote: > > > y = y(:); > > F = F(:); > > > > > > Thanks, Maurice. What do the above two lines do?
If it's matlab, they turn y and F into column vectors. e.g. if y is N x M, then y(:) is NM x 1. Ciao, Peter K. -- Peter J. Kootsookos "I will ignore all ideas for new works [..], the invention of which has reached its limits and for whose improvement I see no further hope." - Julius Frontinus, c. AD 84
Reply by Atri Mandal February 21, 20042004-02-21
Hi Maurice,
Thanks for the code for Goertzel algorithm. It's amazing !!!!
But I could not make out why this algo should work .. if you have time
can you please give me a brief explanation as to how this thing works ?

Thanks,
Atri.



Maurice Givens wrote:

> Atri Mandal <mandala@ics.uci.edu> wrote in message news:<40359D7A.12B15FED@ics.uci.edu>... > > Hi, > > I am writing an application to detect a particular frequency(viz. 4.5 > > Khz) in an input audio signal. I have written the code to capture the > > sound using a microphone; but I have to properly design a digital filter > > which will return TRUE as soon as it detects sound of this frequency in > > the input signal. Also my project demands that I have to detect the > > signal by looking at a very small number of samples e.g. 44. So I will > > apply the digital filter on a window of 44 samples of the input signal > > repeatedly till I get a high response indicating that I have got the > > reqd. frequency. > > > > I know DFT/FFT is an option but are there any better algorithms I can > > use for my project. Please suggest the best algorithm that will do my > > work. I am writing the code in C++ so if anyone can point me to existing > > code on the net that will be really helpful. > > > > Thanks, > > Atri. > > Here is Matlab code for the Goertzel algm if you just need a > TRUE/FLASE indication. Set a threshold, and if y is greater than the > threshold, then the frequency is detected. > > x = input vector > f = frequency desired > N = number of samples to test over > Fs = sample frequency > > function y = goert(x,f,N,Fs) > > k = fix(0.5 + N*f/Fs); > w = (2*pi/N)*k; > coeff = 2 * cos(w); > Q1 = 0; > Q2 = 0; > for j = 1:N > Q0 = coeff * Q1 - Q2 + x(j); > Q2 = Q1; > Q1 = Q0; > end > y = sqrt(Q1^2 + Q2^2 - Q1 * Q2 * coeff); > > Here is code to test the alghm. Plot F aganist y to see the detector > output as a function of frequency. > > fdet is the frequency desired > N = number of samples to test over > Fs = sample frequency > > function [F,y] = testgoert(fdet,N,Fs) > > t = 0:1/Fs:((1/Fs)*N - (1/Fs)); > k = 1; > for f = fix(fdet/2:(fdet/2)/15:fdet*2) > x = sin(2*pi*f*t); > y(k) = goert(x,fdet,N,Fs); > F(k) = f; > k = k + 1; > end > y = y(:); > F = F(:); > > Maurice Givens
Reply by stuart macgregor February 21, 20042004-02-21
To detect is to decide whether what you have is the desired signal, rather
than the other stuff - noise processes - you would expect to see.

The decision will depend on any consequences of wrong decisions of either
type, and on any prior knowledge of liklihood.  It will also depend
importantly on the null hypothesis - what patterns you expect in the
absence of signal.

Testing for a known frequency sine wave in stationary white noise is prety
simple - just correlate to estimate the amplitude and use the known noise
level.  You can do a Bays decision using the gaussian model or use some
stats cook book confidence rule.

If the noise is more variable you could still model it as gaussian in a
local time-frequency region. You could correlate as before to get the
signal power and filter the residue signal in a time-frequency window to
give the local noise power - the distortion of the pure signal you expect.

There are lots of approaches - I find it best to stick to a simple bays
rule and be honest and careful about the implicit assumptions of the
statistical model.  The problem depends on the noise as well as the
signal.  A tone in speech, a tone in a little or a lot of white noise, a
tone in music, one specific tone amother other tones, a tone with a narrow
range of possible frequencies,... they all demand different tests.

PS

Shouldn't this be in comp.dsp?
Reply by Bob Cain February 20, 20042004-02-20
Maurice Givens wrote:

> y = y(:); > F = F(:); > >
Thanks, Maurice. What do the above two lines do? Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein
Reply by John Smith February 20, 20042004-02-20
There is no detection bandwith specified.  1Khz, 100 Hz, 1 Hz, 0.1 Hz ?
If you get a 4.8 KHz signal, should it be detected or not?    The detection
bandwidth is directly related to the amount of time you have to observe the
signal.    You are really trying to detect is about a 0.001 second burst of
a 4.500 KHz tone. That is 4.5 cycles of wanted tone, which indicates that
the detection bandwidth is very large.  Noise and "selectivity" can be
problems with wide bandwidth. Checkout the signal spectrum or FT of a tone
burst.


"Atri Mandal" <mandala@ics.uci.edu> wrote in message
news:40366E19.D39D464C@ics.uci.edu...
> 44 samples at 44.1K samples/sec. > Thanks for all your help. I'll try out the Goertzel algorithm. > -Atri. > > Jerry Avins wrote: > > > One Usenet Poster wrote: > > > > > Atri Mandal wrote: > > > > > >> Hi, > > >> I am writing an application to detect a particular frequency(viz. 4.5 > > >> Khz) in an input audio signal. I have written the code to capture the > > >> sound using a microphone; but I have to properly design a digital
filter
> > >> which will return TRUE as soon as it detects sound of this frequency
in
> > >> the input signal. Also my project demands that I have to detect the > > >> signal by looking at a very small number of samples e.g. 44. So I
will
> > >> apply the digital filter on a window of 44 samples of the input
signal
> > >> repeatedly till I get a high response indicating that I have got the > > >> reqd. frequency. > > >> > > >> I know DFT/FFT is an option but are there any better algorithms I can > > >> use for my project. Please suggest the best algorithm that will do my > > >> work. I am writing the code in C++ so if anyone can point me to
existing
> > >> code on the net that will be really helpful. > > >> > > >> Thanks, > > >> Atri. > > >> > > > > > > Atri: > > > > > > Try the Goertzel algorithm. > > > > > > Good luck, > > > OUP > > > > "44 samples" at what sample rate? > > > > 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; >
Reply by Atri Mandal February 20, 20042004-02-20
44 samples at 44.1K samples/sec.
Thanks for all your help. I'll try out the Goertzel algorithm.
-Atri.

Jerry Avins wrote:

> One Usenet Poster wrote: > > > Atri Mandal wrote: > > > >> Hi, > >> I am writing an application to detect a particular frequency(viz. 4.5 > >> Khz) in an input audio signal. I have written the code to capture the > >> sound using a microphone; but I have to properly design a digital filter > >> which will return TRUE as soon as it detects sound of this frequency in > >> the input signal. Also my project demands that I have to detect the > >> signal by looking at a very small number of samples e.g. 44. So I will > >> apply the digital filter on a window of 44 samples of the input signal > >> repeatedly till I get a high response indicating that I have got the > >> reqd. frequency. > >> > >> I know DFT/FFT is an option but are there any better algorithms I can > >> use for my project. Please suggest the best algorithm that will do my > >> work. I am writing the code in C++ so if anyone can point me to existing > >> code on the net that will be really helpful. > >> > >> Thanks, > >> Atri. > >> > > > > Atri: > > > > Try the Goertzel algorithm. > > > > Good luck, > > OUP > > "44 samples" at what sample rate? > > 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;
Reply by Stephen M. Fortescue February 20, 20042004-02-20
Atri Mandal <mandala@ics.uci.edu> wrote in message news:<40359D7A.12B15FED@ics.uci.edu>...
> Hi, > I am writing an application to detect a particular frequency (viz. > 4.5 Khz) in an input audio signal. I have written the code to > capture the sound using a microphone; but I have to properly design > a digital filter which will return TRUE as soon as it detects sound > of this frequency in the input signal. Also my project demands > that I have to detect the signal by looking at a very small number > of samples e.g. 44. So I will apply the digital filter on a window > of 44 samples of the input signal repeatedly till I get a high > response indicating that I have got the reqd. frequency. > > I know DFT/FFT is an option but are there any better algorithms > I can use for my project. Please suggest the best algorithm that > will do my work. I am writing the code in C++ so if anyone can > point me to existing code on the net that will be really helpful. > > Thanks, > Atri.
I would be inclined to use regression to fit the sampled signal to: c1 + c2 cos(t 2Pi 4500Hz) + c3 sin(t 2Pi 4500Hz) The amplitude of the 4.5 KHz is then sqrt(c2^2 + c3^2). For best results, the model should also include background signals of known specific frequencies. The inverse matrix used in the regression can be calculated ahead of time since it doesn't change. / \ . | n Sum(cos) Sum(sin) | . A = | Sum(cos) Sum(cos^2) Sum(cos sin) | . | Sum(sin) Sum(cos sin) Sum(sin^2) | . \ / / \ / \ . | c1 | | Sum(y) | . C = | c2 | Y = | Sum(y cos) | . | c3 | | Sum(y sin) | . \ / \ / A C = Y C = A^-1 Y