The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/TransformFunctions/arm_cfft_q31.c@3:4098b9d3d571, 2018-06-21 (annotated)
- Committer:
- xorjoep
- Date:
- Thu Jun 21 11:56:27 2018 +0000
- Revision:
- 3:4098b9d3d571
- Parent:
- 1:24714b45cd1b
headers is a folder not a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 1:24714b45cd1b | 1 | /* ---------------------------------------------------------------------- |
xorjoep | 1:24714b45cd1b | 2 | * Project: CMSIS DSP Library |
xorjoep | 1:24714b45cd1b | 3 | * Title: arm_cfft_q31.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Combined Radix Decimation in Frequency CFFT fixed point processing function |
xorjoep | 1:24714b45cd1b | 5 | * |
xorjoep | 1:24714b45cd1b | 6 | * $Date: 27. January 2017 |
xorjoep | 1:24714b45cd1b | 7 | * $Revision: V.1.5.1 |
xorjoep | 1:24714b45cd1b | 8 | * |
xorjoep | 1:24714b45cd1b | 9 | * Target Processor: Cortex-M cores |
xorjoep | 1:24714b45cd1b | 10 | * -------------------------------------------------------------------- */ |
xorjoep | 1:24714b45cd1b | 11 | /* |
xorjoep | 1:24714b45cd1b | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
xorjoep | 1:24714b45cd1b | 13 | * |
xorjoep | 1:24714b45cd1b | 14 | * SPDX-License-Identifier: Apache-2.0 |
xorjoep | 1:24714b45cd1b | 15 | * |
xorjoep | 1:24714b45cd1b | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
xorjoep | 1:24714b45cd1b | 17 | * not use this file except in compliance with the License. |
xorjoep | 1:24714b45cd1b | 18 | * You may obtain a copy of the License at |
xorjoep | 1:24714b45cd1b | 19 | * |
xorjoep | 1:24714b45cd1b | 20 | * www.apache.org/licenses/LICENSE-2.0 |
xorjoep | 1:24714b45cd1b | 21 | * |
xorjoep | 1:24714b45cd1b | 22 | * Unless required by applicable law or agreed to in writing, software |
xorjoep | 1:24714b45cd1b | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
xorjoep | 1:24714b45cd1b | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
xorjoep | 1:24714b45cd1b | 25 | * See the License for the specific language governing permissions and |
xorjoep | 1:24714b45cd1b | 26 | * limitations under the License. |
xorjoep | 1:24714b45cd1b | 27 | */ |
xorjoep | 1:24714b45cd1b | 28 | |
xorjoep | 1:24714b45cd1b | 29 | #include "arm_math.h" |
xorjoep | 1:24714b45cd1b | 30 | |
xorjoep | 1:24714b45cd1b | 31 | extern void arm_radix4_butterfly_q31( |
xorjoep | 1:24714b45cd1b | 32 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 33 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 34 | q31_t * pCoef, |
xorjoep | 1:24714b45cd1b | 35 | uint32_t twidCoefModifier); |
xorjoep | 1:24714b45cd1b | 36 | |
xorjoep | 1:24714b45cd1b | 37 | extern void arm_radix4_butterfly_inverse_q31( |
xorjoep | 1:24714b45cd1b | 38 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 39 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 40 | q31_t * pCoef, |
xorjoep | 1:24714b45cd1b | 41 | uint32_t twidCoefModifier); |
xorjoep | 1:24714b45cd1b | 42 | |
xorjoep | 1:24714b45cd1b | 43 | extern void arm_bitreversal_32( |
xorjoep | 1:24714b45cd1b | 44 | uint32_t * pSrc, |
xorjoep | 1:24714b45cd1b | 45 | const uint16_t bitRevLen, |
xorjoep | 1:24714b45cd1b | 46 | const uint16_t * pBitRevTable); |
xorjoep | 1:24714b45cd1b | 47 | |
xorjoep | 1:24714b45cd1b | 48 | void arm_cfft_radix4by2_q31( |
xorjoep | 1:24714b45cd1b | 49 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 50 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 51 | const q31_t * pCoef); |
xorjoep | 1:24714b45cd1b | 52 | |
xorjoep | 1:24714b45cd1b | 53 | void arm_cfft_radix4by2_inverse_q31( |
xorjoep | 1:24714b45cd1b | 54 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 55 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 56 | const q31_t * pCoef); |
xorjoep | 1:24714b45cd1b | 57 | |
xorjoep | 1:24714b45cd1b | 58 | /** |
xorjoep | 1:24714b45cd1b | 59 | * @ingroup groupTransforms |
xorjoep | 1:24714b45cd1b | 60 | */ |
xorjoep | 1:24714b45cd1b | 61 | |
xorjoep | 1:24714b45cd1b | 62 | /** |
xorjoep | 1:24714b45cd1b | 63 | * @addtogroup ComplexFFT |
xorjoep | 1:24714b45cd1b | 64 | * @{ |
xorjoep | 1:24714b45cd1b | 65 | */ |
xorjoep | 1:24714b45cd1b | 66 | |
xorjoep | 1:24714b45cd1b | 67 | /** |
xorjoep | 1:24714b45cd1b | 68 | * @details |
xorjoep | 1:24714b45cd1b | 69 | * @brief Processing function for the fixed-point complex FFT in Q31 format. |
xorjoep | 1:24714b45cd1b | 70 | * @param[in] *S points to an instance of the fixed-point CFFT structure. |
xorjoep | 1:24714b45cd1b | 71 | * @param[in, out] *p1 points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place. |
xorjoep | 1:24714b45cd1b | 72 | * @param[in] ifftFlag flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. |
xorjoep | 1:24714b45cd1b | 73 | * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. |
xorjoep | 1:24714b45cd1b | 74 | * @return none. |
xorjoep | 1:24714b45cd1b | 75 | */ |
xorjoep | 1:24714b45cd1b | 76 | |
xorjoep | 1:24714b45cd1b | 77 | void arm_cfft_q31( |
xorjoep | 1:24714b45cd1b | 78 | const arm_cfft_instance_q31 * S, |
xorjoep | 1:24714b45cd1b | 79 | q31_t * p1, |
xorjoep | 1:24714b45cd1b | 80 | uint8_t ifftFlag, |
xorjoep | 1:24714b45cd1b | 81 | uint8_t bitReverseFlag) |
xorjoep | 1:24714b45cd1b | 82 | { |
xorjoep | 1:24714b45cd1b | 83 | uint32_t L = S->fftLen; |
xorjoep | 1:24714b45cd1b | 84 | |
xorjoep | 1:24714b45cd1b | 85 | if (ifftFlag == 1U) |
xorjoep | 1:24714b45cd1b | 86 | { |
xorjoep | 1:24714b45cd1b | 87 | switch (L) |
xorjoep | 1:24714b45cd1b | 88 | { |
xorjoep | 1:24714b45cd1b | 89 | case 16: |
xorjoep | 1:24714b45cd1b | 90 | case 64: |
xorjoep | 1:24714b45cd1b | 91 | case 256: |
xorjoep | 1:24714b45cd1b | 92 | case 1024: |
xorjoep | 1:24714b45cd1b | 93 | case 4096: |
xorjoep | 1:24714b45cd1b | 94 | arm_radix4_butterfly_inverse_q31 ( p1, L, (q31_t*)S->pTwiddle, 1 ); |
xorjoep | 1:24714b45cd1b | 95 | break; |
xorjoep | 1:24714b45cd1b | 96 | |
xorjoep | 1:24714b45cd1b | 97 | case 32: |
xorjoep | 1:24714b45cd1b | 98 | case 128: |
xorjoep | 1:24714b45cd1b | 99 | case 512: |
xorjoep | 1:24714b45cd1b | 100 | case 2048: |
xorjoep | 1:24714b45cd1b | 101 | arm_cfft_radix4by2_inverse_q31 ( p1, L, S->pTwiddle ); |
xorjoep | 1:24714b45cd1b | 102 | break; |
xorjoep | 1:24714b45cd1b | 103 | } |
xorjoep | 1:24714b45cd1b | 104 | } |
xorjoep | 1:24714b45cd1b | 105 | else |
xorjoep | 1:24714b45cd1b | 106 | { |
xorjoep | 1:24714b45cd1b | 107 | switch (L) |
xorjoep | 1:24714b45cd1b | 108 | { |
xorjoep | 1:24714b45cd1b | 109 | case 16: |
xorjoep | 1:24714b45cd1b | 110 | case 64: |
xorjoep | 1:24714b45cd1b | 111 | case 256: |
xorjoep | 1:24714b45cd1b | 112 | case 1024: |
xorjoep | 1:24714b45cd1b | 113 | case 4096: |
xorjoep | 1:24714b45cd1b | 114 | arm_radix4_butterfly_q31 ( p1, L, (q31_t*)S->pTwiddle, 1 ); |
xorjoep | 1:24714b45cd1b | 115 | break; |
xorjoep | 1:24714b45cd1b | 116 | |
xorjoep | 1:24714b45cd1b | 117 | case 32: |
xorjoep | 1:24714b45cd1b | 118 | case 128: |
xorjoep | 1:24714b45cd1b | 119 | case 512: |
xorjoep | 1:24714b45cd1b | 120 | case 2048: |
xorjoep | 1:24714b45cd1b | 121 | arm_cfft_radix4by2_q31 ( p1, L, S->pTwiddle ); |
xorjoep | 1:24714b45cd1b | 122 | break; |
xorjoep | 1:24714b45cd1b | 123 | } |
xorjoep | 1:24714b45cd1b | 124 | } |
xorjoep | 1:24714b45cd1b | 125 | |
xorjoep | 1:24714b45cd1b | 126 | if ( bitReverseFlag ) |
xorjoep | 1:24714b45cd1b | 127 | arm_bitreversal_32((uint32_t*)p1,S->bitRevLength,S->pBitRevTable); |
xorjoep | 1:24714b45cd1b | 128 | } |
xorjoep | 1:24714b45cd1b | 129 | |
xorjoep | 1:24714b45cd1b | 130 | /** |
xorjoep | 1:24714b45cd1b | 131 | * @} end of ComplexFFT group |
xorjoep | 1:24714b45cd1b | 132 | */ |
xorjoep | 1:24714b45cd1b | 133 | |
xorjoep | 1:24714b45cd1b | 134 | void arm_cfft_radix4by2_q31( |
xorjoep | 1:24714b45cd1b | 135 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 136 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 137 | const q31_t * pCoef) |
xorjoep | 1:24714b45cd1b | 138 | { |
xorjoep | 1:24714b45cd1b | 139 | uint32_t i, l; |
xorjoep | 1:24714b45cd1b | 140 | uint32_t n2, ia; |
xorjoep | 1:24714b45cd1b | 141 | q31_t xt, yt, cosVal, sinVal; |
xorjoep | 1:24714b45cd1b | 142 | q31_t p0, p1; |
xorjoep | 1:24714b45cd1b | 143 | |
xorjoep | 1:24714b45cd1b | 144 | n2 = fftLen >> 1; |
xorjoep | 1:24714b45cd1b | 145 | ia = 0; |
xorjoep | 1:24714b45cd1b | 146 | for (i = 0; i < n2; i++) |
xorjoep | 1:24714b45cd1b | 147 | { |
xorjoep | 1:24714b45cd1b | 148 | cosVal = pCoef[2*ia]; |
xorjoep | 1:24714b45cd1b | 149 | sinVal = pCoef[2*ia + 1]; |
xorjoep | 1:24714b45cd1b | 150 | ia++; |
xorjoep | 1:24714b45cd1b | 151 | |
xorjoep | 1:24714b45cd1b | 152 | l = i + n2; |
xorjoep | 1:24714b45cd1b | 153 | xt = (pSrc[2 * i] >> 2) - (pSrc[2 * l] >> 2); |
xorjoep | 1:24714b45cd1b | 154 | pSrc[2 * i] = (pSrc[2 * i] >> 2) + (pSrc[2 * l] >> 2); |
xorjoep | 1:24714b45cd1b | 155 | |
xorjoep | 1:24714b45cd1b | 156 | yt = (pSrc[2 * i + 1] >> 2) - (pSrc[2 * l + 1] >> 2); |
xorjoep | 1:24714b45cd1b | 157 | pSrc[2 * i + 1] = (pSrc[2 * l + 1] >> 2) + (pSrc[2 * i + 1] >> 2); |
xorjoep | 1:24714b45cd1b | 158 | |
xorjoep | 1:24714b45cd1b | 159 | mult_32x32_keep32_R(p0, xt, cosVal); |
xorjoep | 1:24714b45cd1b | 160 | mult_32x32_keep32_R(p1, yt, cosVal); |
xorjoep | 1:24714b45cd1b | 161 | multAcc_32x32_keep32_R(p0, yt, sinVal); |
xorjoep | 1:24714b45cd1b | 162 | multSub_32x32_keep32_R(p1, xt, sinVal); |
xorjoep | 1:24714b45cd1b | 163 | |
xorjoep | 1:24714b45cd1b | 164 | pSrc[2U * l] = p0 << 1; |
xorjoep | 1:24714b45cd1b | 165 | pSrc[2U * l + 1U] = p1 << 1; |
xorjoep | 1:24714b45cd1b | 166 | |
xorjoep | 1:24714b45cd1b | 167 | } |
xorjoep | 1:24714b45cd1b | 168 | |
xorjoep | 1:24714b45cd1b | 169 | // first col |
xorjoep | 1:24714b45cd1b | 170 | arm_radix4_butterfly_q31( pSrc, n2, (q31_t*)pCoef, 2U); |
xorjoep | 1:24714b45cd1b | 171 | // second col |
xorjoep | 1:24714b45cd1b | 172 | arm_radix4_butterfly_q31( pSrc + fftLen, n2, (q31_t*)pCoef, 2U); |
xorjoep | 1:24714b45cd1b | 173 | |
xorjoep | 1:24714b45cd1b | 174 | for (i = 0; i < fftLen >> 1; i++) |
xorjoep | 1:24714b45cd1b | 175 | { |
xorjoep | 1:24714b45cd1b | 176 | p0 = pSrc[4*i+0]; |
xorjoep | 1:24714b45cd1b | 177 | p1 = pSrc[4*i+1]; |
xorjoep | 1:24714b45cd1b | 178 | xt = pSrc[4*i+2]; |
xorjoep | 1:24714b45cd1b | 179 | yt = pSrc[4*i+3]; |
xorjoep | 1:24714b45cd1b | 180 | |
xorjoep | 1:24714b45cd1b | 181 | p0 <<= 1; |
xorjoep | 1:24714b45cd1b | 182 | p1 <<= 1; |
xorjoep | 1:24714b45cd1b | 183 | xt <<= 1; |
xorjoep | 1:24714b45cd1b | 184 | yt <<= 1; |
xorjoep | 1:24714b45cd1b | 185 | |
xorjoep | 1:24714b45cd1b | 186 | pSrc[4*i+0] = p0; |
xorjoep | 1:24714b45cd1b | 187 | pSrc[4*i+1] = p1; |
xorjoep | 1:24714b45cd1b | 188 | pSrc[4*i+2] = xt; |
xorjoep | 1:24714b45cd1b | 189 | pSrc[4*i+3] = yt; |
xorjoep | 1:24714b45cd1b | 190 | } |
xorjoep | 1:24714b45cd1b | 191 | |
xorjoep | 1:24714b45cd1b | 192 | } |
xorjoep | 1:24714b45cd1b | 193 | |
xorjoep | 1:24714b45cd1b | 194 | void arm_cfft_radix4by2_inverse_q31( |
xorjoep | 1:24714b45cd1b | 195 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 196 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 197 | const q31_t * pCoef) |
xorjoep | 1:24714b45cd1b | 198 | { |
xorjoep | 1:24714b45cd1b | 199 | uint32_t i, l; |
xorjoep | 1:24714b45cd1b | 200 | uint32_t n2, ia; |
xorjoep | 1:24714b45cd1b | 201 | q31_t xt, yt, cosVal, sinVal; |
xorjoep | 1:24714b45cd1b | 202 | q31_t p0, p1; |
xorjoep | 1:24714b45cd1b | 203 | |
xorjoep | 1:24714b45cd1b | 204 | n2 = fftLen >> 1; |
xorjoep | 1:24714b45cd1b | 205 | ia = 0; |
xorjoep | 1:24714b45cd1b | 206 | for (i = 0; i < n2; i++) |
xorjoep | 1:24714b45cd1b | 207 | { |
xorjoep | 1:24714b45cd1b | 208 | cosVal = pCoef[2*ia]; |
xorjoep | 1:24714b45cd1b | 209 | sinVal = pCoef[2*ia + 1]; |
xorjoep | 1:24714b45cd1b | 210 | ia++; |
xorjoep | 1:24714b45cd1b | 211 | |
xorjoep | 1:24714b45cd1b | 212 | l = i + n2; |
xorjoep | 1:24714b45cd1b | 213 | xt = (pSrc[2 * i] >> 2) - (pSrc[2 * l] >> 2); |
xorjoep | 1:24714b45cd1b | 214 | pSrc[2 * i] = (pSrc[2 * i] >> 2) + (pSrc[2 * l] >> 2); |
xorjoep | 1:24714b45cd1b | 215 | |
xorjoep | 1:24714b45cd1b | 216 | yt = (pSrc[2 * i + 1] >> 2) - (pSrc[2 * l + 1] >> 2); |
xorjoep | 1:24714b45cd1b | 217 | pSrc[2 * i + 1] = (pSrc[2 * l + 1] >> 2) + (pSrc[2 * i + 1] >> 2); |
xorjoep | 1:24714b45cd1b | 218 | |
xorjoep | 1:24714b45cd1b | 219 | mult_32x32_keep32_R(p0, xt, cosVal); |
xorjoep | 1:24714b45cd1b | 220 | mult_32x32_keep32_R(p1, yt, cosVal); |
xorjoep | 1:24714b45cd1b | 221 | multSub_32x32_keep32_R(p0, yt, sinVal); |
xorjoep | 1:24714b45cd1b | 222 | multAcc_32x32_keep32_R(p1, xt, sinVal); |
xorjoep | 1:24714b45cd1b | 223 | |
xorjoep | 1:24714b45cd1b | 224 | pSrc[2U * l] = p0 << 1; |
xorjoep | 1:24714b45cd1b | 225 | pSrc[2U * l + 1U] = p1 << 1; |
xorjoep | 1:24714b45cd1b | 226 | |
xorjoep | 1:24714b45cd1b | 227 | } |
xorjoep | 1:24714b45cd1b | 228 | |
xorjoep | 1:24714b45cd1b | 229 | // first col |
xorjoep | 1:24714b45cd1b | 230 | arm_radix4_butterfly_inverse_q31( pSrc, n2, (q31_t*)pCoef, 2U); |
xorjoep | 1:24714b45cd1b | 231 | // second col |
xorjoep | 1:24714b45cd1b | 232 | arm_radix4_butterfly_inverse_q31( pSrc + fftLen, n2, (q31_t*)pCoef, 2U); |
xorjoep | 1:24714b45cd1b | 233 | |
xorjoep | 1:24714b45cd1b | 234 | for (i = 0; i < fftLen >> 1; i++) |
xorjoep | 1:24714b45cd1b | 235 | { |
xorjoep | 1:24714b45cd1b | 236 | p0 = pSrc[4*i+0]; |
xorjoep | 1:24714b45cd1b | 237 | p1 = pSrc[4*i+1]; |
xorjoep | 1:24714b45cd1b | 238 | xt = pSrc[4*i+2]; |
xorjoep | 1:24714b45cd1b | 239 | yt = pSrc[4*i+3]; |
xorjoep | 1:24714b45cd1b | 240 | |
xorjoep | 1:24714b45cd1b | 241 | p0 <<= 1; |
xorjoep | 1:24714b45cd1b | 242 | p1 <<= 1; |
xorjoep | 1:24714b45cd1b | 243 | xt <<= 1; |
xorjoep | 1:24714b45cd1b | 244 | yt <<= 1; |
xorjoep | 1:24714b45cd1b | 245 | |
xorjoep | 1:24714b45cd1b | 246 | pSrc[4*i+0] = p0; |
xorjoep | 1:24714b45cd1b | 247 | pSrc[4*i+1] = p1; |
xorjoep | 1:24714b45cd1b | 248 | pSrc[4*i+2] = xt; |
xorjoep | 1:24714b45cd1b | 249 | pSrc[4*i+3] = yt; |
xorjoep | 1:24714b45cd1b | 250 | } |
xorjoep | 1:24714b45cd1b | 251 | } |
xorjoep | 1:24714b45cd1b | 252 |