Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- TMS320C2x DSP - with fir/iir fltering, the filtering coefficients may be fixed or http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
      With FIR/IIR fltering, the filtering coefficients may be fixed or
      adapted. If the coefficients are adapted or updated with time,
      usually with each sample, then the MPYA or MPYS and ZALR
      instructions on the TMS320C25 aid that adaptation by reducing the
      execution time.

      A means of adapting the coefficients on the TMS320C2x is the Least-
      Mean-Square (LMS) algorithm given by the following:

      b(k,(i+1)) = b(k,i) + 2*B * e(i) * x(i-k), where e(i) = x(i) - y(i)
                               N-1
                  and y(i) = SUM OF: b(k) * x(i-k)
                               k=0

      Quantatization errors in the updated coefficients can be minimized
      if the result is obtained by rounding rather than truncating. For
      each coefficient in the filter at a given point in time, the factor
      2*B * e(i) is a constant. This factor can then be computed once and
      stored in the T register for each of the updates; thus, the
      computational requirement has become one multiply-accumulate plus
      rounding. Without the new instructions, the adaptation of each
      coefficient is five instructions corresponding to five clock cycles:

      LRLK  AR2,COEFFD        ; LOAD ADDRESS OF COEFFICIENTS.
      LRLK  AR3,LASTAP        ; LOAD ADDRESS OF DATA SAMPLES.
      LARP  AR2
      LT    ERRF              ; errf = 2*B * e(i)
      ...
      ZALH  *,AR3             ; ACC = b(k,i)*2**16
      ADD   ONE,15            ; ACC = b(k,i)*2**16 + 2**15
      MPY   *-,AR2
      APAC                    ; ACC = b(k,i)*2**16 + errf*x(i-k) + 2**15
      SACH  *+                ; SAVE b(k,i).
      ...

      When the MPYA and ZALR instructions on the TMS320C25 are used, the
      adaptation reduces to three instructions corresponding to three
      clock cycles as follows:

      LRLK  AR2,COEFFD        ; LOAD ADDRESS OF COEFFICIENTS.
      LRLK  AR3,LASTAP        ; LOAD ADDRESS OF DATA SAMPLES.
      LARP  AR2
      LT    ERRF              ; errf = 2*B * e(i)
      ...
      ZALR  *,AR3             ; ACC = b(k,i)*2**16 + 2**15
      MPYA  *-,AR2            ; ACC = b(k,i)*2**16 + errf*x(i-k) + 2**15
*                             ; PREG = errf*x(i-k+1)
      SACH  *+                ; SAVE b(k,i).
      ...

      Note that the processing order has been slightly changed to
      incorporate the use of the MPYA instruction. This is due to the
      accumulation performed by the MPYA is the accumulation of a previous
      product. Adaptive filter length is restricted both by the execution
      time and memory. Besides more processing per sample due to
      adaptation, adaptive filters requires the coefficients to be stored
      in the reconfigurable block of on-chip RAM. Thus the practical limit
      of an adaptive filter with no external data memory is 256 taps. The
      following illustrates an adaptive filter (TMS320C25):

      .title        'ADAPTIVE FILTER'
      .def   ADPFIR
      .def   X,Y
*
* 256-TAP ADAPTIVE FIR FILTER
*   USES ON-CHIP MEMORY (BLOCK B0) FOR COEFFICIENTS
*   USES ON-CHIP MEMORY (BLOCK B1) FOR DATA SAMPLES
*   NEWEST INPUT SHOULD BE IN MEMORY LOCATION X WHEN CALLED
*   OUTPUT WILL BE IN MEMORY LOCATION Y WHEN RETURNED
*   ASSUME THE DATA PAGE IS 0 WHEN THE ROUTINE IS CALLED.
*
COEFFP: .set       0ff00h     ; B0 PROGRAM MEMORY ADDRESS
COEFFD: .set       0200h      ; B0 DATA MEMORY ADDRESS
*
ONE:    .set       07ah       ; CONSTANT ONE          (DP=0)
BETA:   .set       07bh       ; ADAPTATION CONSTANT   (DP=0)
ERR:    .set       07ch       ; SIGNAL ERROR          (DP=0)
ERRF:   .set       07dh       ; ERROR FUNCTION        (DP=0)
Y:      .set       07eh       ; FILTER OUTPUT         (DP=0)
X:      .set       07fh       ; NEWEST DATA SAMPLE    (DP=0)
FRSTAP: .set       0300h      ; NEXT NEWEST DATA SAMPLE
LASTAP: .set       03ffh      ; OLDEST DATA SAMPLE
*
* FINITE IMPULSE RESPONSE (FIR) FILTER
*
ADPFIR      CNFP              ; configure B0 as program
            MPYK  0           ; clear the P-register
            LAC   ONE,14      ; load output rounding bit
            LARP  AR3
            LRLK  AR3,LASTAP  ; point to the oldest sample
FIR         RPTK  255
            MACD  COEFFP,*-   ; 256-tap FIR filter
            CNFD              ; configure B0 as data
            APAC
            SACH  Y,1         ; store the filter output
            NEG
            ADD   X,15        ; add the newest input
            SACH  ERR,1       ; err(i) = x(i) - y(i)
*
* LMS ADAPTATION OF FILTER COEFFICIENTS
*
            LT    ERR
            MPY   BETA
            PAC               ; errf(i) = beta * err(i)
            ADD   ONE,14      ; round the result
            SACH  ERRF,1
*
            MAR   *+
            LAC   X           ; include newest sample
            SACL  *
*
            LRLK  AR2,COEFFD  ; point to the coefficients
            LRLK  AR3,LASTAP  ; point to the data samples
            LT    ERRF
            MPY   *-,AR2      ; P=2*beta*err(i)*x(i-255)
*
ADAPT       ZALR  *,AR3       ; load ACCH with b255(i) & rnd
            MPYA  *-,AR2      ; b255(i+1)=b255(i)+P
*                             ; P=2*beta*err(i)*x(i-254)
            SACH  *+,0,AR1    ; store b255(i+1)
*
            ZALR  *,AR3       ; load ACCH with b254(i) & rnd
            MPYA  *-,AR2      ; b254(i+1)=b254(i)+P
*                             ; P=2*beta*err(i)*x(i-253)
            SACH  *+,0,AR1    ; store b254(i+1)
*
            ZALR  *,AR3       ; load ACCH with b253(i) & rnd
            MPYA  *-,AR2      ; b253(i+1)=b253(i)+P
*                             ; P=2*beta*err(i)*x(i-252)
            SACH  *+,0,AR1    ; store b253(i+1)
      .
      .
      .
*
            ZALR  *,AR3       ; load ACCH with b1(i) & rnd
            MPYA  *-,AR2      ; b1(i+1)=b1(i)+P
*                             ; P=2*beta*err(i)*x(i-0)
            SACH  *+,0,AR1    ; store b1(i+1)
*
            ZALR  *,AR3       ; load ACCH with b0(i) & rnd
            APAC  ;*-,AR2     ; b0(i+1)=b0(i)+P
            SACH  *+,0,AR1    ; store b0(i+1)
*
            RET               ; return to calling routine

See Also: fir

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson