1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cfft_radix2_q31.c
4 * Description: Radix-2 Decimation in Frequency CFFT & CIFFT Fixed 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_q31(
35 uint16_t twidCoefModifier
);
37 void arm_radix2_butterfly_inverse_q31(
41 uint16_t twidCoefModifier
);
43 void arm_bitreversal_q31(
46 uint16_t bitRevFactor
,
47 uint16_t * pBitRevTab
);
50 * @ingroup groupTransforms
54 * @addtogroup ComplexFFT
60 * @brief Processing function for the fixed-point CFFT/CIFFT.
61 * @deprecated Do not use this function. It has been superseded by \ref arm_cfft_q31 and will be removed
62 * @param[in] *S points to an instance of the fixed-point CFFT/CIFFT structure.
63 * @param[in, out] *pSrc points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place.
67 void arm_cfft_radix2_q31(
68 const arm_cfft_radix2_instance_q31
* S
,
72 if (S
->ifftFlag
== 1U)
74 arm_radix2_butterfly_inverse_q31(pSrc
, S
->fftLen
,
75 S
->pTwiddle
, S
->twidCoefModifier
);
79 arm_radix2_butterfly_q31(pSrc
, S
->fftLen
,
80 S
->pTwiddle
, S
->twidCoefModifier
);
83 arm_bitreversal_q31(pSrc
, S
->fftLen
, S
->bitRevFactor
, S
->pBitRevTable
);
87 * @} end of ComplexFFT group
90 void arm_radix2_butterfly_q31(
94 uint16_t twidCoefModifier
)
97 unsigned i
, j
, k
, l
, m
;
99 q31_t xt
, yt
, cosVal
, sinVal
;
110 for (i
= 0; i
< n2
; i
++)
112 cosVal
= pCoef
[ia
* 2];
113 sinVal
= pCoef
[(ia
* 2) + 1];
114 ia
= ia
+ twidCoefModifier
;
117 xt
= (pSrc
[2 * i
] >> 1U) - (pSrc
[2 * l
] >> 1U);
118 pSrc
[2 * i
] = ((pSrc
[2 * i
] >> 1U) + (pSrc
[2 * l
] >> 1U)) >> 1U;
120 yt
= (pSrc
[2 * i
+ 1] >> 1U) - (pSrc
[2 * l
+ 1] >> 1U);
122 ((pSrc
[2 * l
+ 1] >> 1U) + (pSrc
[2 * i
+ 1] >> 1U)) >> 1U;
124 mult_32x32_keep32_R(p0
, xt
, cosVal
);
125 mult_32x32_keep32_R(p1
, yt
, cosVal
);
126 multAcc_32x32_keep32_R(p0
, yt
, sinVal
);
127 multSub_32x32_keep32_R(p1
, xt
, sinVal
);
130 pSrc
[2U * l
+ 1U] = p1
;
134 twidCoefModifier
<<= 1U;
137 for (k
= fftLen
/ 2; k
> 2; k
= k
>> 1)
144 for (j
= 0; j
< n2
; j
++)
146 cosVal
= pCoef
[ia
* 2];
147 sinVal
= pCoef
[(ia
* 2) + 1];
148 ia
= ia
+ twidCoefModifier
;
150 // loop for butterfly
156 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
157 pSrc
[2 * i
] = (pSrc
[2 * i
] + pSrc
[2 * l
]) >> 1U;
159 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
160 pSrc
[2 * i
+ 1] = (pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1]) >> 1U;
162 mult_32x32_keep32_R(p0
, xt
, cosVal
);
163 mult_32x32_keep32_R(p1
, yt
, cosVal
);
164 multAcc_32x32_keep32_R(p0
, yt
, sinVal
);
165 multSub_32x32_keep32_R(p1
, xt
, sinVal
);
168 pSrc
[2U * l
+ 1U] = p1
;
171 } while ( m
> 0); // butterfly loop end
175 twidCoefModifier
<<= 1U;
182 cosVal
= pCoef
[ia
* 2];
183 sinVal
= pCoef
[(ia
* 2) + 1];
184 ia
= ia
+ twidCoefModifier
;
186 // loop for butterfly
187 for (i
= 0; i
< fftLen
; i
+= n1
)
190 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
191 pSrc
[2 * i
] = (pSrc
[2 * i
] + pSrc
[2 * l
]);
193 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
194 pSrc
[2 * i
+ 1] = (pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1]);
198 pSrc
[2U * l
+ 1U] = yt
;
203 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
204 pSrc
[2 * i
] = (pSrc
[2 * i
] + pSrc
[2 * l
]);
206 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
207 pSrc
[2 * i
+ 1] = (pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1]);
211 pSrc
[2U * l
+ 1U] = yt
;
213 } // butterfly loop end
218 void arm_radix2_butterfly_inverse_q31(
222 uint16_t twidCoefModifier
)
227 q31_t xt
, yt
, cosVal
, sinVal
;
238 for (i
= 0; i
< n2
; i
++)
240 cosVal
= pCoef
[ia
* 2];
241 sinVal
= pCoef
[(ia
* 2) + 1];
242 ia
= ia
+ twidCoefModifier
;
245 xt
= (pSrc
[2 * i
] >> 1U) - (pSrc
[2 * l
] >> 1U);
246 pSrc
[2 * i
] = ((pSrc
[2 * i
] >> 1U) + (pSrc
[2 * l
] >> 1U)) >> 1U;
248 yt
= (pSrc
[2 * i
+ 1] >> 1U) - (pSrc
[2 * l
+ 1] >> 1U);
250 ((pSrc
[2 * l
+ 1] >> 1U) + (pSrc
[2 * i
+ 1] >> 1U)) >> 1U;
252 mult_32x32_keep32_R(p0
, xt
, cosVal
);
253 mult_32x32_keep32_R(p1
, yt
, cosVal
);
254 multSub_32x32_keep32_R(p0
, yt
, sinVal
);
255 multAcc_32x32_keep32_R(p1
, xt
, sinVal
);
258 pSrc
[2U * l
+ 1U] = p1
;
261 twidCoefModifier
= twidCoefModifier
<< 1U;
264 for (k
= fftLen
/ 2; k
> 2; k
= k
>> 1)
271 for (j
= 0; j
< n2
; j
++)
273 cosVal
= pCoef
[ia
* 2];
274 sinVal
= pCoef
[(ia
* 2) + 1];
275 ia
= ia
+ twidCoefModifier
;
277 // loop for butterfly
278 for (i
= j
; i
< fftLen
; i
+= n1
)
281 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
282 pSrc
[2 * i
] = (pSrc
[2 * i
] + pSrc
[2 * l
]) >> 1U;
284 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
285 pSrc
[2 * i
+ 1] = (pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1]) >> 1U;
287 mult_32x32_keep32_R(p0
, xt
, cosVal
);
288 mult_32x32_keep32_R(p1
, yt
, cosVal
);
289 multSub_32x32_keep32_R(p0
, yt
, sinVal
);
290 multAcc_32x32_keep32_R(p1
, xt
, sinVal
);
293 pSrc
[2U * l
+ 1U] = p1
;
294 } // butterfly loop end
298 twidCoefModifier
= twidCoefModifier
<< 1U;
305 cosVal
= pCoef
[ia
* 2];
306 sinVal
= pCoef
[(ia
* 2) + 1];
307 ia
= ia
+ twidCoefModifier
;
309 // loop for butterfly
310 for (i
= 0; i
< fftLen
; i
+= n1
)
313 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
314 pSrc
[2 * i
] = (pSrc
[2 * i
] + pSrc
[2 * l
]);
316 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
317 pSrc
[2 * i
+ 1] = (pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1]);
321 pSrc
[2U * l
+ 1U] = yt
;
326 xt
= pSrc
[2 * i
] - pSrc
[2 * l
];
327 pSrc
[2 * i
] = (pSrc
[2 * i
] + pSrc
[2 * l
]);
329 yt
= pSrc
[2 * i
+ 1] - pSrc
[2 * l
+ 1];
330 pSrc
[2 * i
+ 1] = (pSrc
[2 * l
+ 1] + pSrc
[2 * i
+ 1]);
334 pSrc
[2U * l
+ 1U] = yt
;
336 } // butterfly loop end