00001
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "dsp.h"
00048
00049 #if defined(FORCE_ALL_GENERICS) || \
00050 defined(FORCE_GENERIC_FILT16_NLMS) || \
00051 !defined(TARGET_SPECIFIC_FILT16_NLMS)
00052
00053 #include "filt_nlms.h"
00054
00055 void dsp16_filt_nlms(dsp16_t *x, dsp16_t *w, int size, dsp16_t new_x, dsp16_t d, dsp16_t *y, dsp16_t *e)
00056 {
00057 int i;
00058 static S32 normalization = 0;
00059 S32 temp;
00060
00061 x[0] = new_x;
00062
00063 temp = 0;
00064
00065 for(i=0; i<size; i+=4)
00066 {
00067 temp += (((S32) w[i])*((S32) x[i]));
00068 temp += (((S32) w[i+1])*((S32) x[i+1]));
00069 temp += (((S32) w[i+2])*((S32) x[i+2]));
00070 temp += (((S32) w[i+3])*((S32) x[i+3]));
00071 }
00072 *y = temp >> (DSP16_QB);
00073
00074
00075 *e = d - *y;
00076
00077
00078 normalization += ((((S32) new_x)*((S32) new_x))) >> (DSP16_QB);
00079
00080
00081 if (!normalization)
00082 normalization = 1;
00083
00084 #if !(DSP_OPTIMIZATION & DSP_OPTI_ACCURACY)
00085 temp = ((S32) *e << DSP16_QB)/normalization;
00086 if (temp > 0x7FFF)
00087 temp = 0x7FFF;
00088 else if (temp < -0x8000)
00089 temp = -0x8000;
00090 #endif
00091
00092
00093 for(i=0; i<size; i+=4)
00094 {
00095 #if (DSP_OPTIMIZATION & DSP_OPTI_ACCURACY)
00096 w[i] += ((((((S32) *e)*((S32) x[i])))/normalization) >> (DSP_NLMS_MU - 1));
00097 w[i+1] += ((((((S32) *e)*((S32) x[i+1])))/normalization) >> (DSP_NLMS_MU - 1));
00098 w[i+2] += ((((((S32) *e)*((S32) x[i+2])))/normalization) >> (DSP_NLMS_MU - 1));
00099 w[i+3] += ((((((S32) *e)*((S32) x[i+3])))/normalization) >> (DSP_NLMS_MU - 1));
00100 #else
00101 w[i] += (temp*((S32) x[i])) >> (DSP_NLMS_MU - 1 + DSP16_QB);
00102 w[i+1] += (temp*((S32) x[i+1])) >> (DSP_NLMS_MU - 1 + DSP16_QB);
00103 w[i+2] += (temp*((S32) x[i+2])) >> (DSP_NLMS_MU - 1 + DSP16_QB);
00104 w[i+3] += (temp*((S32) x[i+3])) >> (DSP_NLMS_MU - 1 + DSP16_QB);
00105 #endif
00106 }
00107
00108
00109 normalization -= ((((S32) x[size-1])*((S32) x[size-1]))) >> (DSP16_QB);
00110
00111
00112 for(i=size-1; i>0; i-=4)
00113 {
00114 x[i] = x[i-1];
00115 x[i-1] = x[i-2];
00116 x[i-2] = x[i-3];
00117 x[i-3] = x[i-4];
00118 }
00119 }
00120
00121 #endif
00122