Let's Get Toned
Rotary dialing is great and all, but it has its limits. In the late 1960's, the telephone companies created DTMF to replace it. DTMF, also known as Touch-Tone dialing, replaces the rotating dial with this familiar beeping keypad:
DTMF stands for Dual Tone Multi Frequency, which means that each number you press sends two tones at the same time, one high tone and one low tone. These audible tones get sent along the wire mixed right in with voice signals. Here's a chart showing the exact tone combinations:
So when you press a button on a touchtone phone, you and your phone essentially become a two-note synth band playing for an audience of one: whatever machine is listening on the other end of the line, decoding the tones.
Secret Decoder Ring
I considered using a dedicated DTMF decoding chip for The Phone Friend. They are inexpensive and pretty easy to implement, but I ran into a problem. Every one I could find runs on 5v, and the rest of The Phone Friend uses 3.3v*.
The Pi Pico that controls The Phone Friend has a powerful processor, and so far in this project, we haven't used it for much more than counting up to 10. I started to wonder if the Pico could do the DTMF decoding by itself. Spoiler: it can.
But First Meet My Friend Goertzel!
A Very Special Algorithm
I started to research how dual tone signals are decoded. Here's what wikipedia has to say about decoding DTMF signals:
DTMF decoding algorithms typically use the Goertzel algorithm.
So I figured that would be a good place to start.
The Goertzel algorithm turns out to be an equation that (warning: I barely understand this part) we can use to identify the most dominant tones in an audio signal. It's similar to its better known friend the fast Fourier transform, but is faster than FFT when you're just searching for a few sets of tones. Seems perfect for detecting DTMF. Unfortunately, its the sort of thing that looks like this when you google it:
...and I just... I can't.
And thats ok!
If you really want to know how it works, you can. But I don't. And didn't.
Part 2: Getting Someone Else To Do It
I fed the Goertzel algorithm to a much, much larger algorithm (GPT-4), and got back a working python function. I adapted that code for CircuitPython, then did some tweaking to make it run fast and reliably. It is not fast enough to keep up with all autodialing machines, some of which dial very fast, but it is more than fast enough to achieve 100% accuracy** with human dialed digits and no false positives.
In the video demo below, notice how The Phone Friend accurately handles repeated short presses of the same digit, as well as extra long presses:
Code is pasted here, with pretty comments that explain how everything works.
I know how the Goertzel code works, but I do not know much about the math behind how it works, so that section is... light on comments.
*technically the Raspberry Pi Pico and AG1171 are both able to tolerate 5v, but the Pico datasheet says 3.3v.
**100% accuracy is not a guarantee, but it is a genuine observation about the results I'm seeing here. Don't rely on The Phone Friend to decode anything critical.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
"I fed the Goertzel algorithm to a much, much larger algorithm (GPT-4), and got back a working python function."
This is so cool, great way to leverage technology! I like the Phone Friend and plan to build one to deter spam calls on my landline.
Are you sure? yes | no
Thanks Neal! Be sure to look at the safety page, I've recently updated it. The Phone Friend shouldn't be attached to an actual phone network: https://hackaday.io/project/190181-the-phone-friend/log/217370-first-a-warning
Are you sure? yes | no