V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.

Dependents:   MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_rfft_q31.c Source File

arm_rfft_q31.c

00001 /* ----------------------------------------------------------------------    
00002 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.    
00003 *    
00004 * $Date:        12. March 2014  
00005 * $Revision:    V1.4.3  
00006 *    
00007 * Project:      CMSIS DSP Library    
00008 * Title:        arm_rfft_q31.c    
00009 *    
00010 * Description:  RFFT & RIFFT Q31 process function    
00011 *    
00012 *    
00013 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
00014 *  
00015 * Redistribution and use in source and binary forms, with or without 
00016 * modification, are permitted provided that the following conditions
00017 * are met:
00018 *   - Redistributions of source code must retain the above copyright
00019 *     notice, this list of conditions and the following disclaimer.
00020 *   - Redistributions in binary form must reproduce the above copyright
00021 *     notice, this list of conditions and the following disclaimer in
00022 *     the documentation and/or other materials provided with the 
00023 *     distribution.
00024 *   - Neither the name of ARM LIMITED nor the names of its contributors
00025 *     may be used to endorse or promote products derived from this
00026 *     software without specific prior written permission.
00027 *
00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00031 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
00032 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00033 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00034 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00036 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00037 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00038 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00039 * POSSIBILITY OF SUCH DAMAGE.    
00040 * -------------------------------------------------------------------- */
00041 
00042 #include "arm_math.h"
00043 
00044 void arm_radix4_butterfly_inverse_q31(
00045 q31_t * pSrc,
00046 uint32_t fftLen,
00047 q31_t * pCoef,
00048 uint32_t twidCoefModifier);
00049 
00050 void arm_radix4_butterfly_q31(
00051 q31_t * pSrc,
00052 uint32_t fftLen,
00053 q31_t * pCoef,
00054 uint32_t twidCoefModifier);
00055 
00056 void arm_bitreversal_q31(
00057 q31_t * pSrc,
00058 uint32_t fftLen,
00059 uint16_t bitRevFactor,
00060 uint16_t * pBitRevTab);
00061 
00062 /*--------------------------------------------------------------------    
00063 *       Internal functions prototypes    
00064 --------------------------------------------------------------------*/
00065 
00066 void arm_split_rfft_q31(
00067   q31_t * pSrc,
00068   uint32_t fftLen,
00069   q31_t * pATable,
00070   q31_t * pBTable,
00071   q31_t * pDst,
00072   uint32_t modifier);
00073 
00074 void arm_split_rifft_q31(
00075   q31_t * pSrc,
00076   uint32_t fftLen,
00077   q31_t * pATable,
00078   q31_t * pBTable,
00079   q31_t * pDst,
00080   uint32_t modifier);
00081 
00082 /**    
00083  * @addtogroup RealFFT    
00084  * @{    
00085  */
00086 
00087 /**    
00088  * @brief Processing function for the Q31 RFFT/RIFFT.   
00089  * @param[in]  *S    points to an instance of the Q31 RFFT/RIFFT structure.   
00090  * @param[in]  *pSrc points to the input buffer.   
00091  * @param[out] *pDst points to the output buffer.   
00092  * @return none.   
00093  *    
00094  * \par Input an output formats:   
00095  * \par    
00096  * Internally input is downscaled by 2 for every stage to avoid saturations inside CFFT/CIFFT process.   
00097  * Hence the output format is different for different RFFT sizes.    
00098  * 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:   
00099  * \par    
00100  * \image html RFFTQ31.gif "Input and Output Formats for Q31 RFFT"    
00101  *    
00102  * \par    
00103  * \image html RIFFTQ31.gif "Input and Output Formats for Q31 RIFFT"    
00104  */
00105 
00106 void arm_rfft_q31(
00107   const arm_rfft_instance_q31 * S,
00108   q31_t * pSrc,
00109   q31_t * pDst)
00110 {
00111   const arm_cfft_radix4_instance_q31 *S_CFFT = S->pCfft;
00112   uint32_t i;
00113 
00114   /* Calculation of RIFFT of input */
00115   if(S->ifftFlagR == 1u)
00116   {
00117     /*  Real IFFT core process */
00118     arm_split_rifft_q31(pSrc, S->fftLenBy2, S->pTwiddleAReal,
00119                         S->pTwiddleBReal, pDst, S->twidCoefRModifier);
00120 
00121     /* Complex readix-4 IFFT process */
00122     arm_radix4_butterfly_inverse_q31(pDst, S_CFFT->fftLen,
00123                                      S_CFFT->pTwiddle,
00124                                      S_CFFT->twidCoefModifier);
00125     /* Bit reversal process */
00126     if(S->bitReverseFlagR == 1u)
00127     {
00128       arm_bitreversal_q31(pDst, S_CFFT->fftLen,
00129                           S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
00130     }
00131     
00132     for(i=0;i<S->fftLenReal;i++)
00133     {
00134       pDst[i] = pDst[i] << 1;
00135     }
00136   }
00137   else
00138   {
00139     /* Calculation of RFFT of input */
00140 
00141     /* Complex readix-4 FFT process */
00142     arm_radix4_butterfly_q31(pSrc, S_CFFT->fftLen,
00143                              S_CFFT->pTwiddle, S_CFFT->twidCoefModifier);
00144 
00145     /* Bit reversal process */
00146     if(S->bitReverseFlagR == 1u)
00147     {
00148       arm_bitreversal_q31(pSrc, S_CFFT->fftLen,
00149                           S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
00150     }
00151 
00152     /*  Real FFT core process */
00153     arm_split_rfft_q31(pSrc, S->fftLenBy2, S->pTwiddleAReal,
00154                        S->pTwiddleBReal, pDst, S->twidCoefRModifier);
00155   }
00156 
00157 }
00158 
00159 
00160   /**    
00161    * @} end of RealFFT group    
00162    */
00163 
00164 /**    
00165  * @brief  Core Real FFT process    
00166  * @param[in]   *pSrc               points to the input buffer.    
00167  * @param[in]   fftLen              length of FFT.   
00168  * @param[in]   *pATable            points to the twiddle Coef A buffer.    
00169  * @param[in]   *pBTable            points to the twiddle Coef B buffer.    
00170  * @param[out]  *pDst               points to the output buffer.    
00171  * @param[in]   modifier            twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.   
00172  * @return none.    
00173  */
00174 
00175 void arm_split_rfft_q31(
00176   q31_t * pSrc,
00177   uint32_t fftLen,
00178   q31_t * pATable,
00179   q31_t * pBTable,
00180   q31_t * pDst,
00181   uint32_t modifier)
00182 {
00183   uint32_t i;                                    /* Loop Counter */
00184   q31_t outR, outI;                              /* Temporary variables for output */
00185   q31_t *pCoefA, *pCoefB;                        /* Temporary pointers for twiddle factors */
00186   q31_t CoefA1, CoefA2, CoefB1;                  /* Temporary variables for twiddle coefficients */
00187   q31_t *pOut1 = &pDst[2], *pOut2 = &pDst[(4u * fftLen) - 1u];
00188   q31_t *pIn1 = &pSrc[2], *pIn2 = &pSrc[(2u * fftLen) - 1u];
00189 
00190   /* Init coefficient pointers */
00191   pCoefA = &pATable[modifier * 2u];
00192   pCoefB = &pBTable[modifier * 2u];
00193 
00194   i = fftLen - 1u;
00195 
00196   while(i > 0u)
00197   {
00198     /*    
00199        outR = (pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1]    
00200        + pSrc[2 * n - 2 * i] * pBTable[2 * i] +    
00201        pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);    
00202      */
00203 
00204     /* outI = (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] +    
00205        pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -    
00206        pIn[2 * n - 2 * i + 1] * pBTable[2 * i]); */
00207 
00208     CoefA1 = *pCoefA++;
00209     CoefA2 = *pCoefA;
00210 
00211     /* outR = (pSrc[2 * i] * pATable[2 * i] */
00212     outR = ((int32_t) (((q63_t) * pIn1 * CoefA1) >> 32));
00213 
00214     /* outI = pIn[2 * i] * pATable[2 * i + 1] */
00215     outI = ((int32_t) (((q63_t) * pIn1++ * CoefA2) >> 32));
00216 
00217     /* - pSrc[2 * i + 1] * pATable[2 * i + 1] */
00218     outR =
00219       (q31_t) ((((q63_t) outR << 32) + ((q63_t) * pIn1 * (-CoefA2))) >> 32);
00220 
00221     /* (pIn[2 * i + 1] * pATable[2 * i] */
00222     outI =
00223       (q31_t) ((((q63_t) outI << 32) + ((q63_t) * pIn1++ * (CoefA1))) >> 32);
00224 
00225     /* pSrc[2 * n - 2 * i] * pBTable[2 * i]  */
00226     outR =
00227       (q31_t) ((((q63_t) outR << 32) + ((q63_t) * pIn2 * (-CoefA2))) >> 32);
00228     CoefB1 = *pCoefB;
00229 
00230     /* pIn[2 * n - 2 * i] * pBTable[2 * i + 1] */
00231     outI =
00232       (q31_t) ((((q63_t) outI << 32) + ((q63_t) * pIn2-- * (-CoefB1))) >> 32);
00233 
00234     /* pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1] */
00235     outR =
00236       (q31_t) ((((q63_t) outR << 32) + ((q63_t) * pIn2 * (CoefB1))) >> 32);
00237 
00238     /* pIn[2 * n - 2 * i + 1] * pBTable[2 * i] */
00239     outI =
00240       (q31_t) ((((q63_t) outI << 32) + ((q63_t) * pIn2-- * (-CoefA2))) >> 32);
00241 
00242     /* write output */
00243     *pOut1++ = outR;
00244     *pOut1++ = outI;
00245 
00246     /* write complex conjugate output */
00247     *pOut2-- = -outI;
00248     *pOut2-- = outR;
00249 
00250     /* update coefficient pointer */
00251     pCoefB = pCoefB + (modifier * 2u);
00252     pCoefA = pCoefA + ((modifier * 2u) - 1u);
00253 
00254     i--;
00255 
00256   }
00257 
00258   pDst[2u * fftLen] = (pSrc[0] - pSrc[1]) >> 1;
00259   pDst[(2u * fftLen) + 1u] = 0;
00260 
00261   pDst[0] = (pSrc[0] + pSrc[1]) >> 1;
00262   pDst[1] = 0;
00263 
00264 }
00265 
00266 
00267 /**    
00268  * @brief  Core Real IFFT process    
00269  * @param[in]   *pSrc               points to the input buffer.   
00270  * @param[in]   fftLen              length of FFT.    
00271  * @param[in]   *pATable            points to the twiddle Coef A buffer.   
00272  * @param[in]   *pBTable            points to the twiddle Coef B buffer.    
00273  * @param[out]  *pDst               points to the output buffer.   
00274  * @param[in]   modifier            twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.   
00275  * @return none.    
00276  */
00277 
00278 void arm_split_rifft_q31(
00279   q31_t * pSrc,
00280   uint32_t fftLen,
00281   q31_t * pATable,
00282   q31_t * pBTable,
00283   q31_t * pDst,
00284   uint32_t modifier)
00285 {
00286   q31_t outR, outI;                              /* Temporary variables for output */
00287   q31_t *pCoefA, *pCoefB;                        /* Temporary pointers for twiddle factors */
00288   q31_t CoefA1, CoefA2, CoefB1;                  /* Temporary variables for twiddle coefficients */
00289   q31_t *pIn1 = &pSrc[0], *pIn2 = &pSrc[(2u * fftLen) + 1u];
00290 
00291   pCoefA = &pATable[0];
00292   pCoefB = &pBTable[0];
00293 
00294   while(fftLen > 0u)
00295   {
00296     /*    
00297        outR = (pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +    
00298        pIn[2 * n - 2 * i] * pBTable[2 * i] -    
00299        pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);    
00300 
00301        outI = (pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] -    
00302        pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -    
00303        pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);    
00304 
00305      */
00306     CoefA1 = *pCoefA++;
00307     CoefA2 = *pCoefA;
00308 
00309     /* outR = (pIn[2 * i] * pATable[2 * i] */
00310     outR = ((int32_t) (((q63_t) * pIn1 * CoefA1) >> 32));
00311 
00312     /* - pIn[2 * i] * pATable[2 * i + 1] */
00313     outI = -((int32_t) (((q63_t) * pIn1++ * CoefA2) >> 32));
00314 
00315     /* pIn[2 * i + 1] * pATable[2 * i + 1] */
00316     outR =
00317       (q31_t) ((((q63_t) outR << 32) + ((q63_t) * pIn1 * (CoefA2))) >> 32);
00318 
00319     /* pIn[2 * i + 1] * pATable[2 * i] */
00320     outI =
00321       (q31_t) ((((q63_t) outI << 32) + ((q63_t) * pIn1++ * (CoefA1))) >> 32);
00322 
00323     /* pIn[2 * n - 2 * i] * pBTable[2 * i] */
00324     outR =
00325       (q31_t) ((((q63_t) outR << 32) + ((q63_t) * pIn2 * (CoefA2))) >> 32);
00326 
00327     CoefB1 = *pCoefB;
00328 
00329     /* pIn[2 * n - 2 * i] * pBTable[2 * i + 1] */
00330     outI =
00331       (q31_t) ((((q63_t) outI << 32) - ((q63_t) * pIn2-- * (CoefB1))) >> 32);
00332 
00333     /* pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1] */
00334     outR =
00335       (q31_t) ((((q63_t) outR << 32) + ((q63_t) * pIn2 * (CoefB1))) >> 32);
00336 
00337     /* pIn[2 * n - 2 * i + 1] * pBTable[2 * i] */
00338     outI =
00339       (q31_t) ((((q63_t) outI << 32) + ((q63_t) * pIn2-- * (CoefA2))) >> 32);
00340 
00341     /* write output */
00342     *pDst++ = outR;
00343     *pDst++ = outI;
00344 
00345     /* update coefficient pointer */
00346     pCoefB = pCoefB + (modifier * 2u);
00347     pCoefA = pCoefA + ((modifier * 2u) - 1u);
00348 
00349     /* Decrement loop count */
00350     fftLen--;
00351 
00352   }
00353 
00354 
00355 }