CMSIS DSP library

Dependents:   KL25Z_FFT_Demo Hat_Board_v5_1 KL25Z_FFT_Demo_tony KL25Z_FFT_Demo_tony ... more

Fork of mbed-dsp by mbed official

Committer:
emilmont
Date:
Thu May 30 17:10:11 2013 +0100
Revision:
2:da51fb522205
Parent:
1:fdd22bb7aa52
Child:
3:7a284390b0ce
Keep "cmsis-dsp" module in synch with its source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
emilmont 1:fdd22bb7aa52 4 * $Date: 15. February 2012
emilmont 2:da51fb522205 5 * $Revision: V1.1.0
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_dct4_q15.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Processing function of DCT4 & IDCT4 Q15.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
emilmont 1:fdd22bb7aa52 14 * Version 1.1.0 2012/02/15
emilmont 1:fdd22bb7aa52 15 * Updated with more optimizations, bug fixes and minor API changes.
emilmont 1:fdd22bb7aa52 16 *
emilmont 1:fdd22bb7aa52 17 * Version 1.0.10 2011/7/15
emilmont 1:fdd22bb7aa52 18 * Big Endian support added and Merged M0 and M3/M4 Source code.
emilmont 1:fdd22bb7aa52 19 *
emilmont 1:fdd22bb7aa52 20 * Version 1.0.3 2010/11/29
emilmont 1:fdd22bb7aa52 21 * Re-organized the CMSIS folders and updated documentation.
emilmont 1:fdd22bb7aa52 22 *
emilmont 1:fdd22bb7aa52 23 * Version 1.0.2 2010/11/11
emilmont 1:fdd22bb7aa52 24 * Documentation updated.
emilmont 1:fdd22bb7aa52 25 *
emilmont 1:fdd22bb7aa52 26 * Version 1.0.1 2010/10/05
emilmont 1:fdd22bb7aa52 27 * Production release and review comments incorporated.
emilmont 1:fdd22bb7aa52 28 *
emilmont 1:fdd22bb7aa52 29 * Version 1.0.0 2010/09/20
emilmont 1:fdd22bb7aa52 30 * Production release and review comments incorporated.
emilmont 1:fdd22bb7aa52 31 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 32
emilmont 1:fdd22bb7aa52 33 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 34
emilmont 1:fdd22bb7aa52 35 /**
emilmont 1:fdd22bb7aa52 36 * @addtogroup DCT4_IDCT4
emilmont 1:fdd22bb7aa52 37 * @{
emilmont 1:fdd22bb7aa52 38 */
emilmont 1:fdd22bb7aa52 39
emilmont 1:fdd22bb7aa52 40 /**
emilmont 1:fdd22bb7aa52 41 * @brief Processing function for the Q15 DCT4/IDCT4.
emilmont 1:fdd22bb7aa52 42 * @param[in] *S points to an instance of the Q15 DCT4 structure.
emilmont 1:fdd22bb7aa52 43 * @param[in] *pState points to state buffer.
emilmont 1:fdd22bb7aa52 44 * @param[in,out] *pInlineBuffer points to the in-place input and output buffer.
emilmont 1:fdd22bb7aa52 45 * @return none.
emilmont 1:fdd22bb7aa52 46 *
emilmont 1:fdd22bb7aa52 47 * \par Input an output formats:
emilmont 1:fdd22bb7aa52 48 * Internally inputs are downscaled in the RFFT process function to avoid overflows.
emilmont 1:fdd22bb7aa52 49 * Number of bits downscaled, depends on the size of the transform.
emilmont 1:fdd22bb7aa52 50 * The input and output formats for different DCT sizes and number of bits to upscale are mentioned in the table below:
emilmont 1:fdd22bb7aa52 51 *
emilmont 1:fdd22bb7aa52 52 * \image html dct4FormatsQ15Table.gif
emilmont 1:fdd22bb7aa52 53 */
emilmont 1:fdd22bb7aa52 54
emilmont 1:fdd22bb7aa52 55 void arm_dct4_q15(
emilmont 1:fdd22bb7aa52 56 const arm_dct4_instance_q15 * S,
emilmont 1:fdd22bb7aa52 57 q15_t * pState,
emilmont 1:fdd22bb7aa52 58 q15_t * pInlineBuffer)
emilmont 1:fdd22bb7aa52 59 {
emilmont 1:fdd22bb7aa52 60 uint32_t i; /* Loop counter */
emilmont 1:fdd22bb7aa52 61 q15_t *weights = S->pTwiddle; /* Pointer to the Weights table */
emilmont 1:fdd22bb7aa52 62 q15_t *cosFact = S->pCosFactor; /* Pointer to the cos factors table */
emilmont 1:fdd22bb7aa52 63 q15_t *pS1, *pS2, *pbuff; /* Temporary pointers for input buffer and pState buffer */
emilmont 1:fdd22bb7aa52 64 q15_t in; /* Temporary variable */
emilmont 1:fdd22bb7aa52 65
emilmont 1:fdd22bb7aa52 66
emilmont 1:fdd22bb7aa52 67 /* DCT4 computation involves DCT2 (which is calculated using RFFT)
emilmont 1:fdd22bb7aa52 68 * along with some pre-processing and post-processing.
emilmont 1:fdd22bb7aa52 69 * Computational procedure is explained as follows:
emilmont 1:fdd22bb7aa52 70 * (a) Pre-processing involves multiplying input with cos factor,
emilmont 1:fdd22bb7aa52 71 * r(n) = 2 * u(n) * cos(pi*(2*n+1)/(4*n))
emilmont 1:fdd22bb7aa52 72 * where,
emilmont 1:fdd22bb7aa52 73 * r(n) -- output of preprocessing
emilmont 1:fdd22bb7aa52 74 * u(n) -- input to preprocessing(actual Source buffer)
emilmont 1:fdd22bb7aa52 75 * (b) Calculation of DCT2 using FFT is divided into three steps:
emilmont 1:fdd22bb7aa52 76 * Step1: Re-ordering of even and odd elements of input.
emilmont 1:fdd22bb7aa52 77 * Step2: Calculating FFT of the re-ordered input.
emilmont 1:fdd22bb7aa52 78 * Step3: Taking the real part of the product of FFT output and weights.
emilmont 1:fdd22bb7aa52 79 * (c) Post-processing - DCT4 can be obtained from DCT2 output using the following equation:
emilmont 1:fdd22bb7aa52 80 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 81 * where,
emilmont 1:fdd22bb7aa52 82 * Y4 -- DCT4 output, Y2 -- DCT2 output
emilmont 1:fdd22bb7aa52 83 * (d) Multiplying the output with the normalizing factor sqrt(2/N).
emilmont 1:fdd22bb7aa52 84 */
emilmont 1:fdd22bb7aa52 85
emilmont 1:fdd22bb7aa52 86 /*-------- Pre-processing ------------*/
emilmont 1:fdd22bb7aa52 87 /* Multiplying input with cos factor i.e. r(n) = 2 * x(n) * cos(pi*(2*n+1)/(4*n)) */
emilmont 1:fdd22bb7aa52 88 arm_mult_q15(pInlineBuffer, cosFact, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 89 arm_shift_q15(pInlineBuffer, 1, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 90
emilmont 1:fdd22bb7aa52 91 /* ----------------------------------------------------------------
emilmont 1:fdd22bb7aa52 92 * Step1: Re-ordering of even and odd elements as
emilmont 1:fdd22bb7aa52 93 * pState[i] = pInlineBuffer[2*i] and
emilmont 1:fdd22bb7aa52 94 * pState[N-i-1] = pInlineBuffer[2*i+1] where i = 0 to N/2
emilmont 1:fdd22bb7aa52 95 ---------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 96
emilmont 1:fdd22bb7aa52 97 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 98 pS1 = pState;
emilmont 1:fdd22bb7aa52 99
emilmont 1:fdd22bb7aa52 100 /* pS2 initialized to pState+N-1, so that it points to the end of the state buffer */
emilmont 1:fdd22bb7aa52 101 pS2 = pState + (S->N - 1u);
emilmont 1:fdd22bb7aa52 102
emilmont 1:fdd22bb7aa52 103 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 104 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 105
emilmont 1:fdd22bb7aa52 106
emilmont 1:fdd22bb7aa52 107 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 110
emilmont 1:fdd22bb7aa52 111 /* Initializing the loop counter to N/2 >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 112 i = (uint32_t) S->Nby2 >> 2u;
emilmont 1:fdd22bb7aa52 113
emilmont 1:fdd22bb7aa52 114 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 115 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 116 do
emilmont 1:fdd22bb7aa52 117 {
emilmont 1:fdd22bb7aa52 118 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 119 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 120 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 121 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 122 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 125 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 128 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 129
emilmont 1:fdd22bb7aa52 130 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 131 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 132
emilmont 1:fdd22bb7aa52 133 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 134 i--;
emilmont 1:fdd22bb7aa52 135 } while(i > 0u);
emilmont 1:fdd22bb7aa52 136
emilmont 1:fdd22bb7aa52 137 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 138 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 139
emilmont 1:fdd22bb7aa52 140 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 141 pS1 = pState;
emilmont 1:fdd22bb7aa52 142
emilmont 1:fdd22bb7aa52 143 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 144 i = (uint32_t) S->N >> 2u;
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 /* Processing with loop unrolling 4 times as N is always multiple of 4.
emilmont 1:fdd22bb7aa52 147 * Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 148 do
emilmont 1:fdd22bb7aa52 149 {
emilmont 1:fdd22bb7aa52 150 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 151 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 152 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 153 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 154 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 155
emilmont 1:fdd22bb7aa52 156 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 157 i--;
emilmont 1:fdd22bb7aa52 158 } while(i > 0u);
emilmont 1:fdd22bb7aa52 159
emilmont 1:fdd22bb7aa52 160
emilmont 1:fdd22bb7aa52 161 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 162 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 163 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 164 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 165 arm_rfft_q15(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 /*----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 168 * Step3: Multiply the FFT output with the weights.
emilmont 1:fdd22bb7aa52 169 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 170 arm_cmplx_mult_cmplx_q15(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 171
emilmont 1:fdd22bb7aa52 172 /* The output of complex multiplication is in 3.13 format.
emilmont 1:fdd22bb7aa52 173 * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.15 format by shifting left by 2 bits. */
emilmont 1:fdd22bb7aa52 174 arm_shift_q15(pState, 2, pState, S->N * 2);
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 177 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 178 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 179 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 180 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 181
emilmont 1:fdd22bb7aa52 182 /* Initializing the loop counter to N >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 183 i = ((uint32_t) S->N - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 184
emilmont 1:fdd22bb7aa52 185 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 186 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 189 pS1 = pState;
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 192 in = *pS1++ >> 1u;
emilmont 1:fdd22bb7aa52 193 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 194 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 197 pS1++;
emilmont 1:fdd22bb7aa52 198
emilmont 1:fdd22bb7aa52 199 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 200 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 201 do
emilmont 1:fdd22bb7aa52 202 {
emilmont 1:fdd22bb7aa52 203 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 204 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 205 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 206 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 207 /* points to the next real value */
emilmont 1:fdd22bb7aa52 208 pS1++;
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 211 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 212 pS1++;
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 215 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 216 pS1++;
emilmont 1:fdd22bb7aa52 217
emilmont 1:fdd22bb7aa52 218 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 219 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 220 pS1++;
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 223 i--;
emilmont 1:fdd22bb7aa52 224 } while(i > 0u);
emilmont 1:fdd22bb7aa52 225
emilmont 1:fdd22bb7aa52 226 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 227 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 228 i = ((uint32_t) S->N - 1u) % 0x4u;
emilmont 1:fdd22bb7aa52 229
emilmont 1:fdd22bb7aa52 230 while(i > 0u)
emilmont 1:fdd22bb7aa52 231 {
emilmont 1:fdd22bb7aa52 232 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 233 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 234 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 235 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 236 /* points to the next real value */
emilmont 1:fdd22bb7aa52 237 pS1++;
emilmont 1:fdd22bb7aa52 238
emilmont 1:fdd22bb7aa52 239 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 240 i--;
emilmont 1:fdd22bb7aa52 241 }
emilmont 1:fdd22bb7aa52 242
emilmont 1:fdd22bb7aa52 243
emilmont 1:fdd22bb7aa52 244 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 245
emilmont 1:fdd22bb7aa52 246 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 247 i = (uint32_t) S->N >> 2u;
emilmont 1:fdd22bb7aa52 248
emilmont 1:fdd22bb7aa52 249 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 250 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 251
emilmont 1:fdd22bb7aa52 252 /* Processing with loop unrolling 4 times as N is always multiple of 4. Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 253 do
emilmont 1:fdd22bb7aa52 254 {
emilmont 1:fdd22bb7aa52 255 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 256 in = *pbuff;
emilmont 1:fdd22bb7aa52 257 *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15));
emilmont 1:fdd22bb7aa52 258
emilmont 1:fdd22bb7aa52 259 in = *pbuff;
emilmont 1:fdd22bb7aa52 260 *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15));
emilmont 1:fdd22bb7aa52 261
emilmont 1:fdd22bb7aa52 262 in = *pbuff;
emilmont 1:fdd22bb7aa52 263 *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15));
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 in = *pbuff;
emilmont 1:fdd22bb7aa52 266 *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15));
emilmont 1:fdd22bb7aa52 267
emilmont 1:fdd22bb7aa52 268 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 269 i--;
emilmont 1:fdd22bb7aa52 270 } while(i > 0u);
emilmont 1:fdd22bb7aa52 271
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 #else
emilmont 1:fdd22bb7aa52 274
emilmont 1:fdd22bb7aa52 275 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 276
emilmont 1:fdd22bb7aa52 277 /* Initializing the loop counter to N/2 */
emilmont 1:fdd22bb7aa52 278 i = (uint32_t) S->Nby2;
emilmont 1:fdd22bb7aa52 279
emilmont 1:fdd22bb7aa52 280 do
emilmont 1:fdd22bb7aa52 281 {
emilmont 1:fdd22bb7aa52 282 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 283 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 284 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 285 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 286 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 289 i--;
emilmont 1:fdd22bb7aa52 290 } while(i > 0u);
emilmont 1:fdd22bb7aa52 291
emilmont 1:fdd22bb7aa52 292 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 293 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 296 pS1 = pState;
emilmont 1:fdd22bb7aa52 297
emilmont 1:fdd22bb7aa52 298 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 299 i = (uint32_t) S->N;
emilmont 1:fdd22bb7aa52 300
emilmont 1:fdd22bb7aa52 301 do
emilmont 1:fdd22bb7aa52 302 {
emilmont 1:fdd22bb7aa52 303 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 304 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 305
emilmont 1:fdd22bb7aa52 306 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 307 i--;
emilmont 1:fdd22bb7aa52 308 } while(i > 0u);
emilmont 1:fdd22bb7aa52 309
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 312 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 313 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 314 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 315 arm_rfft_q15(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 316
emilmont 1:fdd22bb7aa52 317 /*----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 318 * Step3: Multiply the FFT output with the weights.
emilmont 1:fdd22bb7aa52 319 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 320 arm_cmplx_mult_cmplx_q15(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 321
emilmont 1:fdd22bb7aa52 322 /* The output of complex multiplication is in 3.13 format.
emilmont 1:fdd22bb7aa52 323 * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.15 format by shifting left by 2 bits. */
emilmont 1:fdd22bb7aa52 324 arm_shift_q15(pState, 2, pState, S->N * 2);
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 327 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 328 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 329 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 330 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 331
emilmont 1:fdd22bb7aa52 332 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 333 i = ((uint32_t) S->N - 1u);
emilmont 1:fdd22bb7aa52 334
emilmont 1:fdd22bb7aa52 335 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 336 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 337
emilmont 1:fdd22bb7aa52 338 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 339 pS1 = pState;
emilmont 1:fdd22bb7aa52 340
emilmont 1:fdd22bb7aa52 341 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 342 in = *pS1++ >> 1u;
emilmont 1:fdd22bb7aa52 343 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 344 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 345
emilmont 1:fdd22bb7aa52 346 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 347 pS1++;
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 do
emilmont 1:fdd22bb7aa52 350 {
emilmont 1:fdd22bb7aa52 351 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 352 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 353 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 354 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 355 /* points to the next real value */
emilmont 1:fdd22bb7aa52 356 pS1++;
emilmont 1:fdd22bb7aa52 357
emilmont 1:fdd22bb7aa52 358 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 359 i--;
emilmont 1:fdd22bb7aa52 360 } while(i > 0u);
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 363
emilmont 1:fdd22bb7aa52 364 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 365 i = (uint32_t) S->N;
emilmont 1:fdd22bb7aa52 366
emilmont 1:fdd22bb7aa52 367 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 368 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 369
emilmont 1:fdd22bb7aa52 370 do
emilmont 1:fdd22bb7aa52 371 {
emilmont 1:fdd22bb7aa52 372 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 373 in = *pbuff;
emilmont 1:fdd22bb7aa52 374 *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15));
emilmont 1:fdd22bb7aa52 375
emilmont 1:fdd22bb7aa52 376 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 377 i--;
emilmont 1:fdd22bb7aa52 378 } while(i > 0u);
emilmont 1:fdd22bb7aa52 379
emilmont 1:fdd22bb7aa52 380 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 381
emilmont 1:fdd22bb7aa52 382 }
emilmont 1:fdd22bb7aa52 383
emilmont 1:fdd22bb7aa52 384 /**
emilmont 1:fdd22bb7aa52 385 * @} end of DCT4_IDCT4 group
emilmont 1:fdd22bb7aa52 386 */