1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cfft_radix2_f32.c
4 * Description: Radix-2 Decimation in Frequency CFFT & CIFFT Floating point processing function
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
31 void arm_radix2_butterfly_f32(
35 uint16_t twidCoefModifier
);
37 void arm_radix2_butterfly_inverse_f32(
41 uint16_t twidCoefModifier
,
42 float32_t onebyfftLen
);
44 extern void arm_bitreversal_f32(
47 uint16_t bitRevFactor
,
48 uint16_t * pBitRevTab
);
51 * @ingroup groupTransforms
55 * @addtogroup ComplexFFT
61 * @brief Radix-2 CFFT/CIFFT.
62 * @deprecated Do not use this function. It has been superseded by \ref arm_cfft_f32 and will be removed
64 * @param[in] *S points to an instance of the floating-point Radix-2 CFFT/CIFFT structure.
65 * @param[in, out] *pSrc points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place.
69 void arm_cfft_radix2_f32(
70 const arm_cfft_radix2_instance_f32
* S
,
74 if (S
->ifftFlag
== 1U)
76 /* Complex IFFT radix-2 */
77 arm_radix2_butterfly_inverse_f32(pSrc
, S
->fftLen
, S
->pTwiddle
,
78 S
->twidCoefModifier
, S
->onebyfftLen
);
82 /* Complex FFT radix-2 */
83 arm_radix2_butterfly_f32(pSrc
, S
->fftLen
, S
->pTwiddle
,
87 if (S
->bitReverseFlag
== 1U)
90 arm_bitreversal_f32(pSrc
, S
->fftLen
, S
->bitRevFactor
, S
->pBitRevTable
);
97 * @} end of ComplexFFT group
102 /* ----------------------------------------------------------------------
103 ** Internal helper function used by the FFTs
104 ** ------------------------------------------------------------------- */
107 * @brief Core function for the floating-point CFFT butterfly process.
108 * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
109 * @param[in] fftLen length of the FFT.
110 * @param[in] *pCoef points to the twiddle coefficient buffer.
111 * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
115 void arm_radix2_butterfly_f32(
119 uint16_t twidCoefModifier
)
124 float32_t xt
, yt
, cosVal
, sinVal
;
125 float32_t p0
, p1
, p2
, p3
;
128 #if defined (ARM_MATH_DSP)
130 /* Initializations for the first stage */
136 for (k
= n2
; k
> 0; k
--)
138 cosVal
= pCoef
[ia
* 2];
139 sinVal
= pCoef
[(ia
* 2) + 1];
141 /* Twiddle coefficients index modifier */
142 ia
+= twidCoefModifier
;
144 /* index calculation for the input as, */
145 /* pSrc[i + 0], pSrc[i + fftLen/1] */
148 /* Butterfly implementation */
149 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
150 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
152 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
153 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
161 pSrc
[2 * i
+ 1] = a1
;
163 pSrc
[2 * l
] = p0
+ p1
;
164 pSrc
[2 * l
+ 1] = p2
- p3
;
169 twidCoefModifier
<<= 1U;
172 for (k
= n2
; k
> 2; k
= k
>> 1)
182 cosVal
= pCoef
[ia
* 2];
183 sinVal
= pCoef
[(ia
* 2) + 1];
184 ia
+= twidCoefModifier
;
186 // loop for butterfly
191 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
192 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
194 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
195 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
203 pSrc
[2 * i
+ 1] = a1
;
205 pSrc
[2 * l
] = p0
+ p1
;
206 pSrc
[2 * l
+ 1] = p2
- p3
;
209 } while ( i
< fftLen
); // butterfly loop end
211 } while ( j
< n2
); // groups loop end
212 twidCoefModifier
<<= 1U;
215 // loop for butterfly
216 for (i
= 0; i
< fftLen
; i
+= 2)
218 a0
= pSrc
[2 * i
] + pSrc
[2 * i
+ 2];
219 xt
= pSrc
[2 * i
] - pSrc
[2 * i
+ 2];
221 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * i
+ 3];
222 a1
= pSrc
[2 * i
+ 3] + pSrc
[2 * i
+ 1];
225 pSrc
[2 * i
+ 1] = a1
;
226 pSrc
[2 * i
+ 2] = xt
;
227 pSrc
[2 * i
+ 3] = yt
;
235 for (k
= fftLen
; k
> 1; k
= k
>> 1)
245 cosVal
= pCoef
[ia
* 2];
246 sinVal
= pCoef
[(ia
* 2) + 1];
247 ia
+= twidCoefModifier
;
249 // loop for butterfly
254 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
255 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
257 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
258 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
266 pSrc
[2 * i
+ 1] = a1
;
268 pSrc
[2 * l
] = p0
+ p1
;
269 pSrc
[2 * l
+ 1] = p2
- p3
;
272 } while (i
< fftLen
);
275 twidCoefModifier
<<= 1U;
278 #endif // #if defined (ARM_MATH_DSP)
283 void arm_radix2_butterfly_inverse_f32(
287 uint16_t twidCoefModifier
,
288 float32_t onebyfftLen
)
293 float32_t xt
, yt
, cosVal
, sinVal
;
294 float32_t p0
, p1
, p2
, p3
;
297 #if defined (ARM_MATH_DSP)
303 for (i
= 0; i
< n2
; i
++)
305 cosVal
= pCoef
[ia
* 2];
306 sinVal
= pCoef
[(ia
* 2) + 1];
307 ia
+= twidCoefModifier
;
310 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
311 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
313 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
314 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
322 pSrc
[2 * i
+ 1] = a1
;
324 pSrc
[2 * l
] = p0
- p1
;
325 pSrc
[2 * l
+ 1] = p2
+ p3
;
328 twidCoefModifier
<<= 1U;
331 for (k
= fftLen
/ 2; k
> 2; k
= k
>> 1)
341 cosVal
= pCoef
[ia
* 2];
342 sinVal
= pCoef
[(ia
* 2) + 1];
343 ia
+= twidCoefModifier
;
345 // loop for butterfly
350 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
351 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
353 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
354 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
362 pSrc
[2 * i
+ 1] = a1
;
364 pSrc
[2 * l
] = p0
- p1
;
365 pSrc
[2 * l
+ 1] = p2
+ p3
;
368 } while ( i
< fftLen
); // butterfly loop end
370 } while (j
< n2
); // groups loop end
372 twidCoefModifier
<<= 1U;
375 // loop for butterfly
376 for (i
= 0; i
< fftLen
; i
+= 2)
378 a0
= pSrc
[2 * i
] + pSrc
[2 * i
+ 2];
379 xt
= pSrc
[2 * i
] - pSrc
[2 * i
+ 2];
381 a1
= pSrc
[2 * i
+ 3] + pSrc
[2 * i
+ 1];
382 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * i
+ 3];
384 p0
= a0
* onebyfftLen
;
385 p2
= xt
* onebyfftLen
;
386 p1
= a1
* onebyfftLen
;
387 p3
= yt
* onebyfftLen
;
390 pSrc
[2 * i
+ 1] = p1
;
391 pSrc
[2 * i
+ 2] = p2
;
392 pSrc
[2 * i
+ 3] = p3
;
393 } // butterfly loop end
400 for (k
= fftLen
; k
> 2; k
= k
>> 1)
410 cosVal
= pCoef
[ia
* 2];
411 sinVal
= pCoef
[(ia
* 2) + 1];
412 ia
= ia
+ twidCoefModifier
;
414 // loop for butterfly
419 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
420 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
422 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
423 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
431 pSrc
[2 * i
+ 1] = a1
;
433 pSrc
[2 * l
] = p0
- p1
;
434 pSrc
[2 * l
+ 1] = p2
+ p3
;
437 } while ( i
< fftLen
); // butterfly loop end
439 } while ( j
< n2
); // groups loop end
441 twidCoefModifier
= twidCoefModifier
<< 1U;
447 // loop for butterfly
448 for (i
= 0; i
< fftLen
; i
+= n1
)
452 a0
= pSrc
[2 * i
] + pSrc
[2 * l
];
453 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
455 a1
= pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1];
456 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
458 p0
= a0
* onebyfftLen
;
459 p2
= xt
* onebyfftLen
;
460 p1
= a1
* onebyfftLen
;
461 p3
= yt
* onebyfftLen
;
466 pSrc
[2 * i
+ 1] = p1
;
467 pSrc
[2U * l
+ 1U] = p3
;
468 } // butterfly loop end
470 #endif // #if defined (ARM_MATH_DSP)