PAUL B wrote:
>
> >
> >Note that the decoder is not entirely satisfactory with respect to
> >the 'standards', but works if the tones last for over 150ms.
> >
> >Regards,
> >SJH
>
> So what is needed to sort this problem out for dtmf under 150 ms ?
>
Paul,
With Steve's approach you need a little more power than a PIC can deliver.
Those of you familiar with Analog Device's DSP's may recall this approach
implemented in an ADSP-2100 (see chapter 14 of the Digital Signal Processing
Applications). There they have 16 Goertzel algorithms running in parallel.
8 of them are tuned to the 8 DTMF tones while the other 8 are tuned to the
second harmonic of the DTMF tones. The idea is that if a DTMF signal is
present, then only two of the Goertzel outputs in the lower group of 8
(actually one in the first four and the other in the second four) will have
any significant output. The reason for looking at the second harmonic is to
differentiate DTMF signals (low in 2nd harmonic) from ordinary voice (higher
in 2nd harmonic).
[A Goertzel algorithm provides an efficient means of computing the Discrete
Fourier Transform of a signal.]
I have an idea that may make DTMF decoding possible with a PIC. In a message
to Steve I wrote:
> Steve,
>
> I've been thinking about this DTMF stuff a little. I must confess that I have
> little interest beyond the theoretical aspects. In other words, I've never
> built any hardware or written any software to encode or decode DTMF signals,
> but I like to mess around with signal processing and efficient algorithms.
>
> O.K. Having said that, I would like you to consider this idea. Suppose you
looked
> at the zero crossing of the DTMF signals and attempted to perform the decoding
> based on the apriori knowledge of the 8 DTMF frequencies. The "zero-crossing"
> detector is a one-bit A to D converter, i.e. a comparator. (The 16C622 has two
> comparators.) The idea is to sample the comparator output and measure how long
> it takes for the signal to change states. The optimal sampling time and
criteria
{Quote hidden}> to determine if a DTMF signal is present can be obtained by studying a little
> theory.
>
> For example, assuming no noise and equal amplitude for each DTMF tone, we can
> express the signal as:
>
> d(t) = Al * sin(2pi * fl * t + pl) + Ah * sin(2pi * fh * t + ph)
>
> where,
> Al=Ah=A = The amplitudes of each DTMF tone, which are assumed for the moment
> to be equal.
> fl,fh => Are the low and high frequencies of the DTMF tones (known).
> pl,ph => The phase for the low and high tones, which for the sake of
> arguement can be taken to be zero.
> 2pi => 2*3.141592653
>
> Using a trig identity, we can express this sum of sinusoids as a product:
>
> fl + fh fl - fh
> d(t) = 2 * A * sin(2pi * ------- * t) * cos(2pi * ------- * t)
> 2 2
> This makes it very easy to ascertain the zero crossing points. In other words,
d(t)
> goes to zero when ever either the sine term or the cosine term goes to zero:
>
> d(t) = 0
> when
> t = n / (fl + fh) n = 0, +/- 1, +/- 2, etc.
> OR
> t = (m + .5) / (fl - fh) m = 0, +/- 1, +/- 2, etc.
>
> (actually, the .5 is an artifact of the cosine. Since phase is not important,
the .5
> can be ignored. In other words, the .5/(fl-fh) causes a time shift in the zero
crossings.)
>
> The minimum zero crossing frequency is ~ 1209+697 = 1906, while the maximum
is[Steve, your message has an error right here ^^^^^^^^^^^^]
> 941+1633 = 2574. So the sampling time needs to be fast enough to catch 2574 Hz
signal
> and perhaps slow enough to not overflow say an 8-bit variable counting the
1906 Hz
> pulse width. So roughly speaking, you wouldn't want to sample any faster than
1/1906/256
> or about 2 us.(Nor could you) My guess is that 10us is comfortable.
>
> Now for detection... If you look at the time spacing of the zero crossings of
the DTMF
> signals, you'll see something like so:
>
> W W W N N W W W N N W W W N N W W W N N W W W N
>
> where do to my impatience, I've abbreviate wide pulses with W and a narrow
ones with N.
> The number of wide pulses between narrow pulses is roughly (exactly, averaged
over time)
> the ratio of the sum and difference of the DTMF tones:
> fh + fl
> r ~ ---------
> fh - fl
>
> The width of the wide pulses is the spacing between zero crossings due to the
sum of the
> DTMF tones, while the spacing in time of the narrow pulses is due to their
difference.
>
> W ~ 1/(fh + fl)
> space between N's ~ 1/(fh - fl)
>
> The reason there are narrow pulses is due to the two frequencies beating
together. Another
> way to look at it is there are certain integers m and n that can cause the
zero crossing
> gap to be decreased.
>
> As an example, suppose we were looking at key 1 (697,1209). The zero crossing
points
> occur at
> n/(1209 + 697) = 0, 525us, 1049us, 1574us, 2099us, 2623us, 3148us, 3673us,
4197us, 4722us,
> 5247us, 5771us, 6296us, ...
> and
> m/(1209 - 697) = 0, 1953us, 3906us, 5859us, 7812us, 9765us, ...
>
> The pulse widths you would measure would be:
>
> 525, 524, 525, 379, 146, 524, 525, 525, 233, 291, ....
> W W W N N W W W N N
>
> So the wide pulses are ~525us, and there are three of them between the narrow
pulses.
>
> The time between the occurrence of the narrow pulses is about
379+146+524+525+525 or
> 2099us, which is approximately 1953us (=1/[1209-697]). Now this is not
accurate enough
> by itself to be used as an identifier of the frequencies, but it could be used
as a
> discriminator. Perhaps if you average several of these cycles the
approximation improves,
> but I haven't investigated this.
>
> If you repeat this example for the other 15 keys, you start to see a pattern
develop. I've
> written a simple program in MATLAB to demonstrate this. (It's at home and not
at work so I
> can't append a copy of it). It will cycle through the 16 keys and show the
DTMF signal and
> the "digitized" waveform superimposed.
>
> Now for the tough part... So far I've assumed that the two tones have the same
amplitude
> and that there is no noise. From a quick search on the WEB, I learned that
there could be
> up to three dB difference between the two. I emperically found with the MATLAB
program that
> 6 db difference makes it extremely difficult to tell the difference between
two DTMF signals,
> but 3 db can be done.
>
> I assume that the noise floor is several db below the tones. In which case,
the comparator
> hysterisis will "filter" it out. If it is not, then you have a problem. Also,
harmonic
> distortion could also be detrimental. However, I doubt (i.e. guess) that there
are no even
> harmonics and that the odd harmonics are at most 1/n^2 (n = harmonic number)
the amplitude
> of the fundamental. (This is similar to the Fourier series of a triangle
wave.)
>
> At any rate, I do not yet have an algorithm to efficiently pluck the DTMF
signals out of
> the acquired data.
>
And in a subsequent message I also wrote:
> I forgot to tell you one thing about sampling these pulses. It's possible to
miss a short
> pulse with the sampling scheme I described in the last message. This is
because under
> certain conditions the short pulse is shorter than the sampling period. In
this case,
> you would see one really wide pulse inplace of two wide pulses seperated by a
narrow one.
> I think it's possible to recognize when this happens, so it probably is no big
deal.
>
The only reason I'm throwing this stuff out here is maybe someone else has
already attempted
this approach and have either a) made it work or b) realize it's not possible.
Any ideas or
feedback?
Scott