-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patharm_rfft_split_f32.c
More file actions
151 lines (116 loc) · 5.2 KB
/
arm_rfft_split_f32.c
File metadata and controls
151 lines (116 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "Arduino.h"
//--------------------------------------------------------------
void split_rfft_f32 (
float * pSrc,
uint32_t fftLen,
const float * pATable,
const float * pBTable,
float * pDst)
{
uint32_t i; /* Loop Counter */
float outR, outI; /* Temporary variables for output */
const float *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
float CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
float *pDst1 = &pDst[2], *pDst2 = &pDst[(4u * fftLen) - 1u]; /* temp pointers for output buffer */
float *pSrc1 = &pSrc[2], *pSrc2 = &pSrc[(2u * fftLen) - 1u]; /* temp pointers for input buffer */
/* Init coefficient pointers */
pCoefA = &pATable[2u];
pCoefB = &pBTable[2u];
i = fftLen - 1u;
while (i > 0u) {
/*
outR = (pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1]
+ pSrc[2 * n - 2 * i] * pBTable[2 * i] +
pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
*/
/* outI = (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] +
pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
pIn[2 * n - 2 * i + 1] * pBTable[2 * i]); */
/* read pATable[2 * i] */
CoefA1 = *pCoefA++;
/* pATable[2 * i + 1] */
CoefA2 = *pCoefA;
/* pSrc[2 * i] * pATable[2 * i] */
outR = *pSrc1 * CoefA1;
/* pSrc[2 * i] * CoefA2 */
outI = *pSrc1++ * CoefA2;
/* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
outR -= (*pSrc1 + *pSrc2) * CoefA2;
/* pSrc[2 * i + 1] * CoefA1 */
outI += *pSrc1++ * CoefA1;
CoefB1 = *pCoefB;
/* pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
outI -= *pSrc2-- * CoefB1;
/* pSrc[2 * fftLen - 2 * i] * CoefA2 */
outI -= *pSrc2 * CoefA2;
/* pSrc[2 * fftLen - 2 * i] * CoefB1 */
outR += *pSrc2-- * CoefB1;
/* write output */
*pDst1++ = outR / 2;
*pDst1++ = outI / 2;
/* write complex conjugate output */
*pDst2-- = -outI / 2;
*pDst2-- = outR / 2;
/* update coefficient pointer */
pCoefB = pCoefB + (2u);
pCoefA = pCoefA + (2u - 1u);
i--;
}
pDst[2u * fftLen] = pSrc[0] - pSrc[1];
pDst[(2u * fftLen) + 1u] = 0.0f;
pDst[0] = pSrc[0] + pSrc[1];
pDst[1] = 0.0f;
}
//--------------------------------------------------------------
void split_rifft_f32 (
float * pSrc,
uint32_t fftLen,
const float * pATable,
const float * pBTable,
float * pDst)
{
float outR, outI; /* Temporary variables for output */
const float *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
float CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
float *pSrc1 = &pSrc[0], *pSrc2 = &pSrc[(2u * fftLen) + 1u];
pCoefA = &pATable[0];
pCoefB = &pBTable[0];
while (fftLen > 0u)
{
/*
outR = (pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
pIn[2 * n - 2 * i] * pBTable[2 * i] -
pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
outI = (pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] -
pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
*/
CoefA1 = *pCoefA++;
CoefA2 = *pCoefA;
/* outR = (pSrc[2 * i] * CoefA1 */
outR = *pSrc1 * CoefA1;
/* - pSrc[2 * i] * CoefA2 */
outI = -(*pSrc1++) * CoefA2;
/* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
outR += (*pSrc1 + *pSrc2) * CoefA2;
/* pSrc[2 * i + 1] * CoefA1 */
outI += (*pSrc1++) * CoefA1;
CoefB1 = *pCoefB;
/* - pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
outI -= *pSrc2-- * CoefB1;
/* pSrc[2 * fftLen - 2 * i] * CoefB1 */
outR += *pSrc2 * CoefB1;
//outR = ((CoefB1 + CoefA2) * (*pSrc2) + CoefA2 * (*pSrc1) + CoefA1 * (*pSrc1)) / 2;
/* pSrc[2 * fftLen - 2 * i] * CoefA2 */
outI += *pSrc2-- * CoefA2;
//outR = ((CoefB1 + CoefA2) * (*pSrc2) + (CoefA2 + CoefA1) * (*pSrc1)) / 2;
/* write output */
*pDst++ = outR / 2;
*pDst++ = outI / 2;
/* update coefficient pointer */
pCoefB = pCoefB + (2u);
pCoefA = pCoefA + (2u - 1u);
/* Decrement loop count */
fftLen--;
}
}