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
TransformFunctions/arm_dct4_q15.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- Committer:
- emh203
- Date:
- Mon Jul 28 15:03:15 2014 +0000
- Revision:
- 0:3d9c67d97d6f
1st working commit. Had to remove arm_bitreversal2.s arm_cfft_f32.c and arm_rfft_fast_f32.c. The .s will not assemble. For now I removed these functions so we could at least have a library for the other functions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 0:3d9c67d97d6f | 1 | /* ---------------------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
emh203 | 0:3d9c67d97d6f | 3 | * |
emh203 | 0:3d9c67d97d6f | 4 | * $Date: 12. March 2014 |
emh203 | 0:3d9c67d97d6f | 5 | * $Revision: V1.4.3 |
emh203 | 0:3d9c67d97d6f | 6 | * |
emh203 | 0:3d9c67d97d6f | 7 | * Project: CMSIS DSP Library |
emh203 | 0:3d9c67d97d6f | 8 | * Title: arm_dct4_q15.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Processing function of DCT4 & IDCT4 Q15. |
emh203 | 0:3d9c67d97d6f | 11 | * |
emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emh203 | 0:3d9c67d97d6f | 13 | * |
emh203 | 0:3d9c67d97d6f | 14 | * Redistribution and use in source and binary forms, with or without |
emh203 | 0:3d9c67d97d6f | 15 | * modification, are permitted provided that the following conditions |
emh203 | 0:3d9c67d97d6f | 16 | * are met: |
emh203 | 0:3d9c67d97d6f | 17 | * - Redistributions of source code must retain the above copyright |
emh203 | 0:3d9c67d97d6f | 18 | * notice, this list of conditions and the following disclaimer. |
emh203 | 0:3d9c67d97d6f | 19 | * - Redistributions in binary form must reproduce the above copyright |
emh203 | 0:3d9c67d97d6f | 20 | * notice, this list of conditions and the following disclaimer in |
emh203 | 0:3d9c67d97d6f | 21 | * the documentation and/or other materials provided with the |
emh203 | 0:3d9c67d97d6f | 22 | * distribution. |
emh203 | 0:3d9c67d97d6f | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
emh203 | 0:3d9c67d97d6f | 24 | * may be used to endorse or promote products derived from this |
emh203 | 0:3d9c67d97d6f | 25 | * software without specific prior written permission. |
emh203 | 0:3d9c67d97d6f | 26 | * |
emh203 | 0:3d9c67d97d6f | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
emh203 | 0:3d9c67d97d6f | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
emh203 | 0:3d9c67d97d6f | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
emh203 | 0:3d9c67d97d6f | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
emh203 | 0:3d9c67d97d6f | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
emh203 | 0:3d9c67d97d6f | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
emh203 | 0:3d9c67d97d6f | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
emh203 | 0:3d9c67d97d6f | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
emh203 | 0:3d9c67d97d6f | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
emh203 | 0:3d9c67d97d6f | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
emh203 | 0:3d9c67d97d6f | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
emh203 | 0:3d9c67d97d6f | 38 | * POSSIBILITY OF SUCH DAMAGE. |
emh203 | 0:3d9c67d97d6f | 39 | * -------------------------------------------------------------------- */ |
emh203 | 0:3d9c67d97d6f | 40 | |
emh203 | 0:3d9c67d97d6f | 41 | #include "arm_math.h" |
emh203 | 0:3d9c67d97d6f | 42 | |
emh203 | 0:3d9c67d97d6f | 43 | /** |
emh203 | 0:3d9c67d97d6f | 44 | * @addtogroup DCT4_IDCT4 |
emh203 | 0:3d9c67d97d6f | 45 | * @{ |
emh203 | 0:3d9c67d97d6f | 46 | */ |
emh203 | 0:3d9c67d97d6f | 47 | |
emh203 | 0:3d9c67d97d6f | 48 | /** |
emh203 | 0:3d9c67d97d6f | 49 | * @brief Processing function for the Q15 DCT4/IDCT4. |
emh203 | 0:3d9c67d97d6f | 50 | * @param[in] *S points to an instance of the Q15 DCT4 structure. |
emh203 | 0:3d9c67d97d6f | 51 | * @param[in] *pState points to state buffer. |
emh203 | 0:3d9c67d97d6f | 52 | * @param[in,out] *pInlineBuffer points to the in-place input and output buffer. |
emh203 | 0:3d9c67d97d6f | 53 | * @return none. |
emh203 | 0:3d9c67d97d6f | 54 | * |
emh203 | 0:3d9c67d97d6f | 55 | * \par Input an output formats: |
emh203 | 0:3d9c67d97d6f | 56 | * Internally inputs are downscaled in the RFFT process function to avoid overflows. |
emh203 | 0:3d9c67d97d6f | 57 | * Number of bits downscaled, depends on the size of the transform. |
emh203 | 0:3d9c67d97d6f | 58 | * The input and output formats for different DCT sizes and number of bits to upscale are mentioned in the table below: |
emh203 | 0:3d9c67d97d6f | 59 | * |
emh203 | 0:3d9c67d97d6f | 60 | * \image html dct4FormatsQ15Table.gif |
emh203 | 0:3d9c67d97d6f | 61 | */ |
emh203 | 0:3d9c67d97d6f | 62 | |
emh203 | 0:3d9c67d97d6f | 63 | void arm_dct4_q15( |
emh203 | 0:3d9c67d97d6f | 64 | const arm_dct4_instance_q15 * S, |
emh203 | 0:3d9c67d97d6f | 65 | q15_t * pState, |
emh203 | 0:3d9c67d97d6f | 66 | q15_t * pInlineBuffer) |
emh203 | 0:3d9c67d97d6f | 67 | { |
emh203 | 0:3d9c67d97d6f | 68 | uint32_t i; /* Loop counter */ |
emh203 | 0:3d9c67d97d6f | 69 | q15_t *weights = S->pTwiddle; /* Pointer to the Weights table */ |
emh203 | 0:3d9c67d97d6f | 70 | q15_t *cosFact = S->pCosFactor; /* Pointer to the cos factors table */ |
emh203 | 0:3d9c67d97d6f | 71 | q15_t *pS1, *pS2, *pbuff; /* Temporary pointers for input buffer and pState buffer */ |
emh203 | 0:3d9c67d97d6f | 72 | q15_t in; /* Temporary variable */ |
emh203 | 0:3d9c67d97d6f | 73 | |
emh203 | 0:3d9c67d97d6f | 74 | |
emh203 | 0:3d9c67d97d6f | 75 | /* DCT4 computation involves DCT2 (which is calculated using RFFT) |
emh203 | 0:3d9c67d97d6f | 76 | * along with some pre-processing and post-processing. |
emh203 | 0:3d9c67d97d6f | 77 | * Computational procedure is explained as follows: |
emh203 | 0:3d9c67d97d6f | 78 | * (a) Pre-processing involves multiplying input with cos factor, |
emh203 | 0:3d9c67d97d6f | 79 | * r(n) = 2 * u(n) * cos(pi*(2*n+1)/(4*n)) |
emh203 | 0:3d9c67d97d6f | 80 | * where, |
emh203 | 0:3d9c67d97d6f | 81 | * r(n) -- output of preprocessing |
emh203 | 0:3d9c67d97d6f | 82 | * u(n) -- input to preprocessing(actual Source buffer) |
emh203 | 0:3d9c67d97d6f | 83 | * (b) Calculation of DCT2 using FFT is divided into three steps: |
emh203 | 0:3d9c67d97d6f | 84 | * Step1: Re-ordering of even and odd elements of input. |
emh203 | 0:3d9c67d97d6f | 85 | * Step2: Calculating FFT of the re-ordered input. |
emh203 | 0:3d9c67d97d6f | 86 | * Step3: Taking the real part of the product of FFT output and weights. |
emh203 | 0:3d9c67d97d6f | 87 | * (c) Post-processing - DCT4 can be obtained from DCT2 output using the following equation: |
emh203 | 0:3d9c67d97d6f | 88 | * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0) |
emh203 | 0:3d9c67d97d6f | 89 | * where, |
emh203 | 0:3d9c67d97d6f | 90 | * Y4 -- DCT4 output, Y2 -- DCT2 output |
emh203 | 0:3d9c67d97d6f | 91 | * (d) Multiplying the output with the normalizing factor sqrt(2/N). |
emh203 | 0:3d9c67d97d6f | 92 | */ |
emh203 | 0:3d9c67d97d6f | 93 | |
emh203 | 0:3d9c67d97d6f | 94 | /*-------- Pre-processing ------------*/ |
emh203 | 0:3d9c67d97d6f | 95 | /* Multiplying input with cos factor i.e. r(n) = 2 * x(n) * cos(pi*(2*n+1)/(4*n)) */ |
emh203 | 0:3d9c67d97d6f | 96 | arm_mult_q15(pInlineBuffer, cosFact, pInlineBuffer, S->N); |
emh203 | 0:3d9c67d97d6f | 97 | arm_shift_q15(pInlineBuffer, 1, pInlineBuffer, S->N); |
emh203 | 0:3d9c67d97d6f | 98 | |
emh203 | 0:3d9c67d97d6f | 99 | /* ---------------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 100 | * Step1: Re-ordering of even and odd elements as |
emh203 | 0:3d9c67d97d6f | 101 | * pState[i] = pInlineBuffer[2*i] and |
emh203 | 0:3d9c67d97d6f | 102 | * pState[N-i-1] = pInlineBuffer[2*i+1] where i = 0 to N/2 |
emh203 | 0:3d9c67d97d6f | 103 | ---------------------------------------------------------------------*/ |
emh203 | 0:3d9c67d97d6f | 104 | |
emh203 | 0:3d9c67d97d6f | 105 | /* pS1 initialized to pState */ |
emh203 | 0:3d9c67d97d6f | 106 | pS1 = pState; |
emh203 | 0:3d9c67d97d6f | 107 | |
emh203 | 0:3d9c67d97d6f | 108 | /* pS2 initialized to pState+N-1, so that it points to the end of the state buffer */ |
emh203 | 0:3d9c67d97d6f | 109 | pS2 = pState + (S->N - 1u); |
emh203 | 0:3d9c67d97d6f | 110 | |
emh203 | 0:3d9c67d97d6f | 111 | /* pbuff initialized to input buffer */ |
emh203 | 0:3d9c67d97d6f | 112 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 113 | |
emh203 | 0:3d9c67d97d6f | 114 | |
emh203 | 0:3d9c67d97d6f | 115 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 116 | |
emh203 | 0:3d9c67d97d6f | 117 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 118 | |
emh203 | 0:3d9c67d97d6f | 119 | /* Initializing the loop counter to N/2 >> 2 for loop unrolling by 4 */ |
emh203 | 0:3d9c67d97d6f | 120 | i = (uint32_t) S->Nby2 >> 2u; |
emh203 | 0:3d9c67d97d6f | 121 | |
emh203 | 0:3d9c67d97d6f | 122 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
emh203 | 0:3d9c67d97d6f | 123 | ** a second loop below computes the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 124 | do |
emh203 | 0:3d9c67d97d6f | 125 | { |
emh203 | 0:3d9c67d97d6f | 126 | /* Re-ordering of even and odd elements */ |
emh203 | 0:3d9c67d97d6f | 127 | /* pState[i] = pInlineBuffer[2*i] */ |
emh203 | 0:3d9c67d97d6f | 128 | *pS1++ = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 129 | /* pState[N-i-1] = pInlineBuffer[2*i+1] */ |
emh203 | 0:3d9c67d97d6f | 130 | *pS2-- = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 131 | |
emh203 | 0:3d9c67d97d6f | 132 | *pS1++ = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 133 | *pS2-- = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 134 | |
emh203 | 0:3d9c67d97d6f | 135 | *pS1++ = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 136 | *pS2-- = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 137 | |
emh203 | 0:3d9c67d97d6f | 138 | *pS1++ = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 139 | *pS2-- = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 140 | |
emh203 | 0:3d9c67d97d6f | 141 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 142 | i--; |
emh203 | 0:3d9c67d97d6f | 143 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 144 | |
emh203 | 0:3d9c67d97d6f | 145 | /* pbuff initialized to input buffer */ |
emh203 | 0:3d9c67d97d6f | 146 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 147 | |
emh203 | 0:3d9c67d97d6f | 148 | /* pS1 initialized to pState */ |
emh203 | 0:3d9c67d97d6f | 149 | pS1 = pState; |
emh203 | 0:3d9c67d97d6f | 150 | |
emh203 | 0:3d9c67d97d6f | 151 | /* Initializing the loop counter to N/4 instead of N for loop unrolling */ |
emh203 | 0:3d9c67d97d6f | 152 | i = (uint32_t) S->N >> 2u; |
emh203 | 0:3d9c67d97d6f | 153 | |
emh203 | 0:3d9c67d97d6f | 154 | /* Processing with loop unrolling 4 times as N is always multiple of 4. |
emh203 | 0:3d9c67d97d6f | 155 | * Compute 4 outputs at a time */ |
emh203 | 0:3d9c67d97d6f | 156 | do |
emh203 | 0:3d9c67d97d6f | 157 | { |
emh203 | 0:3d9c67d97d6f | 158 | /* Writing the re-ordered output back to inplace input buffer */ |
emh203 | 0:3d9c67d97d6f | 159 | *pbuff++ = *pS1++; |
emh203 | 0:3d9c67d97d6f | 160 | *pbuff++ = *pS1++; |
emh203 | 0:3d9c67d97d6f | 161 | *pbuff++ = *pS1++; |
emh203 | 0:3d9c67d97d6f | 162 | *pbuff++ = *pS1++; |
emh203 | 0:3d9c67d97d6f | 163 | |
emh203 | 0:3d9c67d97d6f | 164 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 165 | i--; |
emh203 | 0:3d9c67d97d6f | 166 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 167 | |
emh203 | 0:3d9c67d97d6f | 168 | |
emh203 | 0:3d9c67d97d6f | 169 | /* --------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 170 | * Step2: Calculate RFFT for N-point input |
emh203 | 0:3d9c67d97d6f | 171 | * ---------------------------------------------------------- */ |
emh203 | 0:3d9c67d97d6f | 172 | /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */ |
emh203 | 0:3d9c67d97d6f | 173 | arm_rfft_q15(S->pRfft, pInlineBuffer, pState); |
emh203 | 0:3d9c67d97d6f | 174 | |
emh203 | 0:3d9c67d97d6f | 175 | /*---------------------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 176 | * Step3: Multiply the FFT output with the weights. |
emh203 | 0:3d9c67d97d6f | 177 | *----------------------------------------------------------------------*/ |
emh203 | 0:3d9c67d97d6f | 178 | arm_cmplx_mult_cmplx_q15(pState, weights, pState, S->N); |
emh203 | 0:3d9c67d97d6f | 179 | |
emh203 | 0:3d9c67d97d6f | 180 | /* The output of complex multiplication is in 3.13 format. |
emh203 | 0:3d9c67d97d6f | 181 | * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.15 format by shifting left by 2 bits. */ |
emh203 | 0:3d9c67d97d6f | 182 | arm_shift_q15(pState, 2, pState, S->N * 2); |
emh203 | 0:3d9c67d97d6f | 183 | |
emh203 | 0:3d9c67d97d6f | 184 | /* ----------- Post-processing ---------- */ |
emh203 | 0:3d9c67d97d6f | 185 | /* DCT-IV can be obtained from DCT-II by the equation, |
emh203 | 0:3d9c67d97d6f | 186 | * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0) |
emh203 | 0:3d9c67d97d6f | 187 | * Hence, Y4(0) = Y2(0)/2 */ |
emh203 | 0:3d9c67d97d6f | 188 | /* Getting only real part from the output and Converting to DCT-IV */ |
emh203 | 0:3d9c67d97d6f | 189 | |
emh203 | 0:3d9c67d97d6f | 190 | /* Initializing the loop counter to N >> 2 for loop unrolling by 4 */ |
emh203 | 0:3d9c67d97d6f | 191 | i = ((uint32_t) S->N - 1u) >> 2u; |
emh203 | 0:3d9c67d97d6f | 192 | |
emh203 | 0:3d9c67d97d6f | 193 | /* pbuff initialized to input buffer. */ |
emh203 | 0:3d9c67d97d6f | 194 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 195 | |
emh203 | 0:3d9c67d97d6f | 196 | /* pS1 initialized to pState */ |
emh203 | 0:3d9c67d97d6f | 197 | pS1 = pState; |
emh203 | 0:3d9c67d97d6f | 198 | |
emh203 | 0:3d9c67d97d6f | 199 | /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */ |
emh203 | 0:3d9c67d97d6f | 200 | in = *pS1++ >> 1u; |
emh203 | 0:3d9c67d97d6f | 201 | /* input buffer acts as inplace, so output values are stored in the input itself. */ |
emh203 | 0:3d9c67d97d6f | 202 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 203 | |
emh203 | 0:3d9c67d97d6f | 204 | /* pState pointer is incremented twice as the real values are located alternatively in the array */ |
emh203 | 0:3d9c67d97d6f | 205 | pS1++; |
emh203 | 0:3d9c67d97d6f | 206 | |
emh203 | 0:3d9c67d97d6f | 207 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
emh203 | 0:3d9c67d97d6f | 208 | ** a second loop below computes the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 209 | do |
emh203 | 0:3d9c67d97d6f | 210 | { |
emh203 | 0:3d9c67d97d6f | 211 | /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */ |
emh203 | 0:3d9c67d97d6f | 212 | /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */ |
emh203 | 0:3d9c67d97d6f | 213 | in = *pS1++ - in; |
emh203 | 0:3d9c67d97d6f | 214 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 215 | /* points to the next real value */ |
emh203 | 0:3d9c67d97d6f | 216 | pS1++; |
emh203 | 0:3d9c67d97d6f | 217 | |
emh203 | 0:3d9c67d97d6f | 218 | in = *pS1++ - in; |
emh203 | 0:3d9c67d97d6f | 219 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 220 | pS1++; |
emh203 | 0:3d9c67d97d6f | 221 | |
emh203 | 0:3d9c67d97d6f | 222 | in = *pS1++ - in; |
emh203 | 0:3d9c67d97d6f | 223 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 224 | pS1++; |
emh203 | 0:3d9c67d97d6f | 225 | |
emh203 | 0:3d9c67d97d6f | 226 | in = *pS1++ - in; |
emh203 | 0:3d9c67d97d6f | 227 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 228 | pS1++; |
emh203 | 0:3d9c67d97d6f | 229 | |
emh203 | 0:3d9c67d97d6f | 230 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 231 | i--; |
emh203 | 0:3d9c67d97d6f | 232 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 235 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 236 | i = ((uint32_t) S->N - 1u) % 0x4u; |
emh203 | 0:3d9c67d97d6f | 237 | |
emh203 | 0:3d9c67d97d6f | 238 | while(i > 0u) |
emh203 | 0:3d9c67d97d6f | 239 | { |
emh203 | 0:3d9c67d97d6f | 240 | /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */ |
emh203 | 0:3d9c67d97d6f | 241 | /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */ |
emh203 | 0:3d9c67d97d6f | 242 | in = *pS1++ - in; |
emh203 | 0:3d9c67d97d6f | 243 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 244 | /* points to the next real value */ |
emh203 | 0:3d9c67d97d6f | 245 | pS1++; |
emh203 | 0:3d9c67d97d6f | 246 | |
emh203 | 0:3d9c67d97d6f | 247 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 248 | i--; |
emh203 | 0:3d9c67d97d6f | 249 | } |
emh203 | 0:3d9c67d97d6f | 250 | |
emh203 | 0:3d9c67d97d6f | 251 | |
emh203 | 0:3d9c67d97d6f | 252 | /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/ |
emh203 | 0:3d9c67d97d6f | 253 | |
emh203 | 0:3d9c67d97d6f | 254 | /* Initializing the loop counter to N/4 instead of N for loop unrolling */ |
emh203 | 0:3d9c67d97d6f | 255 | i = (uint32_t) S->N >> 2u; |
emh203 | 0:3d9c67d97d6f | 256 | |
emh203 | 0:3d9c67d97d6f | 257 | /* pbuff initialized to the pInlineBuffer(now contains the output values) */ |
emh203 | 0:3d9c67d97d6f | 258 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 259 | |
emh203 | 0:3d9c67d97d6f | 260 | /* Processing with loop unrolling 4 times as N is always multiple of 4. Compute 4 outputs at a time */ |
emh203 | 0:3d9c67d97d6f | 261 | do |
emh203 | 0:3d9c67d97d6f | 262 | { |
emh203 | 0:3d9c67d97d6f | 263 | /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */ |
emh203 | 0:3d9c67d97d6f | 264 | in = *pbuff; |
emh203 | 0:3d9c67d97d6f | 265 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emh203 | 0:3d9c67d97d6f | 266 | |
emh203 | 0:3d9c67d97d6f | 267 | in = *pbuff; |
emh203 | 0:3d9c67d97d6f | 268 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emh203 | 0:3d9c67d97d6f | 269 | |
emh203 | 0:3d9c67d97d6f | 270 | in = *pbuff; |
emh203 | 0:3d9c67d97d6f | 271 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emh203 | 0:3d9c67d97d6f | 272 | |
emh203 | 0:3d9c67d97d6f | 273 | in = *pbuff; |
emh203 | 0:3d9c67d97d6f | 274 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emh203 | 0:3d9c67d97d6f | 275 | |
emh203 | 0:3d9c67d97d6f | 276 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 277 | i--; |
emh203 | 0:3d9c67d97d6f | 278 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 279 | |
emh203 | 0:3d9c67d97d6f | 280 | |
emh203 | 0:3d9c67d97d6f | 281 | #else |
emh203 | 0:3d9c67d97d6f | 282 | |
emh203 | 0:3d9c67d97d6f | 283 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 284 | |
emh203 | 0:3d9c67d97d6f | 285 | /* Initializing the loop counter to N/2 */ |
emh203 | 0:3d9c67d97d6f | 286 | i = (uint32_t) S->Nby2; |
emh203 | 0:3d9c67d97d6f | 287 | |
emh203 | 0:3d9c67d97d6f | 288 | do |
emh203 | 0:3d9c67d97d6f | 289 | { |
emh203 | 0:3d9c67d97d6f | 290 | /* Re-ordering of even and odd elements */ |
emh203 | 0:3d9c67d97d6f | 291 | /* pState[i] = pInlineBuffer[2*i] */ |
emh203 | 0:3d9c67d97d6f | 292 | *pS1++ = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 293 | /* pState[N-i-1] = pInlineBuffer[2*i+1] */ |
emh203 | 0:3d9c67d97d6f | 294 | *pS2-- = *pbuff++; |
emh203 | 0:3d9c67d97d6f | 295 | |
emh203 | 0:3d9c67d97d6f | 296 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 297 | i--; |
emh203 | 0:3d9c67d97d6f | 298 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 299 | |
emh203 | 0:3d9c67d97d6f | 300 | /* pbuff initialized to input buffer */ |
emh203 | 0:3d9c67d97d6f | 301 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 302 | |
emh203 | 0:3d9c67d97d6f | 303 | /* pS1 initialized to pState */ |
emh203 | 0:3d9c67d97d6f | 304 | pS1 = pState; |
emh203 | 0:3d9c67d97d6f | 305 | |
emh203 | 0:3d9c67d97d6f | 306 | /* Initializing the loop counter */ |
emh203 | 0:3d9c67d97d6f | 307 | i = (uint32_t) S->N; |
emh203 | 0:3d9c67d97d6f | 308 | |
emh203 | 0:3d9c67d97d6f | 309 | do |
emh203 | 0:3d9c67d97d6f | 310 | { |
emh203 | 0:3d9c67d97d6f | 311 | /* Writing the re-ordered output back to inplace input buffer */ |
emh203 | 0:3d9c67d97d6f | 312 | *pbuff++ = *pS1++; |
emh203 | 0:3d9c67d97d6f | 313 | |
emh203 | 0:3d9c67d97d6f | 314 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 315 | i--; |
emh203 | 0:3d9c67d97d6f | 316 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 317 | |
emh203 | 0:3d9c67d97d6f | 318 | |
emh203 | 0:3d9c67d97d6f | 319 | /* --------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 320 | * Step2: Calculate RFFT for N-point input |
emh203 | 0:3d9c67d97d6f | 321 | * ---------------------------------------------------------- */ |
emh203 | 0:3d9c67d97d6f | 322 | /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */ |
emh203 | 0:3d9c67d97d6f | 323 | arm_rfft_q15(S->pRfft, pInlineBuffer, pState); |
emh203 | 0:3d9c67d97d6f | 324 | |
emh203 | 0:3d9c67d97d6f | 325 | /*---------------------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 326 | * Step3: Multiply the FFT output with the weights. |
emh203 | 0:3d9c67d97d6f | 327 | *----------------------------------------------------------------------*/ |
emh203 | 0:3d9c67d97d6f | 328 | arm_cmplx_mult_cmplx_q15(pState, weights, pState, S->N); |
emh203 | 0:3d9c67d97d6f | 329 | |
emh203 | 0:3d9c67d97d6f | 330 | /* The output of complex multiplication is in 3.13 format. |
emh203 | 0:3d9c67d97d6f | 331 | * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.15 format by shifting left by 2 bits. */ |
emh203 | 0:3d9c67d97d6f | 332 | arm_shift_q15(pState, 2, pState, S->N * 2); |
emh203 | 0:3d9c67d97d6f | 333 | |
emh203 | 0:3d9c67d97d6f | 334 | /* ----------- Post-processing ---------- */ |
emh203 | 0:3d9c67d97d6f | 335 | /* DCT-IV can be obtained from DCT-II by the equation, |
emh203 | 0:3d9c67d97d6f | 336 | * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0) |
emh203 | 0:3d9c67d97d6f | 337 | * Hence, Y4(0) = Y2(0)/2 */ |
emh203 | 0:3d9c67d97d6f | 338 | /* Getting only real part from the output and Converting to DCT-IV */ |
emh203 | 0:3d9c67d97d6f | 339 | |
emh203 | 0:3d9c67d97d6f | 340 | /* Initializing the loop counter */ |
emh203 | 0:3d9c67d97d6f | 341 | i = ((uint32_t) S->N - 1u); |
emh203 | 0:3d9c67d97d6f | 342 | |
emh203 | 0:3d9c67d97d6f | 343 | /* pbuff initialized to input buffer. */ |
emh203 | 0:3d9c67d97d6f | 344 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 345 | |
emh203 | 0:3d9c67d97d6f | 346 | /* pS1 initialized to pState */ |
emh203 | 0:3d9c67d97d6f | 347 | pS1 = pState; |
emh203 | 0:3d9c67d97d6f | 348 | |
emh203 | 0:3d9c67d97d6f | 349 | /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */ |
emh203 | 0:3d9c67d97d6f | 350 | in = *pS1++ >> 1u; |
emh203 | 0:3d9c67d97d6f | 351 | /* input buffer acts as inplace, so output values are stored in the input itself. */ |
emh203 | 0:3d9c67d97d6f | 352 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 353 | |
emh203 | 0:3d9c67d97d6f | 354 | /* pState pointer is incremented twice as the real values are located alternatively in the array */ |
emh203 | 0:3d9c67d97d6f | 355 | pS1++; |
emh203 | 0:3d9c67d97d6f | 356 | |
emh203 | 0:3d9c67d97d6f | 357 | do |
emh203 | 0:3d9c67d97d6f | 358 | { |
emh203 | 0:3d9c67d97d6f | 359 | /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */ |
emh203 | 0:3d9c67d97d6f | 360 | /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */ |
emh203 | 0:3d9c67d97d6f | 361 | in = *pS1++ - in; |
emh203 | 0:3d9c67d97d6f | 362 | *pbuff++ = in; |
emh203 | 0:3d9c67d97d6f | 363 | /* points to the next real value */ |
emh203 | 0:3d9c67d97d6f | 364 | pS1++; |
emh203 | 0:3d9c67d97d6f | 365 | |
emh203 | 0:3d9c67d97d6f | 366 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 367 | i--; |
emh203 | 0:3d9c67d97d6f | 368 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 369 | |
emh203 | 0:3d9c67d97d6f | 370 | /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/ |
emh203 | 0:3d9c67d97d6f | 371 | |
emh203 | 0:3d9c67d97d6f | 372 | /* Initializing the loop counter */ |
emh203 | 0:3d9c67d97d6f | 373 | i = (uint32_t) S->N; |
emh203 | 0:3d9c67d97d6f | 374 | |
emh203 | 0:3d9c67d97d6f | 375 | /* pbuff initialized to the pInlineBuffer(now contains the output values) */ |
emh203 | 0:3d9c67d97d6f | 376 | pbuff = pInlineBuffer; |
emh203 | 0:3d9c67d97d6f | 377 | |
emh203 | 0:3d9c67d97d6f | 378 | do |
emh203 | 0:3d9c67d97d6f | 379 | { |
emh203 | 0:3d9c67d97d6f | 380 | /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */ |
emh203 | 0:3d9c67d97d6f | 381 | in = *pbuff; |
emh203 | 0:3d9c67d97d6f | 382 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emh203 | 0:3d9c67d97d6f | 383 | |
emh203 | 0:3d9c67d97d6f | 384 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 385 | i--; |
emh203 | 0:3d9c67d97d6f | 386 | } while(i > 0u); |
emh203 | 0:3d9c67d97d6f | 387 | |
emh203 | 0:3d9c67d97d6f | 388 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 389 | |
emh203 | 0:3d9c67d97d6f | 390 | } |
emh203 | 0:3d9c67d97d6f | 391 | |
emh203 | 0:3d9c67d97d6f | 392 | /** |
emh203 | 0:3d9c67d97d6f | 393 | * @} end of DCT4_IDCT4 group |
emh203 | 0:3d9c67d97d6f | 394 | */ |