2
\$\begingroup\$

I have a 3.3 V square wave that consists of groups of 5 pulses at either 12.5 khz and 15.625 khz. Each group of 5 pulses represents either a 1 or a 0. I would like this signal to be passed to a smartphone through the microphone input.

From what I have read (please correct me if I am wrong) the voltage will need to come down to a few mV, the signal will need to be AC coupled. Will the phone be able to consistently differentiate between the frequencies or will some sort of frequency change be required?

What circuitry would be recommended for accomplishing this task?

\$\endgroup\$
  • \$\begingroup\$ 12.5~15.625 khz are well within the human range of hearing, and most phone microphone range of frequencies they are capable of sampling. \$\endgroup\$ – Passerby Aug 6 '13 at 19:16
0
\$\begingroup\$

A simple voltage divider will bring the voltage down, though exactly what resistor values to use to be optimal for your phone will depend -- the input levels of phones are far from standardized. I would use a potentiometer and turn it until I was in range.

To detect the input pulses, you could use FFT-based techniques as discussed in other comments and answers. Here is a detailed introduction about how to do that with C code.

However, I urge caution with that approach, since you are detecting high frequencies, you will need a high sample rate, which will result in high computation overhead. This problem can be solved with Goertzel's algorithm in place of the FFT, but you still have an issue that with only 5 five pulses you need a good time resolution. This, too, can be solved with frequent overlapping of your windows, but in the end I think you should use a different technique:

  1. counting the number of times the signal crosses zero. With a little pre-processing (a band-pass filter tuned to the range of your expected frequencies) I would expect it to be easier to get robust results with that, simpler, technique.

  2. Another approach, mimicking how this would be done in the analog domain, is simply to design two band-pass filters and monitor the output of those. This might require a bit of post processing, but I think this would produce excellent results.

It's hard to say for sure, but I would probably lean towards technique #2. It depends on a few things I'm not clear on from your question, eg are the tones likely to appear at the same time (if yes, use #2), are you always going to hear one tone or the other, or sometimes silence, etc. If the spec was likely to change and I was going to have to differentiate between tones that were close together in frequency, I would lean towards #1.

If you need help designing filters, this might be a good place to start.

\$\endgroup\$
  • \$\begingroup\$ One needn't calculate an entire FFT, but just evaluate the DFT at the two frequencies of interest. Look at the actual computations involved in doing that in a windowed and overlapped fashion, and it's pretty much the same operations as running a pair of FIR bandpass filters. \$\endgroup\$ – Chris Stratton Aug 7 '13 at 3:05
  • \$\begingroup\$ @ChrisStratton How is that different from Goertzel's algorithm? \$\endgroup\$ – Bjorn Roche Aug 7 '13 at 8:58
0
\$\begingroup\$

Providing the phones audio circuitry has the bandwidth/sample rate to deal with > 15.625kHz, and assuming your frequency detection code is okay, then detecting tones this far apart should be no problem whatsoever. There are plenty of code snippets and the theory behind them around the 'net if you look around a bit. A good place to start your search for code would be touch tone (DTMF) firmware, theory wise look for stuff like correlation and FFT.

Make sure you confirm the bandwidth of your particular phone, you may need to reduce the frequencies involved if this is a possibility for your project.

There is a good introductory example of a simple DTMF detection technique from Olin in this question. Any decent DSP book will have plenty more on the subject.

\$\endgroup\$
  • \$\begingroup\$ Out of curiosity, do you know of any smartphones which do not have sufficient bandwidth? \$\endgroup\$ – Chris Stratton Aug 7 '13 at 3:07
  • \$\begingroup\$ @Chris - no, I'm not really too knowledgeable in the smartphone audio department, it was just a note of caution. Easy to check before you start down a particular path, and I think of enough importance to spend 5 minutes confirming. I would assume 99% of phones made in the last 5 years should have sufficient bandwidth. \$\endgroup\$ – Oli Glaser Aug 7 '13 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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