Detect Audio Frequency (microphone)

Discussion in 'iOS Programming' started by xArtx, Dec 1, 2013.

  1. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #1
    Hi Guys,
    I'm looking to receive, and interpret DTMF. That's two simultaneous tone frequencies,
    I'm not completely versed with software detecting the frequency of just one tone.

    I think I'm somewhat arriving at a solution in my head without having hit the computer yet.
    Having used the audio out, I'm sure that using audio in, you'll end up with a sample buffer at
    known sample format, and am sure if I try, I'll get that far.

    What then? Are there any canned solutions for looking at the wave form
    to count peaks? DTMF produced by dedicated chips will be nice clean sine waves.
    I have a scope, and will be able to see that much.
    Cheers, Art.
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    You can use either the Audio Queue API or the RemoteIO Audio Unit to stream buffers of audio samples into an iOS app (plenty of docs on the Apple dev site). The Goertzel algorithm is probably the most appropriate method to detect the presence of tone frequencies whose waveforms are mostly sinusoidal inside a buffer of samples. You can also check the ratios of the Goertzel filter outputs and the total energy in the buffer to determine if the S/N ratio is sufficient for DTMF detection.
     
  3. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #3
    Thanks that looks like some good starting points.
    I'm sure there will be ready samples out there to get audio samples in a buffer,
    from there it does look like a much more relaxing task to produce audio, than to interpret some of it.
     
  4. Macman45 macrumors demi-god

    Macman45

    Joined:
    Jul 29, 2011
    Location:
    Somewhere Back In The Long Ago
    #4
  5. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #5
    Thanks, but it looks a bit much considering detecting DTMF is the end of the road for the App.
    I don't have to personally know anything about the audio, only the iOS App does.
    Did I mention I have a scope ? :D

     
  6. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #6
    Looks like you've put me well on the right track firewood & thanks.

    I will have to find a software implementation, when it comes time, and it will.
    I get to cheat out this time, and only need to look for pressure points (pulses).

    There's no way I'm following the Wikipedia formula through to a software implementation! :D
     
  7. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #7
    There is a ton of C source code for the Goertzel algorithm on the net if you search for it. It can be done in less than a dozen lines of code.
     
  8. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #8
    DTMF decoding is a very common problem and there are a few free libraries for doing that. Every telephony system has to do this. I would not try and re-invent this wheel. Google "dtmf decode library" and you get a few pages of hits. This one is not bad:
    http://sourceforge.net/projects/dtmf/

    The solution to apply a filter then compare the ratio of filtered to unfiltered power is good. I'm pretty sure this is how they do it with analog circuits too. But why bother with such details when there are very well tested and fee solutions
     
  9. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #9
    It's a problem I get to totally evade this time :)
    I did decide to go the hardware route, figuring that would be as refined as it gets,
    but the IC stays in the packet because then I realised that overall,
    I was aiming to to both produce DTMF, and then decode it for nothing
    which is quite silly.

    [​IMG]
     
  10. xArtx, Dec 13, 2014
    Last edited: Dec 20, 2014

    xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #10
    Silly in the intended application maybe, but another one came up for a keypad interface in the reverse direction.

    I have an App on my iPhone 5 called Blue Box (not my App).
    [​IMG]

    This one, despite the name leading me to believe it was a modern day "fone phreak wannabe",
    appears to be a real multi frequency signal generator.
    You'd have to use some long samples or awesome loops to cheat out on it.

    Here is a hardware circuit receiving DTMF through a hi-fi stereo:
    *** snip *** updated video below VVVV

    Just a warning to watch clipping on your phone if you do anything with audio :D
    My iPhone 5 has to be turned down about halfway before it either clips,
    or the speaker can no longer reproduce DTMF for whatever reason.

    When I use a scope on the mic preamp output with iPhone 5 generating the DTMF,
    it appears as though I'm amplifying existing clipping because there is some noise
    introduced on the DC component.

    I'm supposed to write the keypad app for the electronics.
    I know how to use the low level audio, but it might pay to record long samples at a level that can't peak.
    Cheers, Art.
     
  11. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #11
    So I updated the YouTube link in the post above with a speed test once I
    figured out how to synthesise DTMF tones with iOS AudioUnits.
    I might make a DTMF App since most Apps just play recorded samples.

    https://www.youtube.com/watch?v=fhqFfszJLU0

    Definitely a form of communication there where the iOS device takes charge of comms and sends then waits for recieve, then checks checksums.
    Given the iOS devices lack a useable serial port, I think this beats flashing the camera LED into a light sensor.

    Note that the video demo is an audio coupling (speaker/microphone) with some background noise.
    A direct connection should be able to do this silently and more reliably.
     

Share This Page