Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "arm_math.h"
00057 void arm_lms_q31(
00058 const arm_lms_instance_q31 * S,
00059 q31_t * pSrc,
00060 q31_t * pRef,
00061 q31_t * pOut,
00062 q31_t * pErr,
00063 uint32_t blockSize)
00064 {
00065 q31_t *pState = S->pState;
00066 uint32_t numTaps = S->numTaps;
00067 q31_t *pCoeffs = S->pCoeffs;
00068 q31_t *pStateCurnt;
00069 q31_t mu = S->mu;
00070 q31_t *px;
00071 q31_t *pb;
00072 uint32_t tapCnt, blkCnt;
00073 q63_t acc;
00074 q31_t e = 0;
00075 q31_t alpha;
00076 q31_t coef;
00077 q31_t x0, x1;
00078 q31_t c0, c1;
00079 q31_t coef0, coef1;
00080 q31_t acc_l, acc_h;
00081 uint32_t uShift = ((uint32_t) S->postShift + 1u);
00082 uint32_t lShift = 32u - uShift;
00083
00084
00085
00086 pStateCurnt = &(S->pState[(numTaps - 1u)]);
00087
00088
00089 blkCnt = blockSize;
00090
00091 while(blkCnt > 0u)
00092 {
00093
00094
00095 *pStateCurnt++ = *pSrc++;
00096
00097
00098 px = pState;
00099
00100
00101 pb = pCoeffs;
00102
00103
00104 acc = 0;
00105
00106
00107 tapCnt = numTaps >> 2;
00108
00109 while(tapCnt > 0u)
00110 {
00111
00112
00113 x0 = *px;
00114 c0 = *pb++;
00115 x1 = *(px + 1u);
00116 c1 = *pb++;
00117
00118
00119
00120 acc += (q63_t)x0 * c0;
00121
00122 acc += (q63_t)x1 * c1;
00123
00124
00125 x0 = *(px + 2u);
00126 c0 = *pb++;
00127 x1 = *(px + 3u);
00128 c1 = *pb++;
00129
00130
00131 px += 4u;
00132
00133
00134
00135 acc += (q63_t)x0 * c0;
00136
00137 acc += (q63_t)x1 * c1;
00138
00139
00140 tapCnt--;
00141 }
00142
00143
00144 tapCnt = numTaps % 0x4u;
00145
00146 while(tapCnt > 0u)
00147 {
00148
00149 acc += ((q63_t) (*px++)) * (*pb++);
00150
00151
00152 tapCnt--;
00153 }
00154
00155
00156
00157 acc_l = acc & 0xffffffff;
00158
00159
00160 acc_h = (acc >> 32) & 0xffffffff;
00161
00162 acc = (uint32_t)acc_l >> lShift | acc_h << uShift;
00163
00164
00165 *pOut++ = (q31_t) acc;
00166
00167
00168 e = *pRef++ - (q31_t) acc;
00169
00170 *pErr++ = (q31_t) e;
00171
00172
00173 alpha = (q31_t) (((q63_t) e * mu) >> 31);
00174
00175
00176
00177 px = pState++;
00178
00179
00180 pb = pCoeffs;
00181
00182
00183 tapCnt = numTaps >> 2;
00184
00185
00186 while(tapCnt > 0u)
00187 {
00188
00189 x0 = *px;
00190 x1 = *(px + 1u);
00191 c0 = *pb;
00192 c1 = *(pb + 1u);
00193
00194
00195 coef0 = (q31_t) (((q63_t) alpha * x0) >> (32));
00196 coef1 = (q31_t) (((q63_t) alpha * x1) >> (32));
00197
00198 c0 = clip_q63_to_q31((q63_t)c0 + (coef0 << 1u));
00199 c1 = clip_q63_to_q31((q63_t)c1 + (coef1 << 1u));
00200
00201
00202 *pb = c0;
00203 *(pb + 1u) = c1;
00204
00205
00206 x0 = *(px + 2u);
00207 x1 = *(px + 3u);
00208 c0 = *(pb + 2u);
00209 c1 = *(pb + 3u);
00210
00211
00212
00213 coef0 = (q31_t) (((q63_t) alpha * x0) >> (32));
00214 coef1 = (q31_t) (((q63_t) alpha * x1) >> (32));
00215
00216
00217 c0 = clip_q63_to_q31((q63_t)c0 + (coef0 << 1u));
00218 c1 = clip_q63_to_q31((q63_t)c1 + (coef1 << 1u));
00219
00220
00221 *(pb + 2u) = c0;
00222 *(pb + 3u) = c1;
00223
00224
00225 px += 4u;
00226 pb += 4u;
00227
00228
00229 tapCnt--;
00230 }
00231
00232
00233 tapCnt = numTaps % 0x4u;
00234
00235 while(tapCnt > 0u)
00236 {
00237
00238 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
00239 *pb = clip_q63_to_q31((q63_t) *pb + (coef << 1u));
00240 pb++;
00241
00242
00243 tapCnt--;
00244 }
00245
00246
00247 blkCnt--;
00248 }
00249
00250
00251
00252
00253
00254
00255 pStateCurnt = S->pState;
00256
00257
00258 tapCnt = (numTaps - 1u) >> 2u;
00259
00260
00261 while(tapCnt > 0u)
00262 {
00263 *pStateCurnt++ = *pState++;
00264 *pStateCurnt++ = *pState++;
00265 *pStateCurnt++ = *pState++;
00266 *pStateCurnt++ = *pState++;
00267
00268
00269 tapCnt--;
00270 }
00271
00272
00273 tapCnt = (numTaps - 1u) % 0x4u;
00274
00275
00276 while(tapCnt > 0u)
00277 {
00278 *pStateCurnt++ = *pState++;
00279
00280
00281 tapCnt--;
00282 }
00283
00284 }
00285