Assembly Files for Matched Filter

by C.R. MacCluer, W8MQW

Three files follow:

  • MATCH.ASM
  • COSINE.ASM
  • THRU.ASM

    THRU.ASM once assembled will test the TI DSK; when running it passes all input to output without change.

    When MATCH.ASM is assembled it will include the COSINE table. When loaded and run it will implement a 8 period matched filter centered at 500 Hz.

    (See annotations for changing center frequency.)

           ****************************************************************
           *   (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 1992                 *
           *                                                              *
           *                       MATCH                                  *
           *                                                              *
           *       This routine first initializes the TMS320C50           *
           *      and TLC32040 on the C5x DSK. The AIC is set to          *
           *      8 kS/s. Then incoming noisy 500 Hz CW signal            *
           *     is filtered by 8 periods of a matched FIR filter.        *
           *                                                              *
           *       This routine is in the main the routines FUNC          *
           *       and Example 7-21 supplied by TI with the DSK.          *
           *                                                              *
           *      Modification by C.R. MacCluer W8MQW  7-8-95             *
           *                                                              *
           ****************************************************************
    
    ;
    
    ; Bit definition of the control register in the AIC             ;
    
    
          ;+-------------------------+
          ;|LP xx G1 G0 | SY AX LB BP|              G1  G0  gain
          ;+------------+------------+             ---------------
          ; |     GAIN    |  |  |  +-- BP Filter    0   0    4
          ; |     Synch --+  |  +----- Loopback     1   1    4
          ; |     Auxin -----+                      0   1    2
          ; + (sinx)/x filter                       1   0    1
    
    ;---------------------------------------------------------------;
    ;
    ;
    	 .mmregs                 ; all standard symbols are defined
    ;
    	 .ds     0f00h           ; store the following initialization
    				 ;  values beginning at 0f00h
    ;
    TA       .word    18              ; sets SCF clock = 288kHz
    RA       .word    18              ;  likewise for receive
    TAp      .word    31              ;
    RAp      .word    31              ;
    TB       .word    36              ; Fs = 8 kHz
    RB       .word    36              ;  likewise for receive
    AIC_CTR  .word    9h
    ;
    ;                explanation of the above:
    ;
    ;  The switched cap filter knee is set by TA and RA --- see fig6,
    ; p. B-29 and p. B-12 of the user guide. The master clock freq is
    ; 10 368 kHz, so dividing by 2*TA=2*18=36 sets SCF clock to 288 kHz,
    ; and thus puts the knee of the filter to just under 4 kHz. See fig6.
    ;
    ;     Next set TB and RB to 36 to give a sampling rate of
    ;              Fs = SCF clock/TB = 288/36 = 8kHz.
    ;
    ;    Since the impulse response uses 16 samples of cosine per period,
    ; the matched filter's center frequency is Fs/16 = 8kHz/16 = 500 Hz.
    ;
    ;   So to listen instead at lower freqs you must lower the sampling
    ; rate Fs by increasing TB and RB.  For example a center freq of
    ; 450 Hz is obtained by changing TB and TB to 40. For these lower center
    ; freqs, the SCF knee should be moved down to below half the sampling
    ; freq Fs to prevent aliasing; do this by increasing TA and RA (to at
    ; most 32) and then refigure TB and RB for the correct filter center freq.
    ; In summary,
    ;
    ;       matched filter center freq = 324/(TA*TB) kHz
    ;
    ;     TAp (TA') and RAp (RA') are not used in this routine but occupy
    ; two spaces in the memory so that TB and RB will be found in their
    ; expected locations.
    ;-------------------------------------------------------------------
    ;  introduce nmemonic address labels:
    ;
    X        .set      037Fh          ; incoming data
    FRSTAP   .set      0380h          ; previous newest data
    LASTAP   .set      03FFh          ; previous oldest data
    COEFFP   .set     02000h          ; cosine table starts
    
    ****************************************************************
    *   Set up the ISR vector                                      *
    
    	 .ps     080ah
    RINT:    B       RECEIVE       ; Serial port rcv interrupt service
    XINT:    B       TRANSMIT      ; Serial port xmt interrupt service
    			       ;
    *
    **************************************************************
    * TMS32C05X INITIALIZATION                                   *
    *                                                            *
    *
    	 .ps 0a00h
    	 .entry
    START:   SETC    INTM             ; Disable interrupts
    	 LDP     #0               ; Set data page pointer
    	 OPL     #0834h,PMST
    	 LACC    #0
    	 SAMM    CWSR             ; Set software wait state to 0
    	 SAMM    PDWSR            ;
    
    * Reset AIC by writing to PA2 (address >52) to DSK
    
    	 SPLK    #022h,IMR        ; Using XINT syn TX & RX
    	 CALL    AICINIT          ; initialize AIC and enable interrupts
    *
    *******************************************************************
    ;         set up convolution:
    ;
    	 CLRC    OVM            ; OVM = 0
    	 SPLK    #012h,IMR
    	 CLRC    INTM           ; enable
    	 SETC   SXM             ; keep track of sign
    	 SPM   3                ; guarantees no overflow in any 128
    				; tap convolution (PM = 11)
    *****************************************************************
    ; the DSP loops, waiting for a rcv or xmt interrupt:
    
    WAIT     NOP
    	 NOP
    	 NOP
    	 B       WAIT
    
    
    
    ****************  end of main program *************************
    ***************************************************************
    
    
    *          Now the subroutines:
    *
    *
    
    ;
    ; RECIEVER INTERRUPT SERVICE ROUTINE
    ;
    RECEIVE:
    
    	 LAMM    DRR          ; read input signal + noise.
    ;  The 16 bit AIC sample comes in with the two lowest bits 0
    
    	 MAR    *,AR2         ; set up aux register
    	 LAR    AR2,#X        ; load memory addr in auxregister
    	 SACL   *,0,AR2       ; store sample in location X
    
    	 MAR   *,AR3          ; set up indirect addressing
    	 LAR  AR3,#LASTAP     ; point to oldest data
    	 ZAP                  ; zero out ACC and P
    	 RPT  #127            ; do 128 tap convolution
    	    MACD  COEFFP,*-
    	 APAC                 ; add in the last product
    
    	 RPT #13              ; output gain is determined:
    	  SFR                 ; throw away lowest 13 bits by
    			      ;  shifting right. This is where
    ; AGC could be inserted: slowly increase the number of right shifts
    ; with strong signals.
    
    	 SFL                  ; shift left twice because the
    	 SFL                  ; lowest two bits sent to AIC
    			      ;  must be 0
    
    	 SACL     DXR         ; send out the processed signal
    
    	 LAR     AR3,#X       ; bring in latest sample mem location
    	 DMOV    *            ; put latest sample in FRSTAP
    	 RETE                 ; return to wait for next input
    
    ****************************************************************
    ; TRANSMIT INTERRUPT SERVICE ROUTINE
    ;
    TRANSMIT:
    	 RETE
    
    *
    ******************************************************************
    *  DESCRIPTION: This routine initializes the TLC320C40 for       *
    *        a 8Khz sample rate with a gain setting of 1             *
    
    * aic initialization data
    *
    AICINIT: SPLK    #20h,TCR           ; To generate 10 MHz from Tout
    	 SPLK    #01h,PRD           ; for AIC master clock
    	 MAR     *,AR0
    	 LACC    #0008h             ; Non continuous mode
    	 SACL    SPC                ; FSX as input
    	 LACC    #00c8h             ; 16 bit words
    	 SACL    SPC
    	 LACC    #080h            ; Pulse AIC reset by setting it low
    	 SACH    DXR
    	 SACL    GREG
    	 LAR     AR0,#0FFFFh
    	 RPT     #10000           ; and taking it high after 10000 cycles
    	 LACC    *,0,AR0          ; (.5ms at 50ns)
    	 SACH    GREG
    	 ;------------------------
    	 LDP     #TA              ;
    	 SETC    SXM              ;
    	 LACC    TA,9             ; Initialized TA and RA register
    	 ADD     RA,2             ;
    	 CALL    AIC_2ND          ;
    	 ;------------------------
    	 LDP     #TB
    	 LACC    TB,9             ; Initialized TB and RB register
    	 ADD     RB,2             ;
    	 ADD     #02h             ;
    	 CALL    AIC_2ND          ;
    	 ;------------------------
    	 LDP     #AIC_CTR
    	 LACC    AIC_CTR,2        ; Initialized control register
    	 ADD     #03h             ;
    	 CALL    AIC_2ND          ;
    	 RET                      ;
    
    AIC_2ND:
    	 LDP     #0
    	 SACH    DXR              ;
    	 CLRC    INTM
    	 IDLE
    	 ADD     #6h,15           ; 0000 0000 0000 0011 XXXX XXXX XXXX XXXX b
    	 SACH    DXR              ;
    	 IDLE
    	 SACL    DXR              ;
    	 IDLE
    	 LACL    #0               ;
    	 SACL    DXR              ; make sure the word got sent
    	 IDLE
    	 SETC    INTM
    	 RET                      ;
    
          .include   "COSINE.ASM"
    
      .end
    
    ***************************************************************
    ***************************************************************
    ***************************************************************
    * *****************************************************
    *            Table of cosines                         *
    *                                                     *
    *      The impulse response of the matched filter     *
    *                                                     *
    *                                                     *
    * *****************************************************
    *
    	 .mmregs
    	 .ds      02000h
    	 .word    32767   ; 1.0          cos 0   period 1
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;    etc       cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    	 .word    32767   ; 1.0          cos 0   period 2
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    	 .word    32767   ; 1.0          cos 0   period 3
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    	 .word    32767   ; 1.0          cos 0   period 4
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    	 .word    32767   ; 1.0          cos 0   period 5
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    	 .word    32767   ; 1.0          cos 0   period 6
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    	 .word    32767   ; 1.0          cos 0   period 7
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    
    	 .word    32767   ; 1.0          cos 0   period 8
    	 .word    30273   ; 0.9238795    cos T
    	 .word    23170   ; 0.7071068    cos 2T
    	 .word    12539   ; 0.3826834    cos 3T
    	 .word    00000   ; 0.0000000    cos 4T
    	 .word   -12539   ;              cos 5T
    	 .word   -23170   ;              cos 6T
    	 .word   -30273   ;              cos 7T
    	 .word   -32768   ;              cos 8T
    	 .word   -30273
    	 .word   -23170
    	 .word   -12539
    	 .word    00000
    	 .word    12539
    	 .word    23170
    	 .word    30273   ;              cos 15T
    *
    
    *********************************************************
    *********************************************************
    *********************************************************
    ****************************************************************
    *   (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 1992                 *
    ****************************************************************
    *  MODULE NAME: thru                                           *
    *                                                              *
    *  DESCRIPTION: This routine initializes the TMS320C50 and     *
    *               TLC32040 on the C5x DSK, then passes           *
    *               a signal thru w/o filtering.                   *
    *                                                              *
    *             mod by C.R. MacCluer W8MQW 7-8-95                *
    *  This a mod of TI's routine FUNC. Many lines are unnecessary *
    *                                                              *
    ****************************************************************
    	 .mmregs
    *
    ;---------------------------------------------------------------;
    ; Bit definition of the control register in the AIC             ;
    ;---------------------------------------------------------------;
    
    
    	 .ds     0f00h           ;
    TA       .word    18              ; Fcut = 4 KHz
    RA       .word    18              ; Fcut = 4 KHz
    TAp      .word    31              ;
    RAp      .word    31              ;
    TB       .word    24              ; Fs = 12 kHz
    RB       .word    24              ; Fs = 12 kHz
    AIC_CTR  .word    9h
    
    ACC_lo   .word    0               ;
    ACC_hi   .word    0               ;
    STAT0    .word    0               ; STAT0 storage
    STAT1    .word    0               ; STAT1 storage
    TEMP     .word    0               ; location of TEMPorary storage
    TEMP1    .word    0               ;
    SIN_SW   .word    00001h          ; 0 -> random noise
    				  ; 1 -> sinewave
    y        .word    0463ch          ; sin(fn*pi), where fn is normalized
    y1       .word    00000h          ; frequency
    seed     .word    07e6dh          ; seed for random noise generator
    
    	 .ds      01000h
    coeff    .word    0678dh          ; cos(fn*pi)
    
    
    ****************************************************************
    *   Set up the ISR vector                                      *
    ****************************************************************
    	 .ps     080ah
    rint:    B       RECEIVE       ;0A; Serial prot receive interrupt RINT.
    xint:    B       TRANSMIT      ;0C; Serial port transmit interrupt XINT.
    
    *
    ******************************************************************
    * TMS32C05X INITIALIZATION                                       *
    *                                                                *
    ******************************************************************
    	 .ps 0a00h
    	 .entry
    START:   SETC    INTM             ; Disable interrupts
    	 LDP     #0               ; Set data page pointer
    	 OPL     #0834h,PMST
    	 LACC    #0
    	 SAMM    CWSR             ; Set software wait state to 0
    	 SAMM    PDWSR            ;
    
    * Reset AIC by writing to PA2 (address >52) to DSK
    
    	 SPLK    #022h,IMR        ; Using XINT syn TX & RX
    	 CALL    AICINIT          ; initialize AIC and enable interrupts
    *
    *******************************************************************
    * This routine enables serial port rx interrupts & configures     *
    * TLC32040 for the frame sync. When RINT is triggered, read a     *
    * dummy data word from the AIC then generate a sine wave to       *
    * send out.                                                       *
    *******************************************************************
    ;
    	 CLRC    OVM              ; OVM = 0
    	 SPM     0                ; PM = 0
    	 SPLK    #012h,IMR
    	 CLRC    INTM             ; enable
    
    ;
    WAIT     NOP                      ; wait for a transmit or receive
    	 NOP
    	 NOP
    	 B       WAIT
    ;------- end of main program ----------;
    
    ;
    ; RECIEVER INTERRUPT SERVICE ROUTINE
    ;
    RECEIVE:
    	 LDP     #TEMP
    	 LAMM    DRR      ; read input
    	 SFL              ;double gain
    	 SFL              ; again
    	 SAMM    DXR      ; send to output
    	 RETE             ; to program
    *
    *
    *
    ; TRANSMIT INTERRUPT SERVICE ROUTINE
    ;
    TRANSMIT:
    	 RETE
    
    *
    ******************************************************************
    *  DESCRIPTION: This routine initializes the TLC320C40 for       *
    *         a 12 Khz sample rate with a gain setting of 1          *
    ******************************************************************
    * aic initialization data
    *
    AICINIT: SPLK    #20h,TCR           ; To generate 10 MHz from Tout
    	 SPLK    #01h,PRD           ; for AIC master clock
    	 MAR     *,AR0
    	 LACC    #0008h             ; Non continuous mode
    	 SACL    SPC                ; FSX as input
    	 LACC    #00c8h             ; 16 bit words
    	 SACL    SPC
    	 LACC    #080h            ; Pulse AIC reset by setting it low
    	 SACH    DXR
    	 SACL    GREG
    	 LAR     AR0,#0FFFFh
    	 RPT     #10000           ; and taking it high after 10000 cycles
    	 LACC    *,0,AR0          ; (.5ms at 50ns)
    	 SACH    GREG
    	 ;------------------------
    	 LDP     #TA              ;
    	 SETC    SXM              ;
    	 LACC    TA,9             ; Initialized TA and RA register
    	 ADD     RA,2             ;
    	 CALL    AIC_2ND          ;
    	 ;------------------------
    	 LDP     #TB
    	 LACC    TB,9             ; Initialized TB and RB register
    	 ADD     RB,2             ;
    	 ADD     #02h             ;
    	 CALL    AIC_2ND          ;
    	 ;------------------------
    	 LDP     #AIC_CTR
    	 LACC    AIC_CTR,2        ; Initialized control register
    	 ADD     #03h             ;
    	 CALL    AIC_2ND          ;
    	 RET                      ;
    
    AIC_2ND:
    	 LDP     #0
    	 SACH    DXR              ;
    	 CLRC    INTM
    	 IDLE
    	 ADD     #6h,15           ; 0000 0000 0000 0011 XXXX XXXX XXXX XXXX b
    	 SACH    DXR              ;
    	 IDLE
    	 SACL    DXR              ;
    	 IDLE
    	 LACL    #0               ;
    	 SACL    DXR              ; make sure the word got sent
    	 IDLE
    	 SETC    INTM
    	 RET                      ;
    	.end
    
    


    This file can be obtained in serveral ways:

  • Contact W8MQW per e-mail.
  • Download this document as a HTML file.
  • Donnload this file with FTP from: www.nitehawk.com == pub == nitehawk == rasmit.


    Return Top of DSP Page.


    For more information on the Matched Filter: Chuck, W8MQW


    For comments or corrections: W6/PA0ZN


    Return to Top Page.