1.4.2.20 DSP_FilterLMS16 Function

Performs a single sample Least Mean Squares FIR Filter.

Description

int16_t DSP_FilterLMS16(int16_t in, int16_t ref, int16_t *coeffs, int16_t *delayline, int16_t *error, int K, int16_t mu);

Computes an LMS adaptive filter on the input in. Filter output of the FIR is given as a 16 bit value. The filter target is ref, and the calculation difference between the output and the target is error. The filter adapts its coefficients, coefs, on each pass. Th number of coefficients (filter taps) is given by the value K. The delayline array should be initialized to zero prior to calling the filter for the first time, and have K elements. The value mu is the rate at which the filter adapts. All values are Q15 fractional numbers.

The function will saturate the output if it exceeds maximum or minimum values. The LMS will adapt its coefs to attempt to drive the output value toward the ref value. The rate of adaption on each pass depends on mu and the error from the previous calculation.

Preconditions

The pointers outdata and indata must be aligned on 4-byte boundaries. delayline must have (K) elements, and be initialized to zero. K (taps) must be a multiple of 4, and >= 8. mu must be positive.

Parameters

in input data value (int16_t)

ref target output value (int16_t)

coeffs pointer to an array of coefficients (int16_t)

delayline pointer to an array of delay variables (int16_t)

error output minus reference (int16_t)

K number of filter taps and coeffs (int)

mu adaption rate (int16_t)

Returns

(int16_t) - FIR filter output

Remarks

Filter coefs may start at random or zero value, but convergence is dependent on the amount of update required.

Example

#define lmsTAPS 8

int16_t lmsOut;

int lmsTaps = lmsTAPS;

int16_t lmsCoefs[lmsTAPS]={0x5000, 0x4000,0x3000, 0x2000,0x1000, 0x0000,0xF000, 0xE000};

int16_t lmsDelay[lmsTAPS]={0};

int16_t *ptrLMSError;

int16_t lmsError = 0x0200;

int16_t inVal=0;

int16_t refVal = 0x0CCC; _// some target value = 0.1_

int16_t lmsAdapt = 0x3000;

ptrLMSError = &lmsError;

for (i=0;i<200;i++)

{

_// get some input value here //_

if (i < 100)

{

inVal = 0x4233;

}

else

{

inVal = 0xCF10;

}

lmsOut = DSP_FilterLMS16(inVal, refVal, lmsCoefs, lmsDelay,

ptrLMSError, lmsTaps, lmsAdapt);

}

C

int16_t DSP_FilterLMS16 (int16_t in , int16_t ref , int16_t * coeffs , int16_t * delayline , int16_t * error , int  K , int16_t mu );