1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_cfft_radix2_f32.c
10 * Description: Radix-2 Decimation in Frequency CFFT & CIFFT Floating point processing function
13 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * - Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * - Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
24 * - Neither the name of ARM LIMITED nor the names of its contributors
25 * may be used to endorse or promote products derived from this
26 * software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 * -------------------------------------------------------------------- */
44 void arm_radix2_butterfly_f32(
48 uint16_t twidCoefModifier
);
50 void arm_radix2_butterfly_inverse_f32(
54 uint16_t twidCoefModifier
,
55 float32_t onebyfftLen
);
57 extern void arm_bitreversal_f32(
60 uint16_t bitRevFactor
,
61 uint16_t * pBitRevTab
);
64 * @ingroup groupTransforms
68 * @addtogroup ComplexFFT
74 * @brief Radix-2 CFFT/CIFFT.
75 * @deprecated Do not use this function. It has been superceded by \ref arm_cfft_f32 and will be removed
77 * @param[in] *S points to an instance of the floating-point Radix-2 CFFT/CIFFT structure.
78 * @param[in, out] *pSrc points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place.
82 void arm_cfft_radix2_f32(
83 const arm_cfft_radix2_instance_f32
* S
,
89 /* Complex IFFT radix-2 */
90 arm_radix2_butterfly_inverse_f32(pSrc
, S
->fftLen
, S
->pTwiddle
,
91 S
->twidCoefModifier
, S
->onebyfftLen
);
95 /* Complex FFT radix-2 */
96 arm_radix2_butterfly_f32(pSrc
, S
->fftLen
, S
->pTwiddle
,
100 if(S
->bitReverseFlag
== 1u)
103 arm_bitreversal_f32(pSrc
, S
->fftLen
, S
->bitRevFactor
, S
->pBitRevTable
);
110 * @} end of ComplexFFT group
115 /* ----------------------------------------------------------------------
116 ** Internal helper function used by the FFTs
117 ** ------------------------------------------------------------------- */
120 * @brief Core function for the floating-point CFFT butterfly process.
121 * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
122 * @param[in] fftLen length of the FFT.
123 * @param[in] *pCoef points to the twiddle coefficient buffer.
124 * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
128 void arm_radix2_butterfly_f32(
132 uint16_t twidCoefModifier
)
137 float32_t xt
, yt
, cosVal
, sinVal
;
138 float32_t p0
, p1
, p2
, p3
;
141 #ifndef ARM_MATH_CM0_FAMILY
143 /* Initializations for the first stage */
149 for (k
= n2
; k
> 0; k
--)
151 cosVal
= pCoef
[ia
* 2];
152 sinVal
= pCoef
[(ia
* 2) + 1];
154 /* Twiddle coefficients index modifier */
155 ia
+= twidCoefModifier
;
157 /* index calculation for the input as, */
158 /* pSrc[i + 0], pSrc[i + fftLen/1] */
161 /* Butterfly implementation */
162 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
163 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
165 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
166 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
174 pSrc
[2 * i
+ 1] = a1
;
176 pSrc
[2 * l
] = p0
+ p1
;
177 pSrc
[2 * l
+ 1] = p2
- p3
;
182 twidCoefModifier
<<= 1u;
185 for (k
= n2
; k
> 2; k
= k
>> 1)
195 cosVal
= pCoef
[ia
* 2];
196 sinVal
= pCoef
[(ia
* 2) + 1];
197 ia
+= twidCoefModifier
;
199 // loop for butterfly
204 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
205 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
207 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
208 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
216 pSrc
[2 * i
+ 1] = a1
;
218 pSrc
[2 * l
] = p0
+ p1
;
219 pSrc
[2 * l
+ 1] = p2
- p3
;
222 } while( i
< fftLen
); // butterfly loop end
224 } while( j
< n2
); // groups loop end
225 twidCoefModifier
<<= 1u;
228 // loop for butterfly
229 for (i
= 0; i
< fftLen
; i
+= 2)
231 a0
= pSrc
[2 * i
] + pSrc
[2 * i
+ 2];
232 xt
= pSrc
[2 * i
] - pSrc
[2 * i
+ 2];
234 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * i
+ 3];
235 a1
= pSrc
[2 * i
+ 3] + pSrc
[2 * i
+ 1];
238 pSrc
[2 * i
+ 1] = a1
;
239 pSrc
[2 * i
+ 2] = xt
;
240 pSrc
[2 * i
+ 3] = yt
;
248 for (k
= fftLen
; k
> 1; k
= k
>> 1)
258 cosVal
= pCoef
[ia
* 2];
259 sinVal
= pCoef
[(ia
* 2) + 1];
260 ia
+= twidCoefModifier
;
262 // loop for butterfly
267 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
268 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
270 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
271 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
279 pSrc
[2 * i
+ 1] = a1
;
281 pSrc
[2 * l
] = p0
+ p1
;
282 pSrc
[2 * l
+ 1] = p2
- p3
;
288 twidCoefModifier
<<= 1u;
291 #endif // #ifndef ARM_MATH_CM0_FAMILY
296 void arm_radix2_butterfly_inverse_f32(
300 uint16_t twidCoefModifier
,
301 float32_t onebyfftLen
)
306 float32_t xt
, yt
, cosVal
, sinVal
;
307 float32_t p0
, p1
, p2
, p3
;
310 #ifndef ARM_MATH_CM0_FAMILY
316 for (i
= 0; i
< n2
; i
++)
318 cosVal
= pCoef
[ia
* 2];
319 sinVal
= pCoef
[(ia
* 2) + 1];
320 ia
+= twidCoefModifier
;
323 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
324 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
326 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
327 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
335 pSrc
[2 * i
+ 1] = a1
;
337 pSrc
[2 * l
] = p0
- p1
;
338 pSrc
[2 * l
+ 1] = p2
+ p3
;
341 twidCoefModifier
<<= 1u;
344 for (k
= fftLen
/ 2; k
> 2; k
= k
>> 1)
354 cosVal
= pCoef
[ia
* 2];
355 sinVal
= pCoef
[(ia
* 2) + 1];
356 ia
+= twidCoefModifier
;
358 // loop for butterfly
363 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
364 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
366 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
367 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
375 pSrc
[2 * i
+ 1] = a1
;
377 pSrc
[2 * l
] = p0
- p1
;
378 pSrc
[2 * l
+ 1] = p2
+ p3
;
381 } while( i
< fftLen
); // butterfly loop end
383 } while(j
< n2
); // groups loop end
385 twidCoefModifier
<<= 1u;
388 // loop for butterfly
389 for (i
= 0; i
< fftLen
; i
+= 2)
391 a0
= pSrc
[2 * i
] + pSrc
[2 * i
+ 2];
392 xt
= pSrc
[2 * i
] - pSrc
[2 * i
+ 2];
394 a1
= pSrc
[2 * i
+ 3] + pSrc
[2 * i
+ 1];
395 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * i
+ 3];
397 p0
= a0
* onebyfftLen
;
398 p2
= xt
* onebyfftLen
;
399 p1
= a1
* onebyfftLen
;
400 p3
= yt
* onebyfftLen
;
403 pSrc
[2 * i
+ 1] = p1
;
404 pSrc
[2 * i
+ 2] = p2
;
405 pSrc
[2 * i
+ 3] = p3
;
406 } // butterfly loop end
413 for (k
= fftLen
; k
> 2; k
= k
>> 1)
423 cosVal
= pCoef
[ia
* 2];
424 sinVal
= pCoef
[(ia
* 2) + 1];
425 ia
= ia
+ twidCoefModifier
;
427 // loop for butterfly
432 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
433 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
435 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
436 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
444 pSrc
[2 * i
+ 1] = a1
;
446 pSrc
[2 * l
] = p0
- p1
;
447 pSrc
[2 * l
+ 1] = p2
+ p3
;
450 } while( i
< fftLen
); // butterfly loop end
452 } while( j
< n2
); // groups loop end
454 twidCoefModifier
= twidCoefModifier
<< 1u;
460 // loop for butterfly
461 for (i
= 0; i
< fftLen
; i
+= n1
)
465 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
466 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
468 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
469 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
471 p0
= a0
* onebyfftLen
;
472 p2
= xt
* onebyfftLen
;
473 p1
= a1
* onebyfftLen
;
474 p3
= yt
* onebyfftLen
;
479 pSrc
[2 * i
+ 1] = p1
;
480 pSrc
[2u * l
+ 1u] = p3
;
481 } // butterfly loop end
483 #endif // #ifndef ARM_MATH_CM0_FAMILY