Vous êtes sur la page 1sur 24

DSP C5000

Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright 2003 Texas Instruments. All rights reserved.

Learning Objectives

DTMF signaling and tone generation. DTMF signal generation DTMF tone detection techniques and the Goertzel algorithm. Implementation of the Goertzel algorithm for tone detection on DSP

ESIEE, Slide 2

Copyright 2003 Texas Instruments. All rights reserved.

Introduction

Dual Tone Multi-Frequency (DTMF) is a widespread used signalling system: telephone services use commonly key strokes for options selection DTMF is mainly used by touch-tone digital telephone sets which are an alternative to rotary telephone sets. DTMF has now been extended to electronic mail and telephone banking systems It is easily implemented on a DSP as small part of the tasks.
Copyright 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 3

DTMF Signaling

In a DTMF signaling system a unique combination of two normalized frequency tones Two types of signal processing are involved:

Coding or generation. Decoding or detection.

For coding, two sinusoidal sequences of finite duration are added in order to represent a digit.

ESIEE, Slide 4

Copyright 2003 Texas Instruments. All rights reserved.

Dual tone Generation


A key stroke on 9 will generate 2 added tones, one at 852Hz low frequency and one at 1477Hz

The 2 tones are Both audible.

ESIEE, Slide 5

Copyright 2003 Texas Instruments. All rights reserved.

Tones Generation

Dual tone generation can be done with 2 sinewave sources connected in parallel. Different method can be used for such implementation:

Polynomial approximation Look-up table Recursive oscillator

DTMF signal must meet certain duration and spacing requirements


10 Digits are sent per second. Sampling is done via a codec at 8Khz Each tone duration must be >40msec and a spacing of 50ms minimum between two digits is required
Copyright 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 6

2 and 9 digit signal sequence

ESIEE, Slide 7

Copyright 2003 Texas Instruments. All rights reserved.

DTMF generation implementation

Tone generation of a DTMF is generally based on two programmable, second order digital sinusoidal oscillators, one for the low fl the other one for the high fh tone. Two oscillators instead of eight reduce the code size. Coefficient and initial conditions are set for each particular oscillation

+ +
Z-1 Low freq Z-1

+ y(n)

+
Z-1
High freq Z-1

ESIEE, Slide 8

Copyright 2003 Texas Instruments. All rights reserved.

Digital oscillator parameters

2 pole resonator filter with 2 complexe poles on the unit cercle (unstable)
Output signal: Y(n)= -a1y(n-1)-y(n-2)

H ( z)

b0 1 a1 z 1 a2 z 2

b0 A sin(0 ) a1 2 cos(0 ) a2 1

Initial conditions:
Y(-1)=0 Y(-2)=-A sin(0)

02Pf0/fs f0 is the tone freq fs is the sampling freq

ESIEE, Slide 9

Copyright 2003 Texas Instruments. All rights reserved.

C55 sine generator code


Frames of data stream of 120 samples (15msec) long contain either DTMF tone samples or pause samples. The encoder is either in idle mode, not used to encode digits or active and generates DTMF tones and pauses The sine equation is implemented in assembly language:
Mov Mpym sub Add ||delay Mov a1/2, T1 *AR1+,T1,AC0; *AR1-<<#16,AC0,AC AC0,AC1 *AR1 rnd(hi(AC1)),*AR1 ; coded in Q15 ;AR1 y(n-1); AR1+1 y(n-2) ;AC1= a1/2*y(n-1)-y(n-2) ; AC1= a1*y(n-1)-y(n-2) ;y(n-2)=y(n-1) ;y(n-1)=y(n)

; output signal pointer is AR1

ESIEE, Slide 10

Copyright 2003 Texas Instruments. All rights reserved.

Oscillator parameters at fs=8Khz

ESIEE, Slide 11

Copyright 2003 Texas Instruments. All rights reserved.

DTMF Tone Detection


Goertzel algorithm is the more efficient detection algorithm for a single tone. To detect the level at a particular frequency the DFT is the most suitable method:

X( k)

m N -1 m 0

x(m).e

j 2km N

The Goertzel algorithm is a recursive implementation


of the DFT , 16 samples of the DFT are computed for 16 tones See DTMF.pdf file for a complete description
ESIEE, Slide 12 Copyright 2003 Texas Instruments. All rights reserved.

Goertzel Algorithm Implementation

To implement the Goertzel algorithm the following equations are required:

If the length of the signal is N, the recursionfor N - 1time is : w k (n) x(n) 2 cos(2f k / f s ) wk (n 1) wk (n 2) X (k ) wn ( N 1) e j 2f k / f s ) wk ( N 2) Magnitude squared is then : X(k) wn ( N 1) 2 cos(2f k / f s ) wk ( N 1).wk ( N 2) wk ( N 2)
2 2 2

Complex formula

The only coefficient needed to compute output signal level is


Cos(2fk/fs)
ESIEE, Slide 13 Copyright 2003 Texas Instruments. All rights reserved.

Goertzel Algorithm Implementation


Get N input samplex(n) Compute recursive part: Wk(n), n=0 to N-1

For 8 frequencies
Calculate X2(k) for 8 freq

Tests: Magnitude Harmonic Total Energy

Output Digit

ESIEE, Slide 14

Copyright 2003 Texas Instruments. All rights reserved.

Goertzel Algorithm Implementation

The value of k determines the tone we are trying to detect and is given by:

fk k N fs

ESIEE, Slide 15

Where: fk = frequency of the tone. fs = sampling frequency. N is set to 205. Then we can calculate coefficient 2cos(2**k/N).
Copyright 2003 Texas Instruments. All rights reserved.

Goertzel Algorithm Implementation


N = 205 fs = 8kHz Frequency 697 770 852 941 1209 1336 1477 1633 k 18 20 22 24 31 34 38 42

Coefficient (decimal) 1.703275 1.635585 1.562297 1.482867 1.163138 1.008835 0.790074 0.559454

Coefficient (Q15) 0x6D02* 0x68AD* 0x63FC* 0x5EE7* 0x4A70* 0x4090* 0x6521 0x479C

* The decimal values are divided by 2 to be represented in Q15 format (a1/2<1).


ESIEE, Slide 16 Copyright 2003 Texas Instruments. All rights reserved.

Goertzel Algorithm Implementation


wn = x(n) - wn-2 + a1*wn-1;
= sum1 + prod1 0n<N-1

Where: a1= 2cos(2k/N) and N=205 This gives 205 MACs+ 205 ADD The last computation gives the energy of the tone and is done with: 2 SQRS and one multiplication

|Yk(N) |2 = Q2(N) + Q2(N-1) - a1*Q(N)*Q(N-1)


ESIEE, Slide 17 Copyright 2003 Texas Instruments. All rights reserved.

Goertzel Algorithm Implementation


void Goertzel (void) { static short delay; static short delay_1 = 0; static short delay_2 = 0; static int N = 0; static int Goertzel_Value = 0; int I, prod1, prod2, prod3, sum, R_in, output; short input; short coef_1 = 0x4A70; // For detecting 1209 Hz
R_in = mcbsp0_read(); input = (short) R_in; input = input >> 4; prod1 = delay = delay_2 delay_1 N++; // Read the signal in // Scale down input to prevent overflow

C code

(delay_1*coef_1)>>14; input + (short)prod1 - delay_2; = delay_1; = delay;

if (N==206) { prod1 = (delay_1 * delay_1); prod2 = (delay_2 * delay_2); prod3 = (delay_1 * coef_1)>>14; prod3 = prod3 * delay_2; Goertzel_Value = (prod1 + prod2 - prod3) >> 15; Goertzel_Value <<= 4; // Scale up value for sensitivity N = 0; delay_1 = delay_2 = 0; } output = (((short) R_in) * ((short)Goertzel_Value)) >> 15; mcbsp0_write(output& 0xfffffffe); // Send the signal out return; ESIEE, Slide } 18 Copyright 2003 Texas Instruments. All rights reserved.

C54 assembly programme Goertzel tone detection routine


;Assume input signal x(n) is read through an I/O port at address 100h ;Output level Y(k)2 is sent to a port at address 1001h ;Scratch RAM reservation .bss wn,2 ;w(n-1) andw(n-2) .bss xn,1 ; input signal xn .bss Y,1 ; tone Energy .bss alpha,1 ;coefficient storage ; Constant initialisation alphap .word 0x68ADh ; a2/2 coefficient value at fs=8khz ; (prog memory) N .set 205 ;value of N ;DSP modes initialisation SSBX FRCT ;Product shift for Q15 format SSBX SXM ;Sign extension during shift RSXB OVA ; no overflowmode for A and B RSXB OVB
ESIEE, Slide 19 Copyright 2003 Texas Instruments. All rights reserved.

C54 assembly programme


;Data pointers Initialisation LD #wn,AR2 ; AR2 is pointing w(n-1) LD #xn,AR1 LD #Y,AR4 LD #alpha,AR3 MVPD #alphap,*AR3 ;Move alpha value to data RAM RPTZ #1 ;Accumulator A=0 STL A,*AR2+ , w(0) and w(-1) are set to 0 MAR *AR2; AR2 is pointing w(n-2)

ESIEE, Slide 20

Copyright 2003 Texas Instruments. All rights reserved.

Algorithm Core
STM RPTB PORTR LD SUB MAC MAC delay STH
Loop

#N-1,BRC loop-1 100h,*AR1 *AR1,16,A *AR2,16,A *AR2,*AR3,A *AR2,*AR3,A *AR2 A,*AR2+

; repeat block number

; AccH=x(n) ;A=x(n)-w(n-2) ;A=x(n)-w(n-2)+alphaw(n-1) ;A=x(n)-w(n-2)+2alphaw(n-1) ;w(n-2)=w(n-1) tap delay ;w(n-1)=w(n) tap delay ;end of loop

ESIEE, Slide 21

Copyright 2003 Texas Instruments. All rights reserved.

Energy calculation
LD *AR2,16,A MPYA *AR2MPY *AR2,A LD *AR3,T MPYA A SUB A,1,B ;A=w(N-1) ;T=w(N-1) B=w(N-1)^2 ;A=w(N)*w(N-1) ;T=alphap ;A=alphap*w(N)*w(N-1) ; substract with a left shift to ;obtain 2alphap ; B=w(N-1)^2-2alphap*w(N)*w(N-1) ;T=w(N) ;B=w(N-1)^2-2alphap*w(N)*w(N-1)+w(N)^2 ;save to Y ;copy output level

LD *AR2,T MAC *AR2,B STH *AR4 PORTW *AR4,101h

ESIEE, Slide 22

Copyright 2003 Texas Instruments. All rights reserved.

Universal Multifrequency Tone Generator and detector (UMTG) This software module developed by SPIRIT Corp. for the TMS320C54x and TMS320C55X platform It can be used into embedded devices for generating various telephone services used in intelligent network systems Or as a simple tone generator for custom applications It is fully compliant with TMS Algorithm standard rules See SPRU 639 and SPRU 638 AN

ESIEE, Slide 23 Copyright 2003 Texas Instruments. All rights reserved.

Follow on Activities

Application 7 for the TMS320C5416 DSK


Uses a microphone to pick up the sounds generated by a touch phone. The buttons pressed are identified using the Goerztel algorithm and their values displayed on Stdout. The frequency response of each Goertzel filter is given using Matlab.

ESIEE, Slide 24

Copyright 2003 Texas Instruments. All rights reserved.

Vous aimerez peut-être aussi