Subversion Repositories LedShow

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------    
2
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.    
3
*    
4
* $Date:        19. March 2015
5
* $Revision:    V.1.4.5  
6
*    
7
* Project:          CMSIS DSP Library    
8
* Title:            arm_rfft_init_q15.c    
9
*    
10
* Description:  RFFT & RIFFT Q15 initialisation function    
11
*    
12
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13
*  
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions
16
* are met:
17
*   - Redistributions of source code must retain the above copyright
18
*     notice, this list of conditions and the following disclaimer.
19
*   - Redistributions in binary form must reproduce the above copyright
20
*     notice, this list of conditions and the following disclaimer in
21
*     the documentation and/or other materials provided with the
22
*     distribution.
23
*   - Neither the name of ARM LIMITED nor the names of its contributors
24
*     may be used to endorse or promote products derived from this
25
*     software without specific prior written permission.
26
*
27
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
* POSSIBILITY OF SUCH DAMAGE.  
39
* -------------------------------------------------------------------- */
40
 
41
 
42
#include "arm_math.h"
43
#include "arm_common_tables.h"
44
#include "arm_const_structs.h"
45
 
46
/**    
47
* @ingroup groupTransforms    
48
*/
49
 
50
/**    
51
* @addtogroup RealFFT    
52
* @{    
53
*/
54
 
55
 
56
 
57
/**    
58
* \par    
59
* Generation fixed-point realCoefAQ15 array in Q15 format:    
60
* \par    
61
* n = 4096    
62
* <pre>for (i = 0; i < n; i++)    
63
*  {    
64
*    pATable[2 * i] = 0.5 * (1.0 - sin (2 * PI / (double) (2 * n) * (double) i));    
65
*    pATable[2 * i + 1] = 0.5 * (-1.0 * cos (2 * PI / (double) (2 * n) * (double) i));    
66
*  } </pre>    
67
* \par    
68
* Convert to fixed point Q15 format    
69
*       round(pATable[i] * pow(2, 15))    
70
*//**    
71
* \par  
72
* Generation of real_CoefB array:    
73
* \par    
74
* n = 4096    
75
* <pre>for (i = 0; i < n; i++)    
76
*  {    
77
*    pBTable[2 * i] = 0.5 * (1.0 + sin (2 * PI / (double) (2 * n) * (double) i));    
78
*    pBTable[2 * i + 1] = 0.5 * (1.0 * cos (2 * PI / (double) (2 * n) * (double) i));    
79
*  } </pre>  
80
* \par    
81
* Convert to fixed point Q15 format    
82
*       round(pBTable[i] * pow(2, 15))    
83
*    
84
*//**    
85
* @brief  Initialization function for the Q15 RFFT/RIFFT.  
86
* @param[in, out] *S             points to an instance of the Q15 RFFT/RIFFT structure.  
87
* @param[in]      fftLenReal     length of the FFT.  
88
* @param[in]      ifftFlagR      flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform.  
89
* @param[in]      bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.  
90
* @return               The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported value.  
91
*    
92
* \par Description:  
93
* \par  
94
* The parameter <code>fftLenReal</code> Specifies length of RFFT/RIFFT Process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.    
95
* \par    
96
* The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.    
97
* Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.    
98
* \par    
99
* The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.    
100
* Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.  
101
* \par    
102
* This function also initializes Twiddle factor table.    
103
*/
104
arm_status arm_rfft_init_q15(
105
    arm_rfft_instance_q15 * S,
106
    uint32_t fftLenReal,
107
    uint32_t ifftFlagR,
108
    uint32_t bitReverseFlag)
109
{
110
    /*  Initialise the default arm status */
111
    arm_status status = ARM_MATH_SUCCESS;
112
113
    /*  Initialize the Real FFT length */
114
    S->fftLenReal = (uint16_t) fftLenReal;
115
116
    /*  Initialize the Twiddle coefficientA pointer */
117
    S->pTwiddleAReal = (q15_t *) realCoefAQ15;
118
119
    /*  Initialize the Twiddle coefficientB pointer */
120
    S->pTwiddleBReal = (q15_t *) realCoefBQ15;
121
122
    /*  Initialize the Flag for selection of RFFT or RIFFT */
123
    S->ifftFlagR = (uint8_t) ifftFlagR;
124
125
    /*  Initialize the Flag for calculation Bit reversal or not */
126
    S->bitReverseFlagR = (uint8_t) bitReverseFlag;
127
128
    /*  Initialization of coef modifier depending on the FFT length */
129
    switch (S->fftLenReal)
130
    {
131
    case 8192u:
132
        S->twidCoefRModifier = 1u;
133
        S->pCfft = &arm_cfft_sR_q15_len4096;
134
        break;
135
    case 4096u:
136
        S->twidCoefRModifier = 2u;
137
        S->pCfft = &arm_cfft_sR_q15_len2048;
138
        break;
139
    case 2048u:
140
        S->twidCoefRModifier = 4u;
141
        S->pCfft = &arm_cfft_sR_q15_len1024;
142
        break;
143
    case 1024u:
144
        S->twidCoefRModifier = 8u;
145
        S->pCfft = &arm_cfft_sR_q15_len512;
146
        break;
147
    case 512u:
148
        S->twidCoefRModifier = 16u;
149
        S->pCfft = &arm_cfft_sR_q15_len256;
150
        break;
151
    case 256u:
152
        S->twidCoefRModifier = 32u;
153
        S->pCfft = &arm_cfft_sR_q15_len128;
154
        break;
155
    case 128u:
156
        S->twidCoefRModifier = 64u;
157
        S->pCfft = &arm_cfft_sR_q15_len64;
158
        break;
159
    case 64u:
160
        S->twidCoefRModifier = 128u;
161
        S->pCfft = &arm_cfft_sR_q15_len32;
162
        break;
163
    case 32u:
164
        S->twidCoefRModifier = 256u;
165
        S->pCfft = &arm_cfft_sR_q15_len16;
166
        break;
167
    default:
168
        /*  Reporting argument error if rfftSize is not valid value */
169
        status = ARM_MATH_ARGUMENT_ERROR;
170
        break;
171
    }
172
173
    /* return the status of RFFT Init function */
174
    return (status);
175
}
176
177
/**    
178
* @} end of RealFFT group    
179
*/
180
 
181