# How to test sound freq?

Started by July 13, 2008
```First of all: Hello, everybody!

I have a problem that I can't figure myself, so I'm kindly asking you for
help. My application consists of two parts: the first one, which is
generating clean sin tone for a given frequency, and the second one, which
is used to detect signal freq.

I have used FFT to find frequency of input sound, but it seems to
expensive for me, because all I need is to test single freq., rather than
whole bandwidth. Is there any cheaper way (in resources thinking) than that
I've mentioned?

Thank you.

```
```>generating clean sin tone for a given frequency

Simply evaluate x = sin(2 * pi * f * t), where f is your frequency in Hz
and t is the time in seconds at which you wish to calculate x.  The  sine
wave amplitudes will be in x.  To generate an actual tone that you can use,
you will have to find some way to convert the amplitudes to a usable
signal.  This depends on the hardware that you have.  If you have a DAC,
then you might write a program to output the amplitudes as an analog
signal.

Using Matlab, you can generate a sine tone with the following program:

fs = 96000;
period = 1/fs;
timemax = 1;
t = 0:period:(1-period);
freq = 1000;
x = sin(2*pi*freq*t);

You could also write the program in a language such as C.

To determine a signal frequency, the Fast Fourier Transform (FFT) is the
most widely-used method to determine spectral content (which is good if you
have a signal with a power-of-two signal length).  However, if you know the
signal frequency which you want to match, you can detect the frequency by
algorithms particular to DTMF signalling.

Of particular interest is the Goertzel algorithm; you can find some
information here:

http://en.wikipedia.org/wiki/Goertzel_algorithm

```
```
Burgos wrote:
> First of all: Hello, everybody!
>
> I have a problem that I can't figure myself, so I'm kindly asking you for
> help. My application consists of two parts: the first one, which is
> generating clean sin tone for a given frequency, and the second one, which
> is used to detect signal freq.
>
> I have used FFT to find frequency of input sound, but it seems to
> expensive for me, because all I need is to test single freq., rather than
> whole bandwidth. Is there any cheaper way (in resources thinking) than that
> I've mentioned?

DSP and Mixed Signal Design Consultant
http://www.abvolt.com
```
```@namespace

I have made tone generator, using DSound buffers and simply cos(2*pi*f*t)
and I know what frequency is.

I've looked around and I've found Goertzel's algorithm, but I didn't use
it because of DTMF structure (as I remember, it was the sum of two sin
signals). You say that I can detect tone frequency with that algorithm?

I think it is not possible for me to develop frequency counter in C++ :(.

Thank you, both.
```
```"You say that I can detect tone frequency with that algorithm? "

What I meant to say is "sound frequency." Sorry :(.

```
```
Burgos wrote:

>
> I think it is not possible for me to develop frequency counter in C++ :(.

How wonderful. So, you can't just count the number of samples between
the two zero crossings of the signal. Is this because of C++, or C# pehaps?

DSP and Mixed Signal Design Consultant
http://www.abvolt.com

```
```I don't know C#, and I am pretty new in DSP, sorry, don't be ironic :(.

However, thank you for your great suggestion, I think that will do the
trick :).

Thank you!
Greetings for Serbia
```
```Hm...

Now I've looked around and I think that I need to implement noise gate,
too, because what I do is capturing data from LineIn, rather than reading
pcm data from file.
```
```On 13-07-2008 at 22:05:36 Burgos <4burgos@gmail.com> wrote:

> First of all: Hello, everybody!
>
> I have a problem that I can't figure myself, so I'm kindly asking you for
> help. My application consists of two parts: the first one, which is
> generating clean sin tone for a given frequency, and the second one,
> which
> is used to detect signal freq.
>
> I have used FFT to find frequency of input sound, but it seems to
> expensive for me, because all I need is to test single freq., rather than
> whole bandwidth. Is there any cheaper way (in resources thinking) than
> that
> I've mentioned?
>
> Thank you.
>

If you want just to detect appearance of the tone at specific frequency
maybe simple filtering would be enough.

How about filter matched tu sine wave or notch filter or any bandpass
filter?
And than some slicer/amplitude detector/integrator-discriminator somthing.

--
Mikolaj
```