Implement the other bandpass filters and frequency detectors to complete
your DTMF detection system. Here is a possible method to make the
programming easier. Rather than repeating the code from Part 1 seven more
times, the eight filters and detectors could be implemented with one code
block executed eight times with a do loop. This method will require the use
of pointers. For example consider the implemenation of a second-order IIR
filter where the subsript *A* repesents the first bandpass filter (the 697 Hz
bandpass filter):

This will be followed by filter *B*, the 770 Hz filter, etc.

You need to set aside storage for the coefficients, and for the delayed *x*and *y* values for filters *A*, *B*, etc.

Before starting the `do` loop, one pointer (`r0` in the example code)
points to the coefficients of the first filter, and another pointer
(`r4`) points to the states (delayed values) for the first filter. In
the loop as the delayed values are used they are replaced with updated values
(e.g., *y*(*n*-2) is replaced by *y*(*n*-1), which will be *y*(*n*-2) the next time
through the loop). At the end of the loop for the first filter, `r0`
points to the coefficients of the second filter, and `r4` points to the
states of the second filter, and the second time through the `do` loop the
second filter and detector are implemented.

After implementing all the stages, the program should check the outputs of the eight detectors. If a DTMF signal is present at the input, one of the detectors for the lower four frequencies should be asserted, and one of the detectors for the upper four frequencies should be asserted. If this is the case put out a four-bit number on bits 3-0 of Port B indicating which of the 16 keys was pressed, and put out a one on bit 4 of Port B to indicate a DTMF signal is present. If a signal other than a DTMF tone is present (at least one detector output asserted, but the detection outputs do not match any DTMF pattern) put out a one on bit 5 of Port B. If none of the detectors are asserted all bits of Port B should be low.

org x:$100 coefs equ * ; Coefficients for Filter A, 697 Hz bandpass bA2 dc xxxxxxxxxx/2.0 bA1 dc xxxxxxxxxx/2.0 bA0 dc xxxxxxxxxx/2.0 aA2 dc xxxxxxxxxx/2.0 aA1 dc xxxxxxxxxx/2.0 ; Coefficients for Filter B, 770 Hz bandpass bB2 dc xxxxxxxxxx/2.0 bB1 dc xxxxxxxxxx/2.0 bB0 dc xxxxxxxxxx/2.0 aB2 dc xxxxxxxxxx/2.0 aB1 dc xxxxxxxxxx/2.0 org y:$0 ; States for Filter A, 697 Hz bandpass states equ * xAnm2 ds 1 xAnm1 ds 1 yAnm2 ds 1 yAnm1 ds 1 ; States for detector for stage A go here ; States for Filter B, 770 Hz bandpass xBnm2 ds 1 xBnm1 ds 1 yBnm2 ds 1 yBnm1 ds 1 ; States for detector for stage B go here ; Program loop ; Set up pointers ; At start of first loop, they point to coefs and states of 1st filter move #coefs,r0 move #states,r4 do #2,end_filter move x:RX_BUF_BASE,x1 ; Put x(n) into x1 ; b_2 -> x0, r0 points to b_1 ; x(n-2) -> y0, r4 points to x(n-1) move x:(r0)+,x0 y:(r4)+,y0 ; b_2 x(n-2) -> a ; b_1 -> x0, r0 points to b_0 ; x(n-1) -> y0, r4 points to x(n-2) mpy x0,y0,a x:(r0)+,x0 y:(r4)-,y0 ; b_2 x(n-2) + b_1 x(n-1) -> a ; b_0 -> x0, r0 points to a_2 ; x(n-1) -> x(n-2) for next time through filter, r4 points to x(n-1) mac x0,y0,a x:(r0)+,x0 y0,y:(r4)+ ; b_2 x(n-2) + b_1 x(n-1) + b_0 x(n) -> a ; x(n) -> x(n-1) for next time through filter, r4 points to y(n-2) mac x0,x1,a x1,y:(r4)+ ; a_2 -> x0, r0 points to a_1 ; y(n-2) -> y0, r4 points to y(n-1) move x:(r0)+,x0 y:(r4)+,y0 ; b_2 x(n-2) + b_1 x(n-1) + b_0 x(n) - a_2 y(n-2) -> a ; a_1 -> x0, r0 points to b_2 of next filter ; y(n-1) -> y0, r4 points to y(n-2) mac -x0,y0,a x:(r0)+,x0 y:(r4)-,y0 ; b_2 x(n-2) + b_1 x(n-1) + b_0 x(n) - a_2 y(n-2) - a_1 y(n-1) -> a ; y(n-1) -> y(n-2) for next time through filter, r4 points to y(n-1) mac -x0,y0,a y0,y:(r4)+ ; multiply y(n)/2 by 2 to get y(n) asl a ; y(n) -> y(n-1) for next time through; r4 points to x(n-2) of next filter move a,y:(r4)+ ; save y(n) in a temp reg x1 as the input to the detector move a,x1 ; Code for detector goes here ; At end of loop, pointers point to coefs and states of next filter end_filter: ; Check all eight outputs of the detectors ; If one from a DTMF row and one from a DTMF column are present, put out a ; four-bit number of Bits 3-0 of Port B to indicate which one. Also, output ; a one on Bit 4 of Port B to indicate that a DTMF tone is present. ; If at least one detector output is asserted but the pattern does not match ; a DTMF tone, output a one on Bit 5 of Port B. ; If no detector output is asserted, output zeros on Bits 5-0 of Port B.

Copyright © 1998, New Mexico Tech