00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "arm_math.h"
00026
00077 void arm_cfft_mag_f32(
00078 const arm_cfft_radix4_instance_f32 * S,
00079 float32_t * pSrc)
00080 {
00081
00082
00083 arm_cfft_mag_butterfly_f32(pSrc, S->fftLen, S->pTwiddle,
00084 S->twidCoefModifier);
00085
00086 if(S->bitReverseFlag == 1u)
00087 {
00088
00089 arm_cfft_mag_bitreversal_f32(pSrc, S->fftLen, S->bitRevFactor, S->pBitRevTable);
00090 }
00091
00092 }
00093
00094
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void arm_cfft_mag_butterfly_f32(
00115 float32_t * pSrc,
00116 uint16_t fftLen,
00117 float32_t * pCoef,
00118 uint16_t twidCoefModifier)
00119 {
00120
00121 float32_t co1, co2, co3, si1, si2, si3;
00122 uint32_t ia1, ia2, ia3;
00123 uint32_t i0, i1, i2, i3;
00124 uint32_t n1, n2, j, k;
00125
00126 float32_t xaIn, yaIn, xbIn, ybIn, xcIn, ycIn, xdIn, ydIn;
00127 float32_t Xaplusc, Xbplusd, Yaplusc, Ybplusd, Xaminusc, Xbminusd, Yaminusc, Ybminusd;
00128 float32_t Xb12C_out, Yb12C_out, Xc12C_out, Yc12C_out, Xd12C_out, Yd12C_out;
00129 float32_t Xb12_out, Yb12_out, Xc12_out, Yc12_out, Xd12_out, Yd12_out;
00130 float32_t Xa12_out, Ya12_out;
00131 float32_t *ptr1;
00132
00133
00134 n2 = fftLen;
00135 n1 = n2;
00136
00137
00138 n2 >>= 2u;
00139 i0 = 0u;
00140 ia1 = 0u;
00141
00142 j = n2;
00143
00144
00145 do
00146 {
00147
00148
00149 i1 = i0 + n2;
00150 i2 = i1 + n2;
00151 i3 = i2 + n2;
00152
00153 xaIn = pSrc[(2u * i0)];
00154 yaIn = pSrc[(2u * i0) + 1u];
00155
00156 xcIn = pSrc[(2u * i2)];
00157 ycIn = pSrc[(2u * i2) + 1u];
00158
00159 xbIn = pSrc[(2u * i1)];
00160 ybIn = pSrc[(2u * i1) + 1u];
00161
00162 xdIn = pSrc[(2u * i3)];
00163 ydIn = pSrc[(2u * i3) + 1u];
00164
00165
00166 Xaplusc = xaIn + xcIn;
00167
00168 Xbplusd = xbIn + xdIn;
00169
00170 Yaplusc = yaIn + ycIn;
00171
00172 Ybplusd = ybIn + ydIn;
00173
00174
00175 ia2 = ia1 + ia1;
00176 co2 = pCoef[ia2 * 2u];
00177 si2 = pCoef[(ia2 * 2u) + 1u];
00178
00179
00180 Xaminusc = xaIn - xcIn;
00181
00182 Xbminusd = xbIn - xdIn;
00183
00184 Yaminusc = yaIn - ycIn;
00185
00186 Ybminusd = ybIn - ydIn;
00187
00188
00189 pSrc[(2u * i0)] = Xaplusc + Xbplusd;
00190
00191 pSrc[(2u * i0) + 1u] = Yaplusc + Ybplusd;
00192
00193
00194 Xb12C_out = (Xaminusc + Ybminusd);
00195
00196 Yb12C_out = (Yaminusc - Xbminusd);
00197
00198 Xc12C_out = (Xaplusc - Xbplusd);
00199
00200 Yc12C_out = (Yaplusc - Ybplusd);
00201
00202 Xd12C_out = (Xaminusc - Ybminusd);
00203
00204 Yd12C_out = (Xbminusd + Yaminusc);
00205
00206 co1 = pCoef[ia1 * 2u];
00207 si1 = pCoef[(ia1 * 2u) + 1u];
00208
00209
00210 ia3 = ia2 + ia1;
00211 co3 = pCoef[ia3 * 2u];
00212 si3 = pCoef[(ia3 * 2u) + 1u];
00213
00214 Xb12_out = Xb12C_out * co1;
00215 Yb12_out = Yb12C_out * co1;
00216 Xc12_out = Xc12C_out * co2;
00217 Yc12_out = Yc12C_out * co2;
00218 Xd12_out = Xd12C_out * co3;
00219 Yd12_out = Yd12C_out * co3;
00220
00221
00222 Xb12_out += Yb12C_out * si1;
00223
00224 Yb12_out -= Xb12C_out * si1;
00225
00226 Xc12_out += Yc12C_out * si2;
00227
00228 Yc12_out -= Xc12C_out * si2;
00229
00230 Xd12_out += Yd12C_out * si3;
00231
00232 Yd12_out -= Xd12C_out * si3;
00233
00234
00235
00236 pSrc[2u * i1] = Xc12_out;
00237
00238
00239 pSrc[(2u * i1) + 1u] = Yc12_out;
00240
00241
00242 pSrc[2u * i2] = Xb12_out;
00243
00244
00245 pSrc[(2u * i2) + 1u] = Yb12_out;
00246
00247
00248 pSrc[2u * i3] = Xd12_out;
00249
00250
00251 pSrc[(2u * i3) + 1u] = Yd12_out;
00252
00253
00254 ia1 = ia1 + twidCoefModifier;
00255
00256
00257 i0 = i0 + 1u;
00258
00259 }
00260 while(--j);
00261
00262 twidCoefModifier <<= 2u;
00263
00264
00265 for (k = fftLen / 4; k > 4u; k >>= 2u)
00266 {
00267
00268 n1 = n2;
00269 n2 >>= 2u;
00270 ia1 = 0u;
00271
00272
00273 for (j = 0u; j <= (n2 - 1u); j++)
00274 {
00275
00276 ia2 = ia1 + ia1;
00277 ia3 = ia2 + ia1;
00278 co1 = pCoef[ia1 * 2u];
00279 si1 = pCoef[(ia1 * 2u) + 1u];
00280 co2 = pCoef[ia2 * 2u];
00281 si2 = pCoef[(ia2 * 2u) + 1u];
00282 co3 = pCoef[ia3 * 2u];
00283 si3 = pCoef[(ia3 * 2u) + 1u];
00284
00285
00286 ia1 = ia1 + twidCoefModifier;
00287
00288 for (i0 = j; i0 < fftLen; i0 += n1)
00289 {
00290
00291
00292 i1 = i0 + n2;
00293 i2 = i1 + n2;
00294 i3 = i2 + n2;
00295
00296 xaIn = pSrc[(2u * i0)];
00297 yaIn = pSrc[(2u * i0) + 1u];
00298
00299 xbIn = pSrc[(2u * i1)];
00300 ybIn = pSrc[(2u * i1) + 1u];
00301
00302 xcIn = pSrc[(2u * i2)];
00303 ycIn = pSrc[(2u * i2) + 1u];
00304
00305 xdIn = pSrc[(2u * i3)];
00306 ydIn = pSrc[(2u * i3) + 1u];
00307
00308
00309 Xaminusc = xaIn - xcIn;
00310
00311 Xbminusd = xbIn - xdIn;
00312
00313 Yaminusc = yaIn - ycIn;
00314
00315 Ybminusd = ybIn - ydIn;
00316
00317
00318 Xaplusc = xaIn + xcIn;
00319
00320 Xbplusd = xbIn + xdIn;
00321
00322 Yaplusc = yaIn + ycIn;
00323
00324 Ybplusd = ybIn + ydIn;
00325
00326
00327 Xb12C_out = (Xaminusc + Ybminusd);
00328
00329 Yb12C_out = (Yaminusc - Xbminusd);
00330
00331 Xc12C_out = (Xaplusc - Xbplusd);
00332
00333 Yc12C_out = (Yaplusc - Ybplusd);
00334
00335 Xd12C_out = (Xaminusc - Ybminusd);
00336
00337 Yd12C_out = (Xbminusd + Yaminusc);
00338
00339 pSrc[(2u * i0)] = Xaplusc + Xbplusd;
00340 pSrc[(2u * i0) + 1u] = Yaplusc + Ybplusd;
00341
00342 Xb12_out = Xb12C_out * co1;
00343 Yb12_out = Yb12C_out * co1;
00344 Xc12_out = Xc12C_out * co2;
00345 Yc12_out = Yc12C_out * co2;
00346 Xd12_out = Xd12C_out * co3;
00347 Yd12_out = Yd12C_out * co3;
00348
00349
00350 Xb12_out += Yb12C_out * si1;
00351
00352 Yb12_out -= Xb12C_out * si1;
00353
00354 Xc12_out += Yc12C_out * si2;
00355
00356 Yc12_out -= Xc12C_out * si2;
00357
00358 Xd12_out += Yd12C_out * si3;
00359
00360 Yd12_out -= Xd12C_out * si3;
00361
00362
00363 pSrc[2u * i1] = Xc12_out;
00364
00365
00366 pSrc[(2u * i1) + 1u] = Yc12_out;
00367
00368
00369 pSrc[2u * i2] = Xb12_out;
00370
00371
00372 pSrc[(2u * i2) + 1u] = Yb12_out;
00373
00374
00375 pSrc[2u * i3] = Xd12_out;
00376
00377
00378 pSrc[(2u * i3) + 1u] = Yd12_out;
00379
00380 }
00381 }
00382 twidCoefModifier <<= 2u;
00383 }
00384
00385 j = fftLen >> 2;
00386 ptr1 = &pSrc[0];
00387
00388
00389 do
00390 {
00391
00392 xaIn = ptr1[0];
00393 xcIn = ptr1[4];
00394 yaIn = ptr1[1];
00395 ycIn = ptr1[5];
00396
00397
00398 Xaplusc = xaIn + xcIn;
00399
00400 xbIn = ptr1[2];
00401
00402
00403 Xaminusc = xaIn - xcIn;
00404
00405 xdIn = ptr1[6];
00406
00407
00408 Yaplusc = yaIn + ycIn;
00409
00410 ybIn = ptr1[3];
00411
00412
00413 Yaminusc = yaIn - ycIn;
00414
00415 ydIn = ptr1[7];
00416
00417
00418 Xbplusd = xbIn + xdIn;
00419
00420
00421 Ybplusd = ybIn + ydIn;
00422
00423
00424 Xa12_out = (Xaplusc + Xbplusd);
00425
00426
00427 Xbminusd = xbIn - xdIn;
00428
00429
00430 Ya12_out = (Yaplusc + Ybplusd);
00431
00432
00433 Ybminusd = ybIn - ydIn;
00434
00435
00436 Xc12_out = (Xaplusc - Xbplusd);
00437
00438 Yc12_out = (Yaplusc - Ybplusd);
00439
00440 Xb12_out = (Xaminusc + Ybminusd);
00441
00442 Yb12_out = (Yaminusc - Xbminusd);
00443
00444 Xd12_out = (Xaminusc - Ybminusd);
00445
00446 Yd12_out = (Xbminusd + Yaminusc);
00447
00448
00449 Xa12_out = Xa12_out * Xa12_out;
00450 Ya12_out = Ya12_out * Ya12_out;
00451
00452 Xc12_out = Xc12_out * Xc12_out;
00453 Yc12_out = Yc12_out * Yc12_out;
00454
00455 Xb12_out = Xb12_out * Xb12_out;
00456 Yb12_out = Yb12_out * Yb12_out;
00457
00458 Xd12_out = Xd12_out * Xd12_out;
00459 Yd12_out = Yd12_out * Yd12_out;
00460
00461 arm_sqrt_f32(Xa12_out + Ya12_out, pSrc++);
00462 arm_sqrt_f32(Xc12_out + Yc12_out, pSrc++);
00463 arm_sqrt_f32(Xb12_out + Yb12_out, pSrc++);
00464 arm_sqrt_f32(Xd12_out + Yd12_out, pSrc++);
00465
00466
00467
00468 ptr1 = ptr1 + 8u;
00469
00470 }while(--j);
00471
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483 void arm_cfft_mag_bitreversal_f32(
00484 float32_t * pSrc,
00485 uint16_t fftSize,
00486 uint16_t bitRevFactor,
00487 uint16_t * pBitRevTab)
00488 {
00489 uint16_t fftLenBy2, fftLenBy2p1;
00490 uint16_t i, j;
00491 float32_t in;
00492
00493
00494 j = 0u;
00495 fftLenBy2 = fftSize >> 1u;
00496 fftLenBy2p1 = (fftSize >> 1u) + 1u;
00497
00498
00499 for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u)
00500 {
00501 if(i < j)
00502 {
00503
00504 in = pSrc[i];
00505 pSrc[i] = pSrc[j];
00506 pSrc[j] = in;
00507
00508
00509 in = pSrc[(i + fftLenBy2p1)];
00510 pSrc[(i + fftLenBy2p1)] = pSrc[(j + fftLenBy2p1)];
00511 pSrc[(j + fftLenBy2p1)] = in;
00512
00513 }
00514
00515
00516 in = pSrc[ (i + 1u)];
00517 pSrc[(i + 1u)] = pSrc[(j + fftLenBy2)];
00518 pSrc[(j + fftLenBy2)] = in;
00519
00520
00521 j = *pBitRevTab;
00522
00523
00524 pBitRevTab += bitRevFactor;
00525 }
00526 }