Hello, I am writing some software to identify a specific tone in a buffer. I only have to tell the difference between 1800 Hertz and 1400 Hertz. Silence could also be present in the buffer. I have attempted using the FFT, but my math doesn't do too good past Calculus so I am having a tough time with it. Are there any other methods for determining frequency that I am not aware of? What other options do I have? Should I continue the FFT route and ask some questions about that? Thanks, Brett
Tone Indentification
Started by ●November 23, 2005
Reply by ●November 23, 20052005-11-23
vbbrett wrote:> Hello, > I am writing some software to identify a specific tone in a buffer. I > only have to tell the difference between 1800 Hertz and 1400 Hertz. > Silence could also be present in the buffer. I have attempted using > the FFT, but my math doesn't do too good past Calculus so I am having a > tough time with it. Are there any other methods for determining > frequency that I am not aware of? What other options do I have? > Should I continue the FFT route and ask some questions about that? > Thanks, > BrettHow free of noise is the buffer full? Are other frequencies present? Can the frequency change in mid buffer? In the simplest case, you can count samples between zero crossings. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●November 23, 20052005-11-23
Your first question was slightly confusing. If you asked how free of noise the buffer is, then I will say that in real life it may have quite a bit of noise, but not enough to injure the wave in any way. Perhaps the same amount of noise you would get over a short distance phone call. No, there won't be any other frequencies on the line, if there are any, it will just be 1800 and 1400. Plus or Minus 3%. The buffer that I analyze will not have just a single frequency in it. It may go back and forth between the two several times. Each tone will be exhibited for only 22 miliseconds. I don't think I can count the period of the wave, if that's what you meant. The buffer does not show every single change in the wave. It may only show 8 different values for a single period. Brett
Reply by ●November 23, 20052005-11-23
vbbrett wrote:> Your first question was slightly confusing. If you asked how free of > noise the buffer is, then I will say that in real life it may have > quite a bit of noise, but not enough to injure the wave in any way. > Perhaps the same amount of noise you would get over a short distance > phone call. No, there won't be any other frequencies on the line, if > there are any, it will just be 1800 and 1400. Plus or Minus 3%. The > buffer that I analyze will not have just a single frequency in it. It > may go back and forth between the two several times. Each tone will be > exhibited for only 22 miliseconds. > > I don't think I can count the period of the wave, if that's what you > meant. The buffer does not show every single change in the wave. It > may only show 8 different values for a single period.FFT might be appropriate. There are some available for download so you don;t have to code your own. Check out http://www.fftw.org/ Typically, this is a job for the Goertzel algorithm. It isn't difficult to code, particularly since you have 8 samples per cycle (4x oversampling). http://cnx.rice.edu/content/m12024/1.3/ http://ptolemy.eecs.berkeley.edu/papers/96/dtmf_ict/www/node3.html#SECTION00030000000000000000 Rice U. had vert simple Goertzel code, simple enough to do DTMF with a Z-80, but I lost the link. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●November 23, 20052005-11-23
Why does the 8 samples per cycle make the algoritm easier to implement? How does the number of samples affect the output? Why can't I just check 88 samples for a particular frequency? I'm afraid I don't understand the restrictions that are placed on the FFT or this Goertzel algorithm. Thanks, Brett
Reply by ●November 23, 20052005-11-23
Scratch that question. Where do I get some code for the Goertzel algorithm? I found a simple rendition on http://www.mstarlabs.com/dsp/goertzel/goertzel.html It's reproduced here: <other page> Coding the Goertzel Algorithm The coding can be implemented like this: realW = 2.0*cos(2.0*pi*k/N); imagW = sin(2.0*pi*k/N); d1 = 0.0; d2 = 0.0; for (n=0; n<N; ++n) { y = x(n) + realW*d1 - d2; d2 = d1; d1 = y; } resultr = 0.5*realW*d1 - d2; resulti = imagW*d1; The results are the real and imaginary parts of the DFT transform for frequency k. </other page> Is that all I need to do to test for a frequency? The only question I have is what is N and n? I am pretty sure that n is just the loop variable. And I figure that n does NOT equal N. So what is N? (Looks like a wimpy programmer... who ever heard of ++n?) Does anyone else have an example for this Goertzel Algorithm code? Thanks alot, Brett
Reply by ●November 23, 20052005-11-23
vbbrett wrote:> Why does the 8 samples per cycle make the algoritm easier to implement? > How does the number of samples affect the output? Why can't I just > check 88 samples for a particular frequency? I'm afraid I don't > understand the restrictions that are placed on the FFT or this Goertzel > algorithm.It's possible to characterize a signal with just two samples per cycle. In the presence of noise, averaging over many cycles is an improvement. So is having more samples. The identification becomes more robust. The algorithm isn't implemented until it works in the environment you need it for. It is more likely to work without tweaking if the signal is oversampled. Since you seem to understand the discrete FT at least a bit, I'll explain in those terms. A DFT works well when each frequency is at precisely a multiple of the sampling frequency, what is generally referred to as the center of the bin (even though a "bin" isn't real and the concept can can be misleading). Frequencies "off center" "leak" into adjacent bins and even remote ones. We use a "window" to minimize the effect, but that broadens the peaks as it reduces the spurious indications. More samples means more bins, and these effects are reduced proportionally. The peaks we seek, although just as broad relative to a bin, are narrower because the bins themselves are. If you looked at a plot to decide where the peak is, you would have no difficulty locating it. You don't look; you have to write code that manipulates the numbers and decides. The more sharply defined the data, the more likely your code is to be reliable. If you're going to use a DFT, you'll need to know about windows. Check out http://www.dspguide.com/ There's probably something for you at http://www.geocities.com/tppandey/DSPSites.htm You could also use a pair of bandpass IIR filters, one for each frequency, and use the sign of the difference of their outputs (normalized by their sum), as we used to do in analog FSK. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●November 23, 20052005-11-23
vbbrett wrote:> Scratch that question. > > Where do I get some code for the Goertzel algorithm? I found a simple > rendition on http://www.mstarlabs.com/dsp/goertzel/goertzel.html > > It's reproduced here: > <other page> > Coding the Goertzel Algorithm > The coding can be implemented like this: > > realW = 2.0*cos(2.0*pi*k/N); > imagW = sin(2.0*pi*k/N); > > d1 = 0.0; > d2 = 0.0; > for (n=0; n<N; ++n) > { > y = x(n) + realW*d1 - d2; > d2 = d1; > d1 = y; > } > resultr = 0.5*realW*d1 - d2; > resulti = imagW*d1; > > The results are the real and imaginary parts of the DFT transform for > frequency k. > </other page> > > > Is that all I need to do to test for a frequency? The only question I > have is what is N and n? I am pretty sure that n is just the loop > variable. And I figure that n does NOT equal N. So what is N? > (Looks like a wimpy programmer... who ever heard of ++n?) > > Does anyone else have an example for this Goertzel Algorithm code?for (n=0; n<N; ++n) Translation: n=0; start with n, the loop counter, at zero. n<N; continue as long as n is less than the loop limit. This sets the number of iterations per pass. ++n; Increment n. Question: realW = 2.0*cos(2.0*pi*k/N); imagW = sin(2.0*pi*k/N) Shouldn't these have the same amplitude? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●November 23, 20052005-11-23
vbbrett wrote:> Your first question was slightly confusing. If you asked how free of > noise the buffer is, then I will say that in real life it may have > quite a bit of noise, but not enough to injure the wave in any way. > Perhaps the same amount of noise you would get over a short distance > phone call. No, there won't be any other frequencies on the line, if > there are any, it will just be 1800 and 1400. Plus or Minus 3%. The > buffer that I analyze will not have just a single frequency in it. It > may go back and forth between the two several times. Each tone will be > exhibited for only 22 miliseconds. > > I don't think I can count the period of the wave, if that's what you > meant. The buffer does not show every single change in the wave. It > may only show 8 different values for a single period.You might be able to measure the period of the wave by measuring the time between zero crossing, interpolating each and/or averaging several zero crossings. The first question should not seem confusing. If the noise is large enough it could swamp out your signal, cause extra zero crossings or distort their location. The noise might be removable by some filtering. Now for my question: Are the 1800 and 1400 tones seperated by silence, or can their be a transition directly from one tone to the other? If the latter, what might be a good method to determine exactly when these frequency transistions occur? Thanks. -- rhn A.T nicholson d.O.t C-o-M
Reply by ●November 23, 20052005-11-23
Thanks Jerry for the explanation. :-D I did understand the syntax, but what I was asking was what is N? What sort of value does N represent? Thanks for the explanation, it was quite helpful! I think I'll be able to code this yet! Ron: The tones sometimes have silence in between, and in other cases are back to back. Brett






