3
\$\begingroup\$

Is it possible to read a set of frequencies with a PIC in such a way that for each frequency a different function is called?

The idea was to send multiple frequencies at different times (no overlapping or super positioning) over one carrier and reading them on the other end resulting in different outputs. I was hoping to avoid having to implement many band-pass filters to channel each frequency to a different pin allowing the PIC to distinguish between the inputs.

In the end there should be ~1000 different frequencies in the audible range, well distinguishable for a micro controller.

Thanks

\$\endgroup\$
4
  • 4
    \$\begingroup\$ If I had known you were going to accept the first answer you get 20 minutes after asking, I wouldn't have bothered with such detail, or probably wouldn't have answered at all. \$\endgroup\$ Commented Aug 8, 2011 at 23:36
  • \$\begingroup\$ Sorry if I upset you by accepting an answer. But I still do very much appreciate your effort of your detailed explanation. Next time I will wait longer. \$\endgroup\$
    – Max Z.
    Commented Aug 8, 2011 at 23:51
  • 1
    \$\begingroup\$ You can change your selected answer if you want. \$\endgroup\$
    – markrages
    Commented Aug 9, 2011 at 3:21
  • 1
    \$\begingroup\$ @Olin - Your answer can (and most likely will) still catch upvotes, and like markrages says, the asker can still change his mind and accept your answer. Happened to me a few times when I answered a question long after it had an accepted answer. \$\endgroup\$
    – stevenvh
    Commented Aug 9, 2011 at 6:17

3 Answers 3

9
\$\begingroup\$

As Brian mentioned, there is something called a FFT (Fast Fourier Transform). It takes a time snippet of signal and returns the amplitude of frequency components in buckets of predetermined frequency and bandwidth. The FFT algorithm is a computationally optimized general Fourier transform that operates on a power of two frequency buckets linearly spread from 0 to the high end of the frequency range it is configured for.

A FFT is computationally expensive, and can only be done on fixed chunks of time domain signal. If you want to get a general frequency content, then it can be appropriate. If you just want to detect the presence of a small number of specific and known frequencies, then it's probably not appropriate. A example of the latter would be DTMF (touch tone) decoding since there are only 8 specific frequencies and you generally want to do the tone decoding continuously, and the frequencies are fairly closely spaced.

To detect the amplitude of a specific frequency in a composite signal, multiply that signal by the sine and cosine of the desired frequency. Low pass filter each of these two product signals separately. The bandwidth of this filter is half the bandwidth the frequency of interest will be detected within. Another way of putting that is that this is the bandwidth of the resulting amplitude output. Now square the two low pass filtered signals and add them together. The result is the square of the amplitude of the signal of interest. You can see where I've simulated this with three adjacent DTMF tones:

The input signal was three adjacent DTMF frequencies for 50ms each with 50ms gaps between. The detection frequency was set up to match the center burst. The blue line is the resulting amplitude squared signal. The low pass filter time constants were adjusted to reject the adjacent frequencies, but still respond well enough within 50 ms (the minimum valid DTMF tone length).

If you need true amplitude, then you'd have to take the square root of the result shown here. For simply detecting the presence of a particular frequency, the magnitude squared is good enough. For other applications the true magnitude may be necessary.

\$\endgroup\$
0
10
\$\begingroup\$

A much simpler solution than has been suggested by some is possible subject to your system meeting the constraints you specify.

You say you are sending one tone at a time. If so, and if you can "square the signal up" so it is presented to the MC (microcontroller) as a square wave and if there is not significant other noise then you can easily determine frequency by any of several methods.

  • Count number of cycles of signal in a finite period. You can do this several times and compare results. Resolution is ~= 1/(f.t) eg at 400 Hz with 1 second counting you get about 1:400 accuracy. At 200 Hz with 3 second sample you get ~= 1:600 accuracy. The accuracy of measuring the time period matters and the accuracy of send frequency. As above, any noise will affect this simple method.

    You don't say how many "channels" you want or how fast a data rate you want but if say you transmitted at from 1 Khz to 2 Khz in 100 Hz steps 1000, 1100, 1200 ...2000) you could get 11 channels. If you counted for 0.1 seconds you would get 1000, 110, 120 ... cycles with a difference between each of 10 counts. With an adequately accurate clock at each end you could easily resolve this. You could drop as low as 5 cycle differences and probably work OK. When you get down to about 2 cycle differences you have to look very carefully at how it all works to avoid errors.

  • Count period of one cycle or of N cycles. Again, your clock accuracy sets a limit. Also here the accuracy of setting zero crossings matters. In the presence of noise this method would also need multiple sends to allow comparison of results.

  • You don't say what you are trying to do and why - and they are an important part of the question. There are many ways of sending data over an audio channel - all are effectiovely "modems" but some are much faster and more error proof than others. Knowing more details would help the best "modem" method to be determined.

\$\endgroup\$
3
\$\begingroup\$

Yes. Sample them at a rate of at least the Nyquist rate. Run a FFT.

You will need a LPF to avoid aliasing.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You will also most likely need a window function. \$\endgroup\$ Commented Aug 9, 2011 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.