Академический Документы
Профессиональный Документы
Культура Документы
http://www.romanblack.com/DTMF/DTMF_alg.htm
www.RomanBlack.com
DTMF
DTMF is Dual Tone Multi Frequency, (or "Touchtone") these are the sounds made by telephones to dial a number. Each DTMF sound is made by two frequencies
which are mixed together.
1 of 9
17/12/2014 3:39 AM
2 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
As you can see above, this seems to work quite well in theory, it eliminates the noise and high frequencies and zero-cross fluff very well, and seems to capture the
major periods fairly reliably. It also reduces the need for external hardware as it provides a significant filtering effect by software alone.
This debounce feature works synergistically to be more than just a period measurement, because it is only triggered on a certain characteristics of the DTMF
waveform it perfoms a crude pattern recogniton too, as you can see it triggers only in response to certain major peaks. This will be very useful later.
Another benefit of this system is that unlike Goertzel or DFT this is not limited to any specific frequency, so the same hardware and code can just as easily detect
the dial tone, ring tone, or ringback tones etc, and can detect a single tone if needed or dual tones, all of which may be of benefit in a PIC telephone application.
17/12/2014 3:39 AM
http://www.romanblack.com/DTMF/DTMF_alg.htm
DTMF pair
697 1209
770 1209
852 1209
941 1209
per1
98
63.3
60.7
58.1
%
56
46
65
70
per2
66
94
90.4
86.5
%
30
44
35
26
697
770
852
941
1336
1336
1336
1336
92
88.7
85
55
74
66
52
56
62
60
57.6
82
5 ?
26
40
42
697
770
852
941
1477
1477
1477
1477
86
83
80
76.9
80
88
72
54
114
54
52.1
26
42
697
770
852
941
1633
1633
1633
1633
80.7
78
75
72.2
66
86
90
72
106.3
102.5
32
12
49.3
26
6 ?
The figures above were quite reliable, with a fixed frequency source (my xtal locked DTMF sine generator) the periods remained within about 0.3% from test to test.
Much less than 1 bar period error on the bargraph. The percentages of the 2 main periods also remained reliable, within 4% and generally better.
How to decode it?
If the DTMF generator frequencies were quite exact (say < 0.5% freq error) this would be as easy as using the most common (primary) period. The two closest
periods are 85 and 86 so they are separated by 1.1% difference in period. That would already be a workable DTMF decoder, but relies on having a good DTMF
generator.
The DTMF spec requires that the decoder will accept generated DTMF up to +/- 1.5% freq error. Usually the real life DTMF is made by dedicated DTMF generator
ICs, and although these are xtal locked their frequencies are approximate and according to some popular IC datasheets the frequencies are normally within 0.3% or
so, with an occasional error as large as 0.7%. So for general use it won't be accurate enough just using the one primary period for testing although it does come
close.
The good news is that it has been extremely easy to get this data, consisting only of a simple comparator, software debounce, and recording 50
consecutive periods.
3 of 9
17/12/2014 3:39 AM
4 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
85
86
52%
80%
57.6
114
40%
6%
If both use a wider period match, like accepting +/- 1.5% freq error each period filter will be;
(85) 83.7 to 86.3
(86) 84.7 to 87.3
So there will be a significant overlap and both primary periods (85 and 86) will be detected.
But the other data can be processed, as with DTMF Tone"8" the 85 period occurs only 52% of the time and has a second period of 57.6 that occurs 40% of the
time. Where the DTMF Tone"3" has period 86 very dominant at 80% and its second period is 114 and occurs only 6% of the time.
It can use a weighted points system that allocates points for each detected period;
if(period is 83 to 87); Tone"8" += 1 and Tone"3" += 1
if(period is 56 to 59); Tone"3" += 4
if(period is 112 to 116); Tone"3" += 20
Those figures were just chosen arbitrarily. For 100 tested periods from each Tone, the points result would be;
Actual DTMF Tone"8"
Tone"8" points = 52*1 + 40*4 = 212
Tone"3" points = 52*1 + 0*20 = 52
Actual DTMF Tone"3"
Tone"8" points = 80*1 + 0*4 = 80
Tone"3" points = 80*1 + 6*20 = 200
So in the case of those two DTMF tone examples, even though the primary periods were both indistinguishable (85 and 86) there was enough difference in the
weighted points that were allocated to clearly identify each DTMF tone and meet the required spec for +/- 1.5% frequency deviation in all the tested periods.
Results of testing;
The numbers on the right of the display show the 16 result accumulators.
Above is an example of what most of the tones look like, there is a clear winner, in this case it is Tone 10 (852 1477).
17/12/2014 3:39 AM
5 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
Tone 3 (941 1209) shows a clear winner. Again this is pretty typical.
Tone 6 (852 1336) is one of the worst cases, it's reliable enough but there is not a very large safety margin.
Here are the weighted points values I used for the different periods; DTMF_simple_points.c
This is looking promising. Although it is not fully practical, this simple decoder uses no input hardware, very litle ROM, only TMR0 set to a low 16uS resolution, very
little RAM, no interrupts, and only needs a slow PIC (assuming it does the weighted points in real time after each period capture). And it gives a working decode
from as little as 30 periods (under 45 mS).
It's not a great decoder but it's working and would be possible even on a 4MHz PIC 10F, 12F or 16F, ie the bottom end PICs!
17/12/2014 3:39 AM
6 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
Above in Tone 3 you can see the new data, with some "double" periods drawn in orange and brown. These demonstrate the most basic pattern that is present; the
2 consecutive periods.
If we call the short period S and the long period L, most double periods consist of an SL pair with SS pairs too. The frequency of the patterns in Tone 3 is; SL/LS=4,
SS=3, LL=0.
Above in Tone 6 the period pairs look very different! They are mostly SL pairs with one LL pair, the pair frequency is; SL/LS=6, SS=0, LL=1.
17/12/2014 3:39 AM
7 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
Here are the triplet analysis results for Tone 3 and Tone 6, the triplets are exactly as predicted by the theory waveform. This is data for 1000 triplets.
Here is data from hardware testing 1000 triplets for each DTMF Tone. It shows periods as Short/Long periods, and shows the most common triplets by
percentage;
Tone
0
1
2
3
DTMF pair
697 1209
770 1209
852 1209
941 1209
Short
66
63.3
60.7
58.1
%
29
43
58
71
Long
98
94
90.4
86.5
%
57
49
39
28
SSS
4
5
6
7
697
770
852
941
1336
1336
1336
1336
62
60
57.6
55
10
27
43
58
92
88.7
85
82
77
66
56
42
53
8
9
10
11
697
770
852
941
1477
1477
1477
1477
86
56.8
54
52.1
84
8
26
43
114
83
80
76.9
9
91
73
57
58
LLL
9
14
SSL
LSS
16
28
16
28
16
75
20
16
16
10
10
LLS
19
10
SLL
19
10
7
23
13
7
23
13
8
26
14
8
26
14
SLS
27
39
28
29
42
LSL
20
32
22
BAD
32
19
8
1
4
23
42
26
23
13
3
1
8
26
43
11
1
1
1
10
29
The triplet pattern recognition seems very reliable! Surprisingly, I did not see one false positive triplet even after many tests.
The only DTMF tones that may cause issues are Tones 4, 8 and 9, these have a very low incidence of one period.
17/12/2014 3:39 AM
8 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
The display shows the spectrum chart of the 30 period samples, then text showing the periods and the number of periods, and on the right it shows the 12 DTMF
points scores.
All 12 DTMF signatures have extremely high separation as seen in the two examples above. Even from a short 45mS sample time, with as little as 32 periods (30
triplets) it looks to be a solid reliable DTMF detection. The particular triplets I chose for the tests have both a Short and Long period so this new decoder is
completely immune to being triggered from a single frequency tone.
Here is the crude system I used for decoding triplets into weighted points; DTMF_decode_triplet_points.c
17/12/2014 3:39 AM
9 of 9
http://www.romanblack.com/DTMF/DTMF_alg.htm
It receives DTMF audio into pin GP1 (comparator input) and needs a 0.1uF to 1uF input cap (AC coupling cap). It also needs a 4k7 or 10k resistor from GP1 to
ground. That's about it, it works fine with DTMF amplitude from about 0.4v peak to peak to over 2v peak to peak.
This DTMF decoder uses 25 RAM (and the C stack) and 318 ROM. If you need to decode all 12 DTMF tones it will fit in this PICs 1k ROM but you need to
reduce or remove the make_beeps() function. I have not tried to shrink any of the code, as that should be quite possible.
Operation
All the PIC does is continually test the incoming signal in groups of 60 periods (60 triplets) which takes about 95mS for each group. The triplet decoding and points
allocating is done in real time after each period capture and there is plenty of time even on this little PIC.
Two DTMF tones can be detected;
Tone 0 (the phone "1" key) = set output GP0 HI
Tone 7 (the phone "0" key) = set output GP0 LO
Also, after the GPO output has been changed the PIC makes one or two "beeps" confirmation on GP2, these beeps can be to a LED or a speaker to tell the user
the signal has been received.
The project will decode any or all of the 12 DTMF tones, but the 10 tones not used are commented out to save ROM and processing time.
It worked very well in testing, and should work for you too provided the DTMF waveform is reasonably clean. If you have dirty DTMF waveform you can clean it up a
lot by adding a RC low-pass filter of 1k5 and 0.033uF or 2 filters of 1k2 and 0.033uF. But this should not be needed in most cases as the algorithm itself will tolerate
a decent amount of noise. The extra filter will be most useful for radio apps that may have hiss on the signal.
An obvious use for this would be as a remote receiver connected to a radio or other audio system, to turn something on or off with a DTMF tone. Likewise it could
be used as a phone remote to turn something on-off at home when you ring home from work. However you must check the legality of connecting equipment to the
phone line (it can be illegal in some areas) and of course check for the spec and safety of the way you connect the electronics to the phone line. There is a lot of
info on the internet.
DTMF_remote.c
DTMF_remote.hex
17/12/2014 3:39 AM