Pages: [1] 2   Go Down
Author Topic: DTMF decoder library  (Read 16156 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have modified the Goertzel algorithm implementation here:
https://github.com/jacobrosenthal/Goertzel
so that it can be used to detect DTMF tones. The new version, like the original, is not interrupt driven.
It is provided AS IS for you to play with.
There are two sample audio files in the zip which, when the windows audio is turned up full, the sample code detects with no errors.
There is also a circuit diagram of how I connected the audio from the computer's headphone output to the Arduino's analog Pin 0. Use at your own risk.
Unzip the attached file into your libraries directory.

Pete

* DTMF.zip (43.35 KB - downloaded 405 times.)
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I took a look and it works beautifully. Their are 2 things I have questions about though. The tone length is very strict. If the tone is too short it wont work and if it plays too long it will put print the number multiple times. Is their any chance you could make it modifiable? Also, the goertzel algorithm  is supposed to compensate for magnitude on its own. Is there anyway to account for that?

Again, great job and thanks for your help!

Moose
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I took a look and it works beautifully. Their are 2 things I have questions about though. The tone length is very strict. If the tone is too short it wont work and if it plays too long it will put print the number multiple times. Is their any chance you could make it modifiable? Also, the goertzel algorithm  is supposed to compensate for magnitude on its own. Is there anyway to account for that?

Again, great job and thanks for your help!

Moose

I believe the official (original ATT specs?) DTMF specs for minimum recognition time (shortest tone period) for a valid digit is around 40 msec if I recall correctly. Decoding multiple repeated digits for a single tone of any length sounds like just a 'feature' of the library.  smiley-wink
« Last Edit: September 05, 2012, 08:55:58 pm by retrolefty » Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The tone length is very strict. If the tone is too short it wont work
How short a tone are you trying? The dialabc example uses 50ms tones. The example code uses a sample length of 128 which means that a sample block is 14 milliseconds long. It should have 3 good blocks in one 50ms tone and might detect tones down to around 30ms - I haven't tried that. You could try making the sample length shorter (try 64) so that the algorithm samples the tone more times. If you do that, you'll have to reduce the threshold amplitude as well.

Quote
and if it plays too long it will put print the number multiple times.
When the code detects a tone it won't return it again until it sees something that is not a tone. If for any reason the amplitude drops a bit to just below the threshold it can think it has seen the end of the tone when there's actually still more to come. Try lowering the threshold amplitude just a bit.

Quote
Is their any chance you could make it modifiable?
Make what modifiable?

Quote
Also, the goertzel algorithm  is supposed to compensate for magnitude on its own.
I saw one implementation which divided the resulting magnitude by the number of samples. I don't know if that's actually part of the Goertzel algorithm itself.
I'll play with it in the next day or so.

Quote
Again, great job and thanks for your help!
You're welcome ;-)

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also, the goertzel algorithm  is supposed to compensate for magnitude on its own.
This can be done without changing the library.
The dtmf_test sketch originally had this code:
Code:
  dtmf.detect(d_mags,512);

  thischar = dtmf.button(d_mags,1800);

Change it to this:
Code:
  dtmf.detect(d_mags,512);
 
  for(int i = 0;i < 8;i++) {
    d_mags[i] /= n;
  }
 
  thischar = dtmf.button(d_mags,20.);
The "for" loop normalizes the magnitudes. I determined the threshold value of 20 empirically but it works for values of n from 55 up to 160 when using either of the sample audio files.
I prefer to leave this outside the library but if you want to build it in, in the method DTMF::detect change this statement:
Code:
    dtmf_mag[i] = sqrt(Q1[i]*Q1[i] + Q2[i]*Q2[i] - coeff[i]*Q1[i]*Q2[i]);
to this:
Code:
    dtmf_mag[i] = sqrt(Q1[i]*Q1[i] + Q2[i]*Q2[i] - coeff[i]*Q1[i]*Q2[i])/N;

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is there a way to make the link alive again?
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've put it on my website here
http://members.shaw.ca/el.supremo/DTMF.zip

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Pete

thanks for the new link, but i fail to understand how the code work .
i dont have any expriance in arduino but i want to give it a shot....

as described i built the neccesery cirucit and connected it to my audio output of my pc.
when i upload the code to my (MEGA2560) i dont see any feedback from the circuit exept from when i opening the serial monitor and the led on pin 13 go ON.  i tried to open the serial monitor
put it on 115200 baud and wait and see the detction working but its seems to do nothing.

how can i adavnce and make it work (sorry for my bad english)
my audio output in full volume and my divider is on 512 please help.
« Last Edit: January 15, 2013, 06:10:25 am by corolla9 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi i have an update its working.
is there a way that can i decode 6 inputs in parallel?
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code could be modified to handle six inputs but it would slow down the sampling rate quite substantially which would change the characteristics of the detection.
A better way to handle the audio sampling is to use a timer interrupt and do the detection on-the-fly but in either case you would probably need a faster processor to handle six channels.

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an issue with the detection of the DTMF tones. When I try with audio archives through my computer, I have no problem, but when I connect my phone, nothing is detected. I don´t know why.

What I have in mind is to connect one phone to my arduino board, with voicemail active, then if there is an incoming call, the voice mail pick up the call and because of this is allowed to dial the tones. For example 001 wich turns on the heating.

But without detection through my mobile I am blocked, what can I do?

Thanks for your help in advanced
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an issue with the detection of the DTMF tones. When I try with audio archives through my computer, I have no problem, but when I connect my phone, nothing is detected. I don´t know why.

What I have in mind is to connect one phone to my arduino board, with voicemail active, then if there is an incoming call, the voice mail pick up the call and because of this is allowed to dial the tones. For example 001 wich turns on the heating.

But without detection through my mobile I am blocked, what can I do?

Thanks for your help in advanced

You would probably have to show us how you are attempting to connect to your telephone line. Actually most countries/telephone companies have laws and rules about how equipment can be wired to the local subscribers loop, as it's a balance line and you are not free to ground either the tip or ring wire. Normally equipment manufactures use approved chips/modules/components to do such electrical interfacing to the line called DAA modules. These usually involve a 600 ohm 1:1 transformer as well as ring detection/protection components. Keep in mind that the ring voltage when your phone rings is a 90 VAC 20Hz signal that can easily blow up components wired directly to the phone pair.

 So I would suggest you do a little goggling for telephone interfacing circuits to see what you should be using.

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have used El_supremo offered drawing and I connected a mobile phone with the audio jack so I don´t have the issue of a landline connetion (this is another point that I want to check out)

Thaks for your help


* audio_1.gif (10.16 KB, 640x480 - viewed 701 times.)
Logged

Livermore, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Tickling critical mass.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi i have an update its working.
is there a way that can i decode 6 inputs in parallel?
The code could be modified to handle six inputs but it would slow down the sampling rate quite substantially which would change the characteristics of the detection.
A better way to handle the audio sampling is to use a timer interrupt and do the detection on-the-fly but in either case you would probably need a faster processor to handle six channels.

Pete
Parallax Propeller could decode to 7 parallel channels with little external circuitry & leaving one of the COG's for serial back to an arduino.. A propeller chip (P8X32A) has 32 I/O, fully digital, analog input can be accomplished via sigma-delta conversion. There are actually 8 separate MCU's called cog's inside of one chip, this is how the propeller can do real-time parallel processing
Logged

Electronics Engineering student - "E=MC^(OMG x WTF?!)"
Professional Auto Collision/Custom tech

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 44
Posts: 2811
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is an IC part# MT8870. It is a DTMF decoder that will provide a Data Valid signal and 4 bit binary output. all it requires is about 100 MV of clean audio, 5 V and a 3.58 MHz color burst crystal.
Here is a link from "Futurlec"that " appears to do a great deal.. and cheaper too @$12.98..

http://www.futurlec.com/Mini_MT8870.shtml.

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Pages: [1] 2   Go Up
Jump to: