SOURCE CODE FOR W9GR-1 DIGITAL SIGNAL PROCESSOR

from

September 1992 QST Magazine

Note: this is not the source code used in the DSP-3

Return to Quantics Home Page


	IDT     'LMS'
	TITL    'LMS Algorithm AutoNotcher/DeNoiser'

* COPYRIGHT (c) 1992 BY DAVID L. HERSHBERGER, W9GR
* ALL RIGHTS RESERVED

* NONCOMMERCIAL USE BY RADIO AMATEURS AND ELECTRONIC HOBBYISTS IS PERMITTED.
* THIS IS NOT PUBLIC DOMAIN SOFTWARE.
* THIS SOFTWARE MAY NOT BE USED WITHOUT A LICENSE AS THE BASIS
* FOR MANUFACTURE OF COMMERCIAL PRODUCTS.
* COMMERCIAL USE OF THIS SOFTWARE REQUIRES A LICENSE.
* LICENSING INQUIRIES MAY BE DIRECTED TO:
*      QUANTICS
*      P. O. BOX 2163
*      NEVADA CITY, CALIFORNIA  95959-2163

* THIS TMS320C10 ASSEMBLY LANGUAGE PROGRAM IS WRITTEN FOR THE
* W9GR QUANTICS DIGITAL SIGNAL PROCESSOR DESCRIBED ON PAGE 43 OF
* THE SEPTEMBER 1992 ISSUE OF QST MAGAZINE.
* ("LOW COST DIGITAL SIGNAL PROCESSING FOR THE RADIO AMATEUR"
* BY DAVE HERSHBERGER, W9GR)
* FURTHER INFORMATION ON THE LMS ALGORITHM AS IMPLEMENTED HERE IS
* GIVEN IN THE ARTICLE "USING THE LMS ALGORITHM FOR QRM AND QRN
* REDUCTION" BY DR. STEVEN E. REYER, WA9VNJ, AND DAVID L. HERSHBERGER, W9GR,
* IN THE SEPTEMBER 1992 ISSUE OF QEX MAGAZINE.

* THE W9GR / QUANTICS DIGITAL SIGNAL PROCESSOR IS AVAILABLE IN KIT FORM
* (INCLUDING ALL PC BOARD MOUNTED COMPONENTS BUT NO ENCLOSURE OR POWER SUPPLY)
* FROM:
*      QUANTICS
*      P. O. BOX 2163
*      NEVADA CITY, CALIFORNIA  95959

* Filter length = 24 Delay length = 65
* Both notcher and denoiser functions, selected by BIO switch
* LMS coefficients are decayed one at a time per program loop
* Each loop uses 301 instruction cycles
* FS = 5 MHZ / 301 = 16611 HZ

* BIO=1 > AUTOMATIC NOTCH
* BIO=0 > DENOISING FUNCTION

	DSEG

	DORG    >00     PAGE 0

NBETA   BSS     1       BETA VALUE (NOTCH)
NDECAY  BSS     1       DECAY VALUE (NOTCH) (>8000 => NO DECAY)
CBETA   BSS     1       BETA VALUE (DENOISE)
CDECAY  BSS     1       DECAY VALUE (DENOISE) (>8000 => NO DECAY)
ONES    BSS     1       ALL ONES FOR EX-OR

* END OF PAGE 0 TABLE READ VARIABLES

D       BSS     65      INPUT SIGNAL DELAY (NOTCH)
X       BSS     24      FILTER DELAY (NOTCH)
W       BSS     24      LMS COEFFICIENTS
BETA    BSS     1       BETA VALUE (NOTCH)
DECAY   BSS     1       DECAY VALUE (>8000 => NO DECAY)
ONE     BSS     1       CONSTANT 1
Y       BSS     1       WIENER FIR FILTER OUTPUT
E       BSS     1       ERROR SIGNAL
EBETA   BSS     1       E*BETA
SQUARE  BSS     1       INPUT SQUARED
LED     BSS     1       LED DISPLAY
TEMP    BSS     1       TEMPORARY STORAGE
HPFOUT  BSS     1       HPF OUTPUT

	DORG    >80     PAGE 1

HPF     BSS     5       HPF NETWORK COEFFICIENTS
MASK    BSS     1       A/D, D/A 2'S COMPLEMENT CONVERSION MASK
LSBMAX  BSS     1       8 BIT MASK
ONE1    BSS     1       CONSTANT 1

* END OF PAGE 1 TABLE READ VARIABLES

INP     BSS     3       INPUT DELAY, USED FOR HPF
DENOM   BSS     2       INPUT HPF DENOMINATOR DELAY

TOP     EQU     >8F
NFIR    EQU     24      LENGTH OF WIENER FIR FILTER
NDEL    EQU     65      LONG DELAY FOR NOTCHER
SDEL    EQU     1       SHORT DELAY FOR DENOISER MODE

	DEND

	PSEG

	B       START
INTRPT  B       START
START   DINT
	SOVM
	LDPK    0
	LARP    AR0

* ZERO ALL DATA MEMORY LOCATIONS

	ZAC
	LARK    AR0,TOP
CLEAR   SACL    *,0
	BANZ    CLEAR

* STORE AWAY "1" VALUE

	LACK    1
	SACL    ONE

* GET READY FOR TABLE READ, PAGE 0

	LARK    AR0,ONES        ONES: LAST TABLE ENTRY
	LT      ONE
	MPYK    TBLEND
	PAC
	LARP    AR0

* MOVE CONSTANTS TO DATA MEMORY, PAGE 0

MOVTBL  TBLR    *
	SUB     ONE
	BANZ    MOVTBL

* GET READY FOR TABLE READ, PAGE 1

	LARK    AR1,ONE1     ONE1: LAST TABLE ENTRY
	LARK    AR0,TBLEND1-TABLE1
	LT      ONE
	MPYK    TBLEND1
	PAC

* MOVE CONSTANTS TO DATA MEMORY, PAGE 1

	LARP    AR1
MOVTBL1 LDPK    1
	LARP    AR1
	TBLR    *-,AR0
	LDPK    0
	SUB     ONE
	BANZ    MOVTBL1

	LARP    AR0
	LDPK    0

	LARP    AR0
	LARK    AR0,NDEL-1
	LARK    AR1,NFIR-1

* MAIN PROGRAM LOOP

AGAIN   LDPK    1
	IN      INP,PA1         INPUT SAMPLE FROM A/D
	OUT     ONE1,PA0        START NEXT CONVERSION

	ZALS    INP             PUT SAMPLE INTO ACC-L
	XOR     MASK            A/D OFFSET BINARY=>2'S COMP
	AND     LSBMAX          CLEAR ALL LOW ORDER BITS (NOISE)
	SACL    INP             PUT BACK

* INPUT HIGHPASS FILTER:

*       NUMERATOR:

	ZAC
	LT      INP+2
	MPY     HPF+2
	LTD     INP+1
	MPY     HPF+1
	LTD     INP
	MPY     HPF

*       DENOMINATOR:

	LTA     DENOM+1
	MPY     HPF+4
	LTD     DENOM
	MPY     HPF+3
	APAC

	ADD     ONE1,11         ADD 0.5 TO ROUND
	SACH    DENOM,4         SAVE WITH SHIFT
	LDPK    0
	SACH    HPFOUT,4        STORE ON PAGE 0 TOO

	SAR     AR0,TEMP        STORE AR0
	LACK    D               LOAD ACCUM WITH OFFSET
	ADD     TEMP            ADD AR0 VALUE
	SACL    LED             STORE USING LED AS TEMP LOCATION
	LAR     AR0,LED         PUT INTO AR0
	ZALH    HPFOUT          LOAD ACCUM WITH HPF OUTPUT
	SACH    *,0             SAVE HPF OUTPUT IN DELAY
	LAR     AR0,TEMP        RESTORE AR0

* DECAY JUST ONE LMS COEFFICIENT (NOTCH)
* USE AR1 TO POINT TO COEFFICIENT TO BE DECAYED
* TEMPORARILY ADD W TO AR0 CONTENTS THEN RESTORE

	LARP    AR1             USE AR1
	SAR     AR1,TEMP        STORE AR1
	LACK    W               LOAD ACCUM WITH OFFSET
	ADD     TEMP            ADD AR1 VALUE
	SACL    LED             STORE USING LED AS TEMP LOCATION
	LAR     AR1,LED         PUT INTO AR1
	LT      DECAY
	MPY     *               MULTIPLY
	PAC
	SACH    *,1             PUT BACK
	LAR     AR1,TEMP        RESTORE AR1
	BANZ    ARDECAY
	LARK    AR1,NFIR-1
	B       BARGRA
ARDECAY NOP                     NOPS TO MAINTAIN SAMPLING RATE
	NOP
	NOP

* SQUARE INPUT FOR LED DISPLAY, 3DB/SEGMENT

BARGRA  ZALH    HPFOUT
	SACH    TEMP
	LT      TEMP
	MPY     TEMP
	PAC
	SACH    TEMP
	SUBH    SQUARE
	BGZ     PEAK
	ZALH    SQUARE
	SUBH    ONE
	ABS
	SACH    SQUARE
	B       DISPLAY

PEAK    ZALH    TEMP
	SACH    SQUARE
	NOP                     NOPS TO MAINTAIN SAMPLING RATE
	NOP
	NOP
	NOP

* CONVERT TO DISPLAY BY BITWISE OR

DISPLAY LAC     SQUARE,12
	SACH    LED

	LAC     SQUARE,11
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,10
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,9
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,8
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,7
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,6
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,5
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,4
	SACH    TEMP
	ZALS    TEMP
	OR      LED
	SACL    LED

	LAC     SQUARE,3
	SACH    TEMP
	ZALS    TEMP
	OR      LED

	XOR     ONES
	SACL    LED

	OUT     LED,PA2

* DATA DELAY MOVE

	LARP    AR0
	BANZ    WRAP
	BIOZ    DENAR0          TEST FOR NOTCH OR DENOISE
	LARK    AR0,NDEL-1      LOAD AR0 FOR LONG (AUTONOTCH) DELAY
	B       TWEAK
DENAR0  LARK    AR0,SDEL-1      LOAD AR0 FOR SHORT (DENOISER) DELAY
	B       TWEAK
WRAP    NOP                     NOPS TO MAINTAIN SAMPLING RATE
	NOP
	NOP
	NOP
	NOP

* TWEAK NOTCH COEFFICIENTS, BEFORE DOING FILTERING/DATA MOVE:

TWEAK   LT      EBETA

	MPY     X+23
	PAC
	ADDH    W+23
	SACH    W+23

	MPY     X+22
	PAC
	ADDH    W+22
	SACH    W+22

	MPY     X+21
	PAC
	ADDH    W+21
	SACH    W+21

	MPY     X+20
	PAC
	ADDH    W+20
	SACH    W+20

	MPY     X+19
        PAC
	ADDH    W+19
	SACH    W+19

	MPY     X+18
	PAC
	ADDH    W+18
	SACH    W+18

	MPY     X+17
	PAC
	ADDH    W+17
	SACH    W+17

	MPY     X+16
	PAC
	ADDH    W+16
	SACH    W+16

	MPY     X+15
	PAC
	ADDH    W+15
	SACH    W+15

	MPY     X+14
	PAC
	ADDH    W+14
	SACH    W+14

	MPY     X+13
	PAC
	ADDH    W+13
	SACH    W+13

	MPY     X+12
	PAC
	ADDH    W+12
	SACH    W+12

	MPY     X+11
	PAC
	ADDH    W+11
	SACH    W+11

	MPY     X+10
	PAC
	ADDH    W+10
	SACH    W+10

	MPY     X+9
	PAC
	ADDH    W+9
	SACH    W+9

	MPY     X+8
	PAC
	ADDH    W+8
	SACH    W+8

	MPY     X+7
	PAC
	ADDH    W+7
	SACH    W+7

	MPY     X+6
	PAC
	ADDH    W+6
	SACH    W+6

	MPY     X+5
	PAC
	ADDH    W+5
	SACH    W+5

	MPY     X+4
	PAC
	ADDH    W+4
	SACH    W+4

	MPY     X+3
	PAC
	ADDH    W+3
	SACH    W+3

	MPY     X+2
	PAC
	ADDH    W+2
	SACH    W+2

	MPY     X+1
	PAC
	ADDH    W+1
	SACH    W+1

	MPY     X
	PAC
	ADDH    W
	SACH    W

* NOTCHER/DENOISER FIR WIENER FILTER:

	ZAC
	LT      X+23
	MPY     W+23
	LTD     X+22
	MPY     W+22
	LTD     X+21
	MPY     W+21
	LTD     X+20
	MPY     W+20
	LTD     X+19
	MPY     W+19
	LTD     X+18
	MPY     W+18
	LTD     X+17
	MPY     W+17
	LTD     X+16
	MPY     W+16
	LTD     X+15
	MPY     W+15
	LTD     X+14
	MPY     W+14
	LTD     X+13
	MPY     W+13
	LTD     X+12
	MPY     W+12
	LTD     X+11
	MPY     W+11
	LTD     X+10
	MPY     W+10
	LTD     X+9
	MPY     W+9
	LTD     X+8
	MPY     W+8
	LTD     X+7
	MPY     W+7
	LTD     X+6
	MPY     W+6
	LTD     X+5
	MPY     W+5
	LTD     X+4
	MPY     W+4
	LTD     X+3
	MPY     W+3
	LTD     X+2
	MPY     W+2
	LTD     X+1
	MPY     W+1
	LTD     X
	MPY     W
	APAC
	ADD     ONE,15          ADD 0.5 TO ROUND
	SACH    Y,0

* E = D - Y

	ZALH    HPFOUT
	SUBH    Y
	SACH    E

	LT      E
	MPY     BETA
	PAC
	SACH    EBETA

* TAKE DATA FROM DELAY LINE AND PUT IT IN FIR FILTER

	SAR     AR0,TEMP        STORE AR0
	LACK    D               LOAD ACCUM WITH OFFSET
	ADD     TEMP            ADD AR0 VALUE
	SACL    LED             STORE USING LED AS TEMP LOCATION
	LAR     AR0,LED         PUT INTO AR0
	ZALH    *
	SACH    X
	LAR     AR0,TEMP        RESTORE AR0

	BIOZ    DENOISE         TEST FOR NOTCH OR DENOISE

* OUTPUT NOTCHED SIGNAL TO DAC

	ZALS    E               NOTCHED OUTPUT SIGNAL
	LDPK    1
	XOR     MASK            2'S COMP=>OFFSET BINARY
	LDPK    0
	SACL    TEMP            SAVE IT
	OUT     TEMP,PA1        TO D/A CONV

* LOAD NOTCH VALUES FOR DECAY AND BETA

	ZALH    NDECAY
	SACH    DECAY
	ZALH    NBETA
	SACH    BETA

	B AGAIN

* OUTPUT DENOISED SIGNAL TO DAC

DENOISE ZALS    Y               CORRELATOR (DENOISED)
	LDPK    1
	XOR     MASK            2'S COMP=>OFFSET BINARY
	LDPK    0
	SACL    TEMP            SAVE IT
	OUT     TEMP,PA1        TO D/A CONV

* LOAD DENOISE VALUES FOR DECAY AND BETA

	ZALH    CDECAY
	SACH    DECAY
	ZALH    CBETA
	SACH    BETA

	B AGAIN


TABLE   DATA    >1000           NOTCHER BETA VALUE
	DATA    >7FE4           NOTCHER DECAY VALUE (>8000 => NO DECAY)
	DATA    >1800           DENOISE BETA VALUE
	DATA    >7D80           DENOISE DECAY VALUE (>8000 => NO DECAY)
TBLEND  DATA    ?1111111111111111       ONES

* 0.5 DB/40 DB ELLIPTIC IIR HPF
* PASS 300 HZ REJ 35 HZ
* HPF COEFFICIENTS:
TABLE1  DATA    3644,-7288,3644,7700,-3644
	DATA    ?1000000000000000   A/D, D/A 2'S COMPLEMENT CONVERSION MASK
	DATA    ?1111111100000000   A/D 8 BIT MASK
TBLEND1 DATA    ?0000000000000001   CONSTANT ONE

* COPYRIGHT NOTICE

* ASCII DATA STRING EMBEDDED IN THE FOLLOWING DATA STATEMENTS:
* Copyright (c) 1992 by David L. Hershberger W9GR,
* DBA Quantics, P. O. Box 2163, Nevada City, CA 95959-2163.
* All rights reserved.
	DATA    >4343,>6F6F,>7070,>7979,>7272,>6969,>6767,>6868
	DATA    >7474,>2020,>2828,>6363,>2929,>2020,>3131,>3939
	DATA    >3939,>3232,>2020,>6262,>7979,>2020,>4444,>6161
	DATA    >7676,>6969,>6464,>2020,>4C4C,>2E2E,>2020,>4848
	DATA    >6565,>7272,>7373,>6868,>6262,>6565,>7272,>6767
	DATA    >6565,>7272,>2020,>5757,>3939,>4747,>5252,>2C2C
	DATA    >2020,>4444,>4242,>4141,>2020,>5151,>7575,>6161
	DATA    >6E6E,>7474,>6969,>6363,>7373,>2C2C,>2020,>5050
	DATA    >2E2E,>2020,>4F4F,>2E2E,>2020,>4242,>6F6F,>7878
	DATA    >2020,>3232,>3131,>3636,>3333,>2C2C,>2020,>4E4E
	DATA    >6565,>7676,>6161,>6464,>6161,>2020,>4343,>6969
	DATA    >7474,>7979,>2C2C,>2020,>4343,>4141,>2020,>3939
	DATA    >3535,>3939,>3535,>3939,>2D2D,>3232,>3131,>3636
	DATA    >3333,>2E2E,>2020,>4141,>6C6C,>6C6C,>2020,>7272
	DATA    >6969,>6767,>6868,>7474,>7373,>2020,>7272,>6565
	DATA    >7373,>6565,>7272,>7676,>6565,>6464,>2E2E

	DEND
	END



Return to Quantics Home Page