CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Committer:
simon
Date:
Thu Mar 10 15:07:50 2011 +0000
Revision:
0:1014af42efd9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:1014af42efd9 1 /* ----------------------------------------------------------------------
simon 0:1014af42efd9 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
simon 0:1014af42efd9 3 *
simon 0:1014af42efd9 4 * $Date: 29. November 2010
simon 0:1014af42efd9 5 * $Revision: V1.0.3
simon 0:1014af42efd9 6 *
simon 0:1014af42efd9 7 * Project: CMSIS DSP Library
simon 0:1014af42efd9 8 * Title: arm_rfft_q15.c
simon 0:1014af42efd9 9 *
simon 0:1014af42efd9 10 * Description: RFFT & RIFFT Q15 process function
simon 0:1014af42efd9 11 *
simon 0:1014af42efd9 12 *
simon 0:1014af42efd9 13 * Target Processor: Cortex-M4/Cortex-M3
simon 0:1014af42efd9 14 *
simon 0:1014af42efd9 15 * Version 1.0.3 2010/11/29
simon 0:1014af42efd9 16 * Re-organized the CMSIS folders and updated documentation.
simon 0:1014af42efd9 17 *
simon 0:1014af42efd9 18 * Version 1.0.2 2010/11/11
simon 0:1014af42efd9 19 * Documentation updated.
simon 0:1014af42efd9 20 *
simon 0:1014af42efd9 21 * Version 1.0.1 2010/10/05
simon 0:1014af42efd9 22 * Production release and review comments incorporated.
simon 0:1014af42efd9 23 *
simon 0:1014af42efd9 24 * Version 1.0.0 2010/09/20
simon 0:1014af42efd9 25 * Production release and review comments incorporated
simon 0:1014af42efd9 26 *
simon 0:1014af42efd9 27 * Version 0.0.7 2010/06/10
simon 0:1014af42efd9 28 * Misra-C changes done
simon 0:1014af42efd9 29 * -------------------------------------------------------------------- */
simon 0:1014af42efd9 30
simon 0:1014af42efd9 31
simon 0:1014af42efd9 32 #include "arm_math.h"
simon 0:1014af42efd9 33
simon 0:1014af42efd9 34 /*--------------------------------------------------------------------
simon 0:1014af42efd9 35 * Internal functions prototypes
simon 0:1014af42efd9 36 --------------------------------------------------------------------*/
simon 0:1014af42efd9 37
simon 0:1014af42efd9 38 void arm_split_rfft_q15(
simon 0:1014af42efd9 39 q15_t * pSrc,
simon 0:1014af42efd9 40 uint32_t fftLen,
simon 0:1014af42efd9 41 q15_t * pATable,
simon 0:1014af42efd9 42 q15_t * pBTable,
simon 0:1014af42efd9 43 q15_t * pDst,
simon 0:1014af42efd9 44 uint32_t modifier);
simon 0:1014af42efd9 45
simon 0:1014af42efd9 46 void arm_split_rifft_q15(
simon 0:1014af42efd9 47 q15_t * pSrc,
simon 0:1014af42efd9 48 uint32_t fftLen,
simon 0:1014af42efd9 49 q15_t * pATable,
simon 0:1014af42efd9 50 q15_t * pBTable,
simon 0:1014af42efd9 51 q15_t * pDst,
simon 0:1014af42efd9 52 uint32_t modifier);
simon 0:1014af42efd9 53
simon 0:1014af42efd9 54 /**
simon 0:1014af42efd9 55 * @addtogroup RFFT_RIFFT
simon 0:1014af42efd9 56 * @{
simon 0:1014af42efd9 57 */
simon 0:1014af42efd9 58
simon 0:1014af42efd9 59 /**
simon 0:1014af42efd9 60 * @brief Processing function for the Q15 RFFT/RIFFT.
simon 0:1014af42efd9 61 * @param[in] *S points to an instance of the Q15 RFFT/RIFFT structure.
simon 0:1014af42efd9 62 * @param[in] *pSrc points to the input buffer.
simon 0:1014af42efd9 63 * @param[out] *pDst points to the output buffer.
simon 0:1014af42efd9 64 * @return none.
simon 0:1014af42efd9 65 *
simon 0:1014af42efd9 66 * \par Input an output formats:
simon 0:1014af42efd9 67 * \par
simon 0:1014af42efd9 68 * Internally input is downscaled by 2 for every stage to avoid saturations inside CFFT/CIFFT process.
simon 0:1014af42efd9 69 * Hence the output format is different for different RFFT sizes.
simon 0:1014af42efd9 70 * The input and output formats for different RFFT sizes and number of bits to upscale are mentioned in the tables below for RFFT and RIFFT:
simon 0:1014af42efd9 71 * \par
simon 0:1014af42efd9 72 * \image html RFFTQ15.gif "Input and Output Formats for Q15 RFFT"
simon 0:1014af42efd9 73 * \par
simon 0:1014af42efd9 74 * \image html RIFFTQ15.gif "Input and Output Formats for Q15 RIFFT"
simon 0:1014af42efd9 75 */
simon 0:1014af42efd9 76
simon 0:1014af42efd9 77 void arm_rfft_q15(
simon 0:1014af42efd9 78 const arm_rfft_instance_q15 * S,
simon 0:1014af42efd9 79 q15_t * pSrc,
simon 0:1014af42efd9 80 q15_t * pDst)
simon 0:1014af42efd9 81 {
simon 0:1014af42efd9 82 const arm_cfft_radix4_instance_q15 *S_CFFT = S->pCfft;
simon 0:1014af42efd9 83
simon 0:1014af42efd9 84 /* Calculation of RIFFT of input */
simon 0:1014af42efd9 85 if(S->ifftFlagR == 1u)
simon 0:1014af42efd9 86 {
simon 0:1014af42efd9 87 /* Real IFFT core process */
simon 0:1014af42efd9 88 arm_split_rifft_q15(pSrc, S->fftLenBy2, S->pTwiddleAReal,
simon 0:1014af42efd9 89 S->pTwiddleBReal, pDst, S->twidCoefRModifier);
simon 0:1014af42efd9 90
simon 0:1014af42efd9 91 /* Complex readix-4 IFFT process */
simon 0:1014af42efd9 92 arm_radix4_butterfly_inverse_q15(pDst, S_CFFT->fftLen,
simon 0:1014af42efd9 93 S_CFFT->pTwiddle,
simon 0:1014af42efd9 94 S_CFFT->twidCoefModifier);
simon 0:1014af42efd9 95
simon 0:1014af42efd9 96 /* Bit reversal process */
simon 0:1014af42efd9 97 if(S->bitReverseFlagR == 1u)
simon 0:1014af42efd9 98 {
simon 0:1014af42efd9 99 arm_bitreversal_q15(pDst, S_CFFT->fftLen,
simon 0:1014af42efd9 100 S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
simon 0:1014af42efd9 101 }
simon 0:1014af42efd9 102 }
simon 0:1014af42efd9 103 else
simon 0:1014af42efd9 104 {
simon 0:1014af42efd9 105 /* Calculation of RFFT of input */
simon 0:1014af42efd9 106
simon 0:1014af42efd9 107 /* Complex readix-4 FFT process */
simon 0:1014af42efd9 108 arm_radix4_butterfly_q15(pSrc, S_CFFT->fftLen,
simon 0:1014af42efd9 109 S_CFFT->pTwiddle, S_CFFT->twidCoefModifier);
simon 0:1014af42efd9 110
simon 0:1014af42efd9 111 /* Bit reversal process */
simon 0:1014af42efd9 112 if(S->bitReverseFlagR == 1u)
simon 0:1014af42efd9 113 {
simon 0:1014af42efd9 114 arm_bitreversal_q15(pSrc, S_CFFT->fftLen,
simon 0:1014af42efd9 115 S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
simon 0:1014af42efd9 116 }
simon 0:1014af42efd9 117
simon 0:1014af42efd9 118 arm_split_rfft_q15(pSrc, S->fftLenBy2, S->pTwiddleAReal,
simon 0:1014af42efd9 119 S->pTwiddleBReal, pDst, S->twidCoefRModifier);
simon 0:1014af42efd9 120 }
simon 0:1014af42efd9 121
simon 0:1014af42efd9 122 }
simon 0:1014af42efd9 123
simon 0:1014af42efd9 124 /**
simon 0:1014af42efd9 125 * @} end of RFFT_RIFFT group
simon 0:1014af42efd9 126 */
simon 0:1014af42efd9 127
simon 0:1014af42efd9 128 /**
simon 0:1014af42efd9 129 * @brief Core Real FFT process
simon 0:1014af42efd9 130 * @param *pSrc points to the input buffer.
simon 0:1014af42efd9 131 * @param fftLen length of FFT.
simon 0:1014af42efd9 132 * @param *pATable points to the A twiddle Coef buffer.
simon 0:1014af42efd9 133 * @param *pBTable points to the B twiddle Coef buffer.
simon 0:1014af42efd9 134 * @param *pDst points to the output buffer.
simon 0:1014af42efd9 135 * @param modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
simon 0:1014af42efd9 136 * @return none.
simon 0:1014af42efd9 137 * The function implements a Real FFT
simon 0:1014af42efd9 138 */
simon 0:1014af42efd9 139
simon 0:1014af42efd9 140 void arm_split_rfft_q15(
simon 0:1014af42efd9 141 q15_t * pSrc,
simon 0:1014af42efd9 142 uint32_t fftLen,
simon 0:1014af42efd9 143 q15_t * pATable,
simon 0:1014af42efd9 144 q15_t * pBTable,
simon 0:1014af42efd9 145 q15_t * pDst,
simon 0:1014af42efd9 146 uint32_t modifier)
simon 0:1014af42efd9 147 {
simon 0:1014af42efd9 148 uint32_t i; /* Loop Counter */
simon 0:1014af42efd9 149 q31_t outR, outI; /* Temporary variables for output */
simon 0:1014af42efd9 150 q15_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
simon 0:1014af42efd9 151 q15_t *pSrc1, *pSrc2;
simon 0:1014af42efd9 152
simon 0:1014af42efd9 153
simon 0:1014af42efd9 154 pSrc[2u * fftLen] = pSrc[0];
simon 0:1014af42efd9 155 pSrc[(2u * fftLen) + 1u] = pSrc[1];
simon 0:1014af42efd9 156
simon 0:1014af42efd9 157 pCoefA = &pATable[modifier * 2u];
simon 0:1014af42efd9 158 pCoefB = &pBTable[modifier * 2u];
simon 0:1014af42efd9 159
simon 0:1014af42efd9 160 pSrc1 = &pSrc[2];
simon 0:1014af42efd9 161 pSrc2 = &pSrc[(2u * fftLen) - 2u];
simon 0:1014af42efd9 162
simon 0:1014af42efd9 163 i = 1u;
simon 0:1014af42efd9 164
simon 0:1014af42efd9 165 while(i < fftLen)
simon 0:1014af42efd9 166 {
simon 0:1014af42efd9 167 /*
simon 0:1014af42efd9 168 outR = (pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1]
simon 0:1014af42efd9 169 + pSrc[2 * n - 2 * i] * pBTable[2 * i] +
simon 0:1014af42efd9 170 pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
simon 0:1014af42efd9 171 */
simon 0:1014af42efd9 172
simon 0:1014af42efd9 173 /* outI = (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] +
simon 0:1014af42efd9 174 pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
simon 0:1014af42efd9 175 pIn[2 * n - 2 * i + 1] * pBTable[2 * i]); */
simon 0:1014af42efd9 176
simon 0:1014af42efd9 177 /* pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1] */
simon 0:1014af42efd9 178 outR = __SMUSD(*__SIMD32(pSrc1), *__SIMD32(pCoefA));
simon 0:1014af42efd9 179
simon 0:1014af42efd9 180 /* pSrc[2 * n - 2 * i] * pBTable[2 * i] +
simon 0:1014af42efd9 181 pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]) */
simon 0:1014af42efd9 182 outR = __SMLAD(*__SIMD32(pSrc2), *__SIMD32(pCoefB), outR) >> 15u;
simon 0:1014af42efd9 183
simon 0:1014af42efd9 184 /* pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
simon 0:1014af42efd9 185 pIn[2 * n - 2 * i + 1] * pBTable[2 * i] */
simon 0:1014af42efd9 186 outI = __SMUSDX(*__SIMD32(pSrc2)--, *__SIMD32(pCoefB));
simon 0:1014af42efd9 187
simon 0:1014af42efd9 188 /* (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] */
simon 0:1014af42efd9 189 outI = __SMLADX(*__SIMD32(pSrc1)++, *__SIMD32(pCoefA), outI);
simon 0:1014af42efd9 190
simon 0:1014af42efd9 191 /* write output */
simon 0:1014af42efd9 192 pDst[2u * i] = (q15_t) outR;
simon 0:1014af42efd9 193 pDst[(2u * i) + 1u] = outI >> 15u;
simon 0:1014af42efd9 194
simon 0:1014af42efd9 195 /* write complex conjugate output */
simon 0:1014af42efd9 196 pDst[(4u * fftLen) - (2u * i)] = (q15_t) outR;
simon 0:1014af42efd9 197 pDst[((4u * fftLen) - (2u * i)) + 1u] = -(outI >> 15u);
simon 0:1014af42efd9 198
simon 0:1014af42efd9 199 /* update coefficient pointer */
simon 0:1014af42efd9 200 pCoefB = pCoefB + (2u * modifier);
simon 0:1014af42efd9 201 pCoefA = pCoefA + (2u * modifier);
simon 0:1014af42efd9 202
simon 0:1014af42efd9 203 i++;
simon 0:1014af42efd9 204
simon 0:1014af42efd9 205 }
simon 0:1014af42efd9 206
simon 0:1014af42efd9 207 pDst[2u * fftLen] = pSrc[0] - pSrc[1];
simon 0:1014af42efd9 208 pDst[(2u * fftLen) + 1u] = 0;
simon 0:1014af42efd9 209
simon 0:1014af42efd9 210 pDst[0] = pSrc[0] + pSrc[1];
simon 0:1014af42efd9 211 pDst[1] = 0;
simon 0:1014af42efd9 212
simon 0:1014af42efd9 213 }
simon 0:1014af42efd9 214
simon 0:1014af42efd9 215
simon 0:1014af42efd9 216 /**
simon 0:1014af42efd9 217 * @brief Core Real IFFT process
simon 0:1014af42efd9 218 * @param[in] *pSrc points to the input buffer.
simon 0:1014af42efd9 219 * @param[in] fftLen length of FFT.
simon 0:1014af42efd9 220 * @param[in] *pATable points to the twiddle Coef A buffer.
simon 0:1014af42efd9 221 * @param[in] *pBTable points to the twiddle Coef B buffer.
simon 0:1014af42efd9 222 * @param[out] *pDst points to the output buffer.
simon 0:1014af42efd9 223 * @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
simon 0:1014af42efd9 224 * @return none.
simon 0:1014af42efd9 225 * The function implements a Real IFFT
simon 0:1014af42efd9 226 */
simon 0:1014af42efd9 227
simon 0:1014af42efd9 228 void arm_split_rifft_q15(
simon 0:1014af42efd9 229 q15_t * pSrc,
simon 0:1014af42efd9 230 uint32_t fftLen,
simon 0:1014af42efd9 231 q15_t * pATable,
simon 0:1014af42efd9 232 q15_t * pBTable,
simon 0:1014af42efd9 233 q15_t * pDst,
simon 0:1014af42efd9 234 uint32_t modifier)
simon 0:1014af42efd9 235 {
simon 0:1014af42efd9 236 uint32_t i; /* Loop Counter */
simon 0:1014af42efd9 237 q31_t outR, outI; /* Temporary variables for output */
simon 0:1014af42efd9 238 q15_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
simon 0:1014af42efd9 239 q15_t *pSrc1, *pSrc2;
simon 0:1014af42efd9 240 q15_t *pDst1 = &pDst[0];
simon 0:1014af42efd9 241
simon 0:1014af42efd9 242 pCoefA = &pATable[0];
simon 0:1014af42efd9 243 pCoefB = &pBTable[0];
simon 0:1014af42efd9 244
simon 0:1014af42efd9 245 pSrc1 = &pSrc[0];
simon 0:1014af42efd9 246 pSrc2 = &pSrc[2u * fftLen];
simon 0:1014af42efd9 247
simon 0:1014af42efd9 248 i = fftLen;
simon 0:1014af42efd9 249
simon 0:1014af42efd9 250 while(i > 0u)
simon 0:1014af42efd9 251 {
simon 0:1014af42efd9 252
simon 0:1014af42efd9 253 /*
simon 0:1014af42efd9 254 outR = (pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
simon 0:1014af42efd9 255 pIn[2 * n - 2 * i] * pBTable[2 * i] -
simon 0:1014af42efd9 256 pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
simon 0:1014af42efd9 257
simon 0:1014af42efd9 258 outI = (pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] -
simon 0:1014af42efd9 259 pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
simon 0:1014af42efd9 260 pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
simon 0:1014af42efd9 261
simon 0:1014af42efd9 262 */
simon 0:1014af42efd9 263
simon 0:1014af42efd9 264 /* pIn[2 * n - 2 * i] * pBTable[2 * i] -
simon 0:1014af42efd9 265 pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]) */
simon 0:1014af42efd9 266 outR = __SMUSD(*__SIMD32(pSrc2), *__SIMD32(pCoefB));
simon 0:1014af42efd9 267
simon 0:1014af42efd9 268 /* pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
simon 0:1014af42efd9 269 pIn[2 * n - 2 * i] * pBTable[2 * i] */
simon 0:1014af42efd9 270 outR = __SMLAD(*__SIMD32(pSrc1), *__SIMD32(pCoefA), outR) >> 15u;
simon 0:1014af42efd9 271
simon 0:1014af42efd9 272 /*
simon 0:1014af42efd9 273 -pIn[2 * n - 2 * i] * pBTable[2 * i + 1] +
simon 0:1014af42efd9 274 pIn[2 * n - 2 * i + 1] * pBTable[2 * i] */
simon 0:1014af42efd9 275 outI = __SMUADX(*__SIMD32(pSrc2)--, *__SIMD32(pCoefB));
simon 0:1014af42efd9 276
simon 0:1014af42efd9 277 /* pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] */
simon 0:1014af42efd9 278 outI = __SMLSDX(*__SIMD32(pCoefA), *__SIMD32(pSrc1)++, -outI);
simon 0:1014af42efd9 279
simon 0:1014af42efd9 280 /* write output */
simon 0:1014af42efd9 281 *__SIMD32(pDst1)++ =
simon 0:1014af42efd9 282 (q31_t) ((outI << 1u) & 0xFFFF0000) | (outR & 0x0000FFFF);
simon 0:1014af42efd9 283
simon 0:1014af42efd9 284 /* update coefficient pointer */
simon 0:1014af42efd9 285 pCoefB = pCoefB + (2u * modifier);
simon 0:1014af42efd9 286 pCoefA = pCoefA + (2u * modifier);
simon 0:1014af42efd9 287
simon 0:1014af42efd9 288 i--;
simon 0:1014af42efd9 289
simon 0:1014af42efd9 290 }
simon 0:1014af42efd9 291
simon 0:1014af42efd9 292 }