1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cfft_f64.c
4 * Description: Combined Radix Decimation in Frequency CFFT Double Precision Floating point processing function
5 *
6 * $Date: 23 April 2021
7 * $Revision: V1.9.0
8 *
9 * Target Processor: Cortex-M and Cortex-A cores
10 * -------------------------------------------------------------------- */
11 /*
12 * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 *
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
19 *
20 * www.apache.org/licenses/LICENSE-2.0
21 *
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.
27 */
28
29 #include "dsp/transform_functions.h"
30 #include "arm_common_tables.h"
31
32
33 extern void arm_radix4_butterfly_f64(
34 float64_t * pSrc,
35 uint16_t fftLen,
36 const float64_t * pCoef,
37 uint16_t twidCoefModifier);
38
39 extern void arm_bitreversal_64(
40 uint64_t * pSrc,
41 const uint16_t bitRevLen,
42 const uint16_t * pBitRevTable);
43
44 /* ----------------------------------------------------------------------
45 * Internal helper function used by the FFTs
46 * ---------------------------------------------------------------------- */
47
48 /*
49 * @brief Core function for the Double Precision floating-point CFFT butterfly process.
50 * @param[in, out] *pSrc points to the in-place buffer of F64 data type.
51 * @param[in] fftLen length of the FFT.
52 * @param[in] *pCoef points to the twiddle coefficient buffer.
53 * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
54 */
55
arm_radix4_butterfly_f64(float64_t * pSrc,uint16_t fftLen,const float64_t * pCoef,uint16_t twidCoefModifier)56 void arm_radix4_butterfly_f64(
57 float64_t * pSrc,
58 uint16_t fftLen,
59 const float64_t * pCoef,
60 uint16_t twidCoefModifier)
61 {
62
63 float64_t co1, co2, co3, si1, si2, si3;
64 uint32_t ia1, ia2, ia3;
65 uint32_t i0, i1, i2, i3;
66 uint32_t n1, n2, j, k;
67
68 float64_t t1, t2, r1, r2, s1, s2;
69
70
71 /* Initializations for the fft calculation */
72 n2 = fftLen;
73 n1 = n2;
74 for (k = fftLen; k > 1U; k >>= 2U)
75 {
76 /* Initializations for the fft calculation */
77 n1 = n2;
78 n2 >>= 2U;
79 ia1 = 0U;
80
81 /* FFT Calculation */
82 j = 0;
83 do
84 {
85 /* index calculation for the coefficients */
86 ia2 = ia1 + ia1;
87 ia3 = ia2 + ia1;
88 co1 = pCoef[ia1 * 2U];
89 si1 = pCoef[(ia1 * 2U) + 1U];
90 co2 = pCoef[ia2 * 2U];
91 si2 = pCoef[(ia2 * 2U) + 1U];
92 co3 = pCoef[ia3 * 2U];
93 si3 = pCoef[(ia3 * 2U) + 1U];
94
95 /* Twiddle coefficients index modifier */
96 ia1 = ia1 + twidCoefModifier;
97
98 i0 = j;
99 do
100 {
101 /* index calculation for the input as, */
102 /* pSrc[i0 + 0], pSrc[i0 + fftLen/4], pSrc[i0 + fftLen/2], pSrc[i0 + 3fftLen/4] */
103 i1 = i0 + n2;
104 i2 = i1 + n2;
105 i3 = i2 + n2;
106
107 /* xa + xc */
108 r1 = pSrc[(2U * i0)] + pSrc[(2U * i2)];
109
110 /* xa - xc */
111 r2 = pSrc[(2U * i0)] - pSrc[(2U * i2)];
112
113 /* ya + yc */
114 s1 = pSrc[(2U * i0) + 1U] + pSrc[(2U * i2) + 1U];
115
116 /* ya - yc */
117 s2 = pSrc[(2U * i0) + 1U] - pSrc[(2U * i2) + 1U];
118
119 /* xb + xd */
120 t1 = pSrc[2U * i1] + pSrc[2U * i3];
121
122 /* xa' = xa + xb + xc + xd */
123 pSrc[2U * i0] = r1 + t1;
124
125 /* xa + xc -(xb + xd) */
126 r1 = r1 - t1;
127
128 /* yb + yd */
129 t2 = pSrc[(2U * i1) + 1U] + pSrc[(2U * i3) + 1U];
130
131 /* ya' = ya + yb + yc + yd */
132 pSrc[(2U * i0) + 1U] = s1 + t2;
133
134 /* (ya + yc) - (yb + yd) */
135 s1 = s1 - t2;
136
137 /* (yb - yd) */
138 t1 = pSrc[(2U * i1) + 1U] - pSrc[(2U * i3) + 1U];
139
140 /* (xb - xd) */
141 t2 = pSrc[2U * i1] - pSrc[2U * i3];
142
143 /* xc' = (xa-xb+xc-xd)co2 + (ya-yb+yc-yd)(si2) */
144 pSrc[2U * i1] = (r1 * co2) + (s1 * si2);
145
146 /* yc' = (ya-yb+yc-yd)co2 - (xa-xb+xc-xd)(si2) */
147 pSrc[(2U * i1) + 1U] = (s1 * co2) - (r1 * si2);
148
149 /* (xa - xc) + (yb - yd) */
150 r1 = r2 + t1;
151
152 /* (xa - xc) - (yb - yd) */
153 r2 = r2 - t1;
154
155 /* (ya - yc) - (xb - xd) */
156 s1 = s2 - t2;
157
158 /* (ya - yc) + (xb - xd) */
159 s2 = s2 + t2;
160
161 /* xb' = (xa+yb-xc-yd)co1 + (ya-xb-yc+xd)(si1) */
162 pSrc[2U * i2] = (r1 * co1) + (s1 * si1);
163
164 /* yb' = (ya-xb-yc+xd)co1 - (xa+yb-xc-yd)(si1) */
165 pSrc[(2U * i2) + 1U] = (s1 * co1) - (r1 * si1);
166
167 /* xd' = (xa-yb-xc+yd)co3 + (ya+xb-yc-xd)(si3) */
168 pSrc[2U * i3] = (r2 * co3) + (s2 * si3);
169
170 /* yd' = (ya+xb-yc-xd)co3 - (xa-yb-xc+yd)(si3) */
171 pSrc[(2U * i3) + 1U] = (s2 * co3) - (r2 * si3);
172
173 i0 += n1;
174 } while ( i0 < fftLen);
175 j++;
176 } while (j <= (n2 - 1U));
177 twidCoefModifier <<= 2U;
178 }
179 }
180
181 /*
182 * @brief Core function for the Double Precision floating-point CFFT butterfly process.
183 * @param[in, out] *pSrc points to the in-place buffer of F64 data type.
184 * @param[in] fftLen length of the FFT.
185 * @param[in] *pCoef points to the twiddle coefficient buffer.
186 * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
187 */
188
arm_cfft_radix4by2_f64(float64_t * pSrc,uint32_t fftLen,const float64_t * pCoef)189 void arm_cfft_radix4by2_f64(
190 float64_t * pSrc,
191 uint32_t fftLen,
192 const float64_t * pCoef)
193 {
194 uint32_t i, l;
195 uint32_t n2, ia;
196 float64_t xt, yt, cosVal, sinVal;
197 float64_t p0, p1,p2,p3,a0,a1;
198
199 n2 = fftLen >> 1;
200 ia = 0;
201 for (i = 0; i < n2; i++)
202 {
203 cosVal = pCoef[2*ia];
204 sinVal = pCoef[2*ia + 1];
205 ia++;
206
207 l = i + n2;
208
209 /* Butterfly implementation */
210 a0 = pSrc[2 * i] + pSrc[2 * l];
211 xt = pSrc[2 * i] - pSrc[2 * l];
212
213 yt = pSrc[2 * i + 1] - pSrc[2 * l + 1];
214 a1 = pSrc[2 * l + 1] + pSrc[2 * i + 1];
215
216 p0 = xt * cosVal;
217 p1 = yt * sinVal;
218 p2 = yt * cosVal;
219 p3 = xt * sinVal;
220
221 pSrc[2 * i] = a0;
222 pSrc[2 * i + 1] = a1;
223
224 pSrc[2 * l] = p0 + p1;
225 pSrc[2 * l + 1] = p2 - p3;
226
227 }
228
229 // first col
230 arm_radix4_butterfly_f64( pSrc, n2, (float64_t*)pCoef, 2U);
231 // second col
232 arm_radix4_butterfly_f64( pSrc + fftLen, n2, (float64_t*)pCoef, 2U);
233
234 }
235
236 /**
237 @addtogroup ComplexFFTF64
238 @{
239 */
240
241 /**
242 @brief Processing function for the Double Precision floating-point complex FFT.
243 @param[in] S points to an instance of the Double Precision floating-point CFFT structure
244 @param[in,out] p1 points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place
245 @param[in] ifftFlag flag that selects transform direction
246 - value = 0: forward transform
247 - value = 1: inverse transform
248 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
249 - value = 0: disables bit reversal of output
250 - value = 1: enables bit reversal of output
251 */
252
arm_cfft_f64(const arm_cfft_instance_f64 * S,float64_t * p1,uint8_t ifftFlag,uint8_t bitReverseFlag)253 void arm_cfft_f64(
254 const arm_cfft_instance_f64 * S,
255 float64_t * p1,
256 uint8_t ifftFlag,
257 uint8_t bitReverseFlag)
258 {
259 uint32_t L = S->fftLen, l;
260 float64_t invL, * pSrc;
261
262 if (ifftFlag == 1U)
263 {
264 /* Conjugate input data */
265 pSrc = p1 + 1;
266 for(l=0; l<L; l++)
267 {
268 *pSrc = -*pSrc;
269 pSrc += 2;
270 }
271 }
272
273 switch (L)
274 {
275 case 16:
276 case 64:
277 case 256:
278 case 1024:
279 case 4096:
280 arm_radix4_butterfly_f64 (p1, L, (float64_t*)S->pTwiddle, 1U);
281 break;
282
283 case 32:
284 case 128:
285 case 512:
286 case 2048:
287 arm_cfft_radix4by2_f64 ( p1, L, (float64_t*)S->pTwiddle);
288 break;
289
290 }
291
292 if ( bitReverseFlag )
293 arm_bitreversal_64((uint64_t*)p1, S->bitRevLength,S->pBitRevTable);
294
295 if (ifftFlag == 1U)
296 {
297 invL = 1.0 / (float64_t)L;
298 /* Conjugate and scale output data */
299 pSrc = p1;
300 for(l=0; l<L; l++)
301 {
302 *pSrc++ *= invL ;
303 *pSrc = -(*pSrc) * invL;
304 pSrc++;
305 }
306 }
307 }
308
309 /**
310 @} end of ComplexFFTF64 group
311 */
312