24
Copyrigh t © 2003 DSP C5000 DSP C5000 Chapter 17 Chapter 17 DTMF generation and DTMF generation and detection detection Dual Tone Multiple Dual Tone Multiple Frequency Frequency

Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Embed Size (px)

Citation preview

Page 1: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

DSP C5000DSP C5000

Chapter 17Chapter 17

DTMF generation and detectionDTMF generation and detection

Dual Tone Multiple FrequencyDual Tone Multiple Frequency

Page 2: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 2

Learning ObjectivesLearning Objectives

DTMF signaling and tone generation.DTMF signaling and tone generation. DTMF signal generationDTMF signal generation DTMF tone detection techniques and DTMF tone detection techniques and

the Goertzel algorithm.the Goertzel algorithm. Implementation of the Goertzel Implementation of the Goertzel

algorithm for tone detection on DSPalgorithm for tone detection on DSP

Page 3: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 3

IntroductionIntroduction Dual Tone Multi-Frequency (DTMF) is a widespread used signalling system: telephone Dual Tone Multi-Frequency (DTMF) is a widespread used signalling system: telephone

services use commonly key strokes for options selectionservices use commonly key strokes for options selection DTMF is mainly used by touch-tone digital telephone sets which are an alternative to rotary DTMF is mainly used by touch-tone digital telephone sets which are an alternative to rotary

telephone sets.telephone sets. DTMF has now been extended to electronic mail and telephone banking systemsDTMF has now been extended to electronic mail and telephone banking systems It is easily implemented on a DSP as small part of the tasks.It is easily implemented on a DSP as small part of the tasks.

Page 4: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 4

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

Coding or generation.Coding or generation. Decoding or detection.Decoding or detection.

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

DTMF SignalingDTMF Signaling

Page 5: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 5

Dual tone GenerationDual tone Generation

A key stroke onA key stroke on

« 9 » will generate« 9 » will generate

2 added 2 added tones, tones, one atone at

852Hz low frequency852Hz low frequency

and one at 1477Hzand one at 1477Hz

The 2 tones areThe 2 tones are

Both audible.Both audible.

Page 6: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 6

Tones GenerationTones Generation Dual tone generation can be done with 2 Dual tone generation can be done with 2

sinewave sources connected in parallel.sinewave sources connected in parallel. Different method can be used for such Different method can be used for such

implementation:implementation: Polynomial approximationPolynomial approximation Look-up tableLook-up table Recursive oscillatorRecursive oscillator

DTMF signal must meet certain duration and DTMF signal must meet certain duration and spacing requirementsspacing requirements 10 Digits are sent per second.10 Digits are sent per second. Sampling is done via a codec at 8KhzSampling is done via a codec at 8Khz Each tone duration must be >40msec and a Each tone duration must be >40msec and a

spacing of 50ms minimum between two digits is spacing of 50ms minimum between two digits is requiredrequired

Page 7: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 7

2 and 9 digit signal sequence 2 and 9 digit signal sequence

Page 8: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 8

DTMF generation implementationDTMF generation implementation Tone generation of a Tone generation of a

DTMF is generally DTMF is generally based on two based on two programmable, second programmable, second order digital sinusoidal order digital sinusoidal oscillators, one for the oscillators, one for the low flow fl l the other one for the other one for the high fthe high fhh tone. tone.

Two oscillators instead Two oscillators instead of eight reduce the of eight reduce the code size. code size.

Coefficient and initial Coefficient and initial conditions are set for conditions are set for each particular each particular oscillation oscillation

ZZ-1-1

ZZ-1-1

ZZ-1-1

ZZ-1

++

++

++

++

++ y(n)y(n)Low Low freqfreq

HighHigh

freqfreq

Page 9: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 9

Digital oscillator parametersDigital oscillator parameters 2 pole resonator 2 pole resonator

filter with 2 filter with 2 complexe poles on complexe poles on the unit cercle the unit cercle (unstable)(unstable)

22

11

0

1)(

zaza

bzH

1

)cos(2

)sin(

2

01

00

a

a

Ab

Output signal:Output signal:

Y(n)= -aY(n)= -a11y(n-1)-y(n-2)y(n-1)-y(n-2)

Initial conditions:Initial conditions:

Y(-1)=0Y(-1)=0

Y(-2)=-A sin(Y(-2)=-A sin())ff00/fs/fs

ff00 is the tone freq is the tone freq

fs is the sampling freqfs is the sampling freq

Page 10: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 10

C55 sine generator codeC55 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:

MovMov aa11/2, T1/2, T1 ; coded in Q15; coded in Q15

MpymMpym *AR1+,T1,AC0;*AR1+,T1,AC0; ;AR1 y(n-1); AR1+1 y(n-2);AR1 y(n-1); AR1+1 y(n-2)

subsub *AR1-<<#16,AC0,AC*AR1-<<#16,AC0,AC ;AC1= a1/2*y(n-1)-y(n-2);AC1= a1/2*y(n-1)-y(n-2)

AddAdd AC0,AC1AC0,AC1 ; AC1= a1*y(n-1)-y(n-2); AC1= a1*y(n-1)-y(n-2)

||delay||delay *AR1*AR1 ;y(n-2)=y(n-1);y(n-2)=y(n-1)

MovMov rnd(hi(AC1)),*AR1rnd(hi(AC1)),*AR1 ;y(n-1)=y(n);y(n-1)=y(n)

; output signal pointer is AR1; output signal pointer is AR1

Page 11: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 11

Oscillator parameters at fs=8KhzOscillator parameters at fs=8Khz

Page 12: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 12

DTMF Tone DetectionDTMF Tone Detection Goertzel algorithm is the more efficient detection algorithm for Goertzel algorithm is the more efficient detection algorithm for

a single tone.a single tone. To detect the level at a particular frequency the DFT is the To detect the level at a particular frequency the DFT is the

most suitable method:most suitable method:

x(m).e k) X(1-Nm

0m

N

kmj2-

•The Goertzel algorithm is a recursive implementation The Goertzel algorithm is a recursive implementation

of the DFT , of the DFT ,

•16 samples of the DFT are computed for 16 tones16 samples of the DFT are computed for 16 tones

See See DTMF.pdf file for a complete descriptionfile for a complete description

Page 13: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 13

Goertzel Algorithm ImplementationGoertzel Algorithm Implementation To implement the Goertzel algorithm the To implement the Goertzel algorithm the

following equations are required: following equations are required:

)2()2().1()/2cos(2)1(X(k)

: thenis squared Magnitude

formulaComplex )2()1()(

)2()1()/2cos(2)()(w

:is 1time-Nfor recursion theN, is signal theoflength theIf

222

)/2

k

NwNwNwffNw

NweNwkX

nwnwffnxn

kkkskn

kffj

n

kksk

sk

The only coefficient needed to compute output signal level isThe only coefficient needed to compute output signal level is

Cos(2Cos(2ffkk/f/fss))

Page 14: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 14

Goertzel Algorithm ImplementationGoertzel Algorithm ImplementationGet N input samplex(n)Get N input samplex(n)

Compute recursive part:Compute recursive part:

WWkk(n), n=0 to N-1(n), n=0 to N-1

For 8 frequenciesFor 8 frequencies

Calculate XCalculate X22(k) for 8 freq(k) for 8 freq

Tests:Tests:

MagnitudeMagnitude

HarmonicHarmonic

Total EnergyTotal Energy

Output DigitOutput Digit

Page 15: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 15

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

Goertzel Algorithm ImplementationGoertzel Algorithm Implementation

s

k

f

fNk

Where:Where: ffkk == frequency of the tone.frequency of the tone.

ffss == sampling frequency.sampling frequency.

N is set to 205.N is set to 205.

Then we can calculate coefficient Then we can calculate coefficient 2cos(2*2cos(2**k/N).*k/N).

Page 16: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 16

Goertzel Algorithm ImplementationGoertzel Algorithm Implementation

FrequencyFrequency kk CoefficientCoefficient(decimal)(decimal)

CoefficientCoefficient(Q15)(Q15)

16331633 4242 0.5594540.559454 0x479C0x479C14771477 3838 0.7900740.790074 0x65210x652113361336 3434 1.0088351.008835 0x4090*0x4090*12091209 3131 1.1631381.163138 0x4A70*0x4A70*941941 2424 1.4828671.482867 0x5EE7*0x5EE7*852852 2222 1.5622971.562297 0x63FC*0x63FC*770770 2020 1.6355851.635585 0x68AD*0x68AD*697697 1818 1.7032751.703275 0x6D02*0x6D02*

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

N = 205N = 205

fs = 8kHzfs = 8kHz

Page 17: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 17

wwnn = x(n) - w= x(n) - wn-2 n-2 + a+ a11*w*wn-1n-1; ; 00n<N-1n<N-1

= sum1= sum1 ++ prod1 prod1

Goertzel Algorithm ImplementationGoertzel Algorithm Implementation

Where: Where: aa11= 2cos(2= 2cos(2k/N) and N=205k/N) and N=205

This gives This gives 205 MACs+ 205 ADD205 MACs+ 205 ADD

|Yk(N) ||Yk(N) |22 = Q = Q22(N) + Q(N) + Q22(N-1) -(N-1) - aa11*Q(N)*Q(N-1)*Q(N)*Q(N-1)

The last computation gives the energy of the tone The last computation gives the energy of the tone and is done with:and is done with:

2 SQRS and one multiplication2 SQRS and one multiplication

Page 18: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 18

Goertzel Algorithm ImplementationGoertzel Algorithm Implementationvoid 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(); // Read the signal in

input = (short) R_in;input = input >> 4; // Scale down input to prevent overflow

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

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 sensitivityN = 0;delay_1 = delay_2 = 0;

}

output = (((short) R_in) * ((short)Goertzel_Value)) >> 15;

mcbsp0_write(output& 0xfffffffe); // Send the signal out return; }

‘‘C’ codeC’ code

Page 19: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 19

C54 assembly programmeC54 assembly programmeGoertzel tone detection routineGoertzel tone detection routine

;;Assume input signal x(n) is read through an I/O port at address 100h 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;Output level Y(k)2 is sent to a port at address 1001h;Scratch RAM reservation;Scratch RAM reservation

.bss.bss wn,2wn,2 ;w(n-1) andw(n-2);w(n-1) andw(n-2)

.bss.bss xn,1xn,1 ; input signal xn; input signal xn

.bss.bss Y,1Y,1 ; tone Energy; tone Energy

.bss.bss alpha,1alpha,1 ;coefficient storage;coefficient storage; Constant initialisation; Constant initialisationalphapalphap .word.word 0x68ADh0x68ADh ; a2/2 coefficient value at ; a2/2 coefficient value at

fs=8khz fs=8khz ; (prog ; (prog memory)memory)

NN .set.set 205205 ;value of N;value of N

;DSP modes initialisation;DSP modes initialisationSSBXSSBX FRCTFRCT ;Product shift for Q15 format;Product shift for Q15 formatSSBXSSBX SXMSXM ;Sign extension during shift;Sign extension during shiftRSXBRSXB OVAOVA ; no overflowmode for A and B; no overflowmode for A and BRSXBRSXB OVBOVB

Page 20: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 20

C54 assembly programmeC54 assembly programme

;;Data pointers InitialisationData pointers Initialisation

LDLD #wn,AR2#wn,AR2 ; AR2 is pointing w(n-1); AR2 is pointing w(n-1)

LDLD #xn,AR1#xn,AR1

LDLD #Y,AR4#Y,AR4

LDLD #alpha,AR3#alpha,AR3

MVPDMVPD #alphap,*AR3#alphap,*AR3 ;Move alpha value to data RAM;Move alpha value to data RAM

RPTZRPTZ #1#1 ;Accumulator A=0;Accumulator A=0

STLSTL A,*AR2+A,*AR2+ , w(0) and w(-1) are set to 0, w(0) and w(-1) are set to 0

MARMAR *AR2-*AR2- ; AR2 is pointing w(n-2); AR2 is pointing w(n-2)

Page 21: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 21

Algorithm CoreAlgorithm Core

STMSTM #N-1,BRC#N-1,BRC ; repeat block number; repeat block number

RPTBRPTB loop-1loop-1

PORTRPORTR 100h,*AR1100h,*AR1

LDLD *AR1,16,A*AR1,16,A ; AccH=x(n); AccH=x(n)

SUBSUB *AR2,16,A*AR2,16,A ;A=x(n)-w(n-2);A=x(n)-w(n-2)

MACMAC *AR2,*AR3,A*AR2,*AR3,A ;A=x(n)-w(n-2)+alphaw(n-1);A=x(n)-w(n-2)+alphaw(n-1)

MACMAC *AR2,*AR3,A*AR2,*AR3,A ;A=x(n)-w(n-2)+2alphaw(n-1);A=x(n)-w(n-2)+2alphaw(n-1)

delaydelay *AR2*AR2 ;w(n-2)=w(n-1) tap delay;w(n-2)=w(n-1) tap delay

STHSTH A,*AR2+A,*AR2+ ;w(n-1)=w(n) tap delay;w(n-1)=w(n) tap delay

LoopLoop ;end of loop;end of loop

Page 22: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 22

Energy calculationEnergy calculation

LDLD *AR2,16,A*AR2,16,A ;A=w(N-1);A=w(N-1)

MPYAMPYA *AR2-*AR2- ;T=w(N-1) B=w(N-1)^2;T=w(N-1) B=w(N-1)^2

MPYMPY *AR2,A*AR2,A ;A=w(N)*w(N-1);A=w(N)*w(N-1)

LDLD *AR3,T*AR3,T ;T=alphap;T=alphap

MPYAMPYA AA ;A=alphap*w(N)*w(N-1);A=alphap*w(N)*w(N-1)

SUBSUB A,1,BA,1,B ; substract with a left shift to ; substract with a left shift to ;obtain 2alphap;obtain 2alphap

; B=w(N-1)^2-2alphap*w(N)*w(N-1); B=w(N-1)^2-2alphap*w(N)*w(N-1)

LDLD *AR2,T*AR2,T ;T=w(N);T=w(N)

MACMAC *AR2,B*AR2,B ;B=w(N-1)^2-2alphap*w(N)*w(N-;B=w(N-1)^2-2alphap*w(N)*w(N-1)+w(N)^21)+w(N)^2

STHSTH *AR4*AR4 ;save to Y;save to Y

PORTW *AR4,101hPORTW *AR4,101h ;copy output level;copy output level

Page 23: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 23

Universal MultifrequencyTone 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 ANSee SPRU 639 and SPRU 638 AN

Page 24: Copyright © 2003 Texas Instruments. All rights reserved. DSP C5000 Chapter 17 DTMF generation and detection Dual Tone Multiple Frequency

Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 24

Follow on ActivitiesFollow on Activities Application 7 for the TMS320C5416 DSKApplication 7 for the TMS320C5416 DSK Uses a microphone to pick up the sounds generated Uses a microphone to pick up the sounds generated

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