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:
mbed_official
Date:
Fri Nov 08 13:45:10 2013 +0000
Revision:
3:7a284390b0ce
Parent:
2:da51fb522205
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 3:7a284390b0ce 2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 3:7a284390b0ce 4 * $Date: 17. January 2013
mbed_official 3:7a284390b0ce 5 * $Revision: V1.4.1
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_dct4_f32.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Processing function of DCT4 & IDCT4 F32.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
mbed_official 3:7a284390b0ce 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 3:7a284390b0ce 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 3:7a284390b0ce 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 3:7a284390b0ce 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40
emilmont 1:fdd22bb7aa52 41 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @ingroup groupTransforms
emilmont 1:fdd22bb7aa52 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
emilmont 1:fdd22bb7aa52 48 * @defgroup DCT4_IDCT4 DCT Type IV Functions
emilmont 1:fdd22bb7aa52 49 * Representation of signals by minimum number of values is important for storage and transmission.
emilmont 1:fdd22bb7aa52 50 * The possibility of large discontinuity between the beginning and end of a period of a signal
emilmont 1:fdd22bb7aa52 51 * in DFT can be avoided by extending the signal so that it is even-symmetric.
emilmont 1:fdd22bb7aa52 52 * Discrete Cosine Transform (DCT) is constructed such that its energy is heavily concentrated in the lower part of the
emilmont 1:fdd22bb7aa52 53 * spectrum and is very widely used in signal and image coding applications.
emilmont 1:fdd22bb7aa52 54 * The family of DCTs (DCT type- 1,2,3,4) is the outcome of different combinations of homogeneous boundary conditions.
emilmont 1:fdd22bb7aa52 55 * DCT has an excellent energy-packing capability, hence has many applications and in data compression in particular.
emilmont 1:fdd22bb7aa52 56 *
emilmont 1:fdd22bb7aa52 57 * DCT is essentially the Discrete Fourier Transform(DFT) of an even-extended real signal.
emilmont 1:fdd22bb7aa52 58 * Reordering of the input data makes the computation of DCT just a problem of
emilmont 1:fdd22bb7aa52 59 * computing the DFT of a real signal with a few additional operations.
emilmont 1:fdd22bb7aa52 60 * This approach provides regular, simple, and very efficient DCT algorithms for practical hardware and software implementations.
emilmont 1:fdd22bb7aa52 61 *
emilmont 1:fdd22bb7aa52 62 * DCT type-II can be implemented using Fast fourier transform (FFT) internally, as the transform is applied on real values, Real FFT can be used.
emilmont 1:fdd22bb7aa52 63 * DCT4 is implemented using DCT2 as their implementations are similar except with some added pre-processing and post-processing.
emilmont 1:fdd22bb7aa52 64 * DCT2 implementation can be described in the following steps:
emilmont 1:fdd22bb7aa52 65 * - Re-ordering input
emilmont 1:fdd22bb7aa52 66 * - Calculating Real FFT
emilmont 1:fdd22bb7aa52 67 * - Multiplication of weights and Real FFT output and getting real part from the product.
emilmont 1:fdd22bb7aa52 68 *
emilmont 1:fdd22bb7aa52 69 * This process is explained by the block diagram below:
emilmont 1:fdd22bb7aa52 70 * \image html DCT4.gif "Discrete Cosine Transform - type-IV"
emilmont 1:fdd22bb7aa52 71 *
emilmont 1:fdd22bb7aa52 72 * \par Algorithm:
emilmont 1:fdd22bb7aa52 73 * The N-point type-IV DCT is defined as a real, linear transformation by the formula:
emilmont 1:fdd22bb7aa52 74 * \image html DCT4Equation.gif
emilmont 1:fdd22bb7aa52 75 * where <code>k = 0,1,2,.....N-1</code>
emilmont 1:fdd22bb7aa52 76 *\par
emilmont 1:fdd22bb7aa52 77 * Its inverse is defined as follows:
emilmont 1:fdd22bb7aa52 78 * \image html IDCT4Equation.gif
emilmont 1:fdd22bb7aa52 79 * where <code>n = 0,1,2,.....N-1</code>
emilmont 1:fdd22bb7aa52 80 *\par
emilmont 1:fdd22bb7aa52 81 * The DCT4 matrices become involutory (i.e. they are self-inverse) by multiplying with an overall scale factor of sqrt(2/N).
emilmont 1:fdd22bb7aa52 82 * The symmetry of the transform matrix indicates that the fast algorithms for the forward
emilmont 1:fdd22bb7aa52 83 * and inverse transform computation are identical.
emilmont 1:fdd22bb7aa52 84 * Note that the implementation of Inverse DCT4 and DCT4 is same, hence same process function can be used for both.
emilmont 1:fdd22bb7aa52 85 *
emilmont 1:fdd22bb7aa52 86 * \par Lengths supported by the transform:
emilmont 1:fdd22bb7aa52 87 * As DCT4 internally uses Real FFT, it supports all the lengths supported by arm_rfft_f32().
emilmont 1:fdd22bb7aa52 88 * The library provides separate functions for Q15, Q31, and floating-point data types.
emilmont 1:fdd22bb7aa52 89 * \par Instance Structure
emilmont 1:fdd22bb7aa52 90 * The instances for Real FFT and FFT, cosine values table and twiddle factor table are stored in an instance data structure.
emilmont 1:fdd22bb7aa52 91 * A separate instance structure must be defined for each transform.
emilmont 1:fdd22bb7aa52 92 * There are separate instance structure declarations for each of the 3 supported data types.
emilmont 1:fdd22bb7aa52 93 *
emilmont 1:fdd22bb7aa52 94 * \par Initialization Functions
emilmont 1:fdd22bb7aa52 95 * There is also an associated initialization function for each data type.
emilmont 1:fdd22bb7aa52 96 * The initialization function performs the following operations:
emilmont 1:fdd22bb7aa52 97 * - Sets the values of the internal structure fields.
emilmont 1:fdd22bb7aa52 98 * - Initializes Real FFT as its process function is used internally in DCT4, by calling arm_rfft_init_f32().
emilmont 1:fdd22bb7aa52 99 * \par
emilmont 1:fdd22bb7aa52 100 * Use of the initialization function is optional.
emilmont 1:fdd22bb7aa52 101 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
emilmont 1:fdd22bb7aa52 102 * To place an instance structure into a const data section, the instance structure must be manually initialized.
emilmont 1:fdd22bb7aa52 103 * Manually initialize the instance structure as follows:
emilmont 1:fdd22bb7aa52 104 * <pre>
emilmont 1:fdd22bb7aa52 105 *arm_dct4_instance_f32 S = {N, Nby2, normalize, pTwiddle, pCosFactor, pRfft, pCfft};
emilmont 1:fdd22bb7aa52 106 *arm_dct4_instance_q31 S = {N, Nby2, normalize, pTwiddle, pCosFactor, pRfft, pCfft};
emilmont 1:fdd22bb7aa52 107 *arm_dct4_instance_q15 S = {N, Nby2, normalize, pTwiddle, pCosFactor, pRfft, pCfft};
emilmont 1:fdd22bb7aa52 108 * </pre>
emilmont 1:fdd22bb7aa52 109 * where \c N is the length of the DCT4; \c Nby2 is half of the length of the DCT4;
emilmont 1:fdd22bb7aa52 110 * \c normalize is normalizing factor used and is equal to <code>sqrt(2/N)</code>;
emilmont 1:fdd22bb7aa52 111 * \c pTwiddle points to the twiddle factor table;
emilmont 1:fdd22bb7aa52 112 * \c pCosFactor points to the cosFactor table;
emilmont 1:fdd22bb7aa52 113 * \c pRfft points to the real FFT instance;
emilmont 1:fdd22bb7aa52 114 * \c pCfft points to the complex FFT instance;
emilmont 1:fdd22bb7aa52 115 * The CFFT and RFFT structures also needs to be initialized, refer to arm_cfft_radix4_f32()
emilmont 1:fdd22bb7aa52 116 * and arm_rfft_f32() respectively for details regarding static initialization.
emilmont 1:fdd22bb7aa52 117 *
emilmont 1:fdd22bb7aa52 118 * \par Fixed-Point Behavior
emilmont 1:fdd22bb7aa52 119 * Care must be taken when using the fixed-point versions of the DCT4 transform functions.
emilmont 1:fdd22bb7aa52 120 * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered.
emilmont 1:fdd22bb7aa52 121 * Refer to the function specific documentation below for usage guidelines.
emilmont 1:fdd22bb7aa52 122 */
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 /**
emilmont 1:fdd22bb7aa52 125 * @addtogroup DCT4_IDCT4
emilmont 1:fdd22bb7aa52 126 * @{
emilmont 1:fdd22bb7aa52 127 */
emilmont 1:fdd22bb7aa52 128
emilmont 1:fdd22bb7aa52 129 /**
emilmont 1:fdd22bb7aa52 130 * @brief Processing function for the floating-point DCT4/IDCT4.
emilmont 1:fdd22bb7aa52 131 * @param[in] *S points to an instance of the floating-point DCT4/IDCT4 structure.
emilmont 1:fdd22bb7aa52 132 * @param[in] *pState points to state buffer.
emilmont 1:fdd22bb7aa52 133 * @param[in,out] *pInlineBuffer points to the in-place input and output buffer.
emilmont 1:fdd22bb7aa52 134 * @return none.
emilmont 1:fdd22bb7aa52 135 */
emilmont 1:fdd22bb7aa52 136
emilmont 1:fdd22bb7aa52 137 void arm_dct4_f32(
emilmont 1:fdd22bb7aa52 138 const arm_dct4_instance_f32 * S,
emilmont 1:fdd22bb7aa52 139 float32_t * pState,
emilmont 1:fdd22bb7aa52 140 float32_t * pInlineBuffer)
emilmont 1:fdd22bb7aa52 141 {
emilmont 1:fdd22bb7aa52 142 uint32_t i; /* Loop counter */
emilmont 1:fdd22bb7aa52 143 float32_t *weights = S->pTwiddle; /* Pointer to the Weights table */
emilmont 1:fdd22bb7aa52 144 float32_t *cosFact = S->pCosFactor; /* Pointer to the cos factors table */
emilmont 1:fdd22bb7aa52 145 float32_t *pS1, *pS2, *pbuff; /* Temporary pointers for input buffer and pState buffer */
emilmont 1:fdd22bb7aa52 146 float32_t in; /* Temporary variable */
emilmont 1:fdd22bb7aa52 147
emilmont 1:fdd22bb7aa52 148
emilmont 1:fdd22bb7aa52 149 /* DCT4 computation involves DCT2 (which is calculated using RFFT)
emilmont 1:fdd22bb7aa52 150 * along with some pre-processing and post-processing.
emilmont 1:fdd22bb7aa52 151 * Computational procedure is explained as follows:
emilmont 1:fdd22bb7aa52 152 * (a) Pre-processing involves multiplying input with cos factor,
emilmont 1:fdd22bb7aa52 153 * r(n) = 2 * u(n) * cos(pi*(2*n+1)/(4*n))
emilmont 1:fdd22bb7aa52 154 * where,
emilmont 1:fdd22bb7aa52 155 * r(n) -- output of preprocessing
emilmont 1:fdd22bb7aa52 156 * u(n) -- input to preprocessing(actual Source buffer)
emilmont 1:fdd22bb7aa52 157 * (b) Calculation of DCT2 using FFT is divided into three steps:
emilmont 1:fdd22bb7aa52 158 * Step1: Re-ordering of even and odd elements of input.
emilmont 1:fdd22bb7aa52 159 * Step2: Calculating FFT of the re-ordered input.
emilmont 1:fdd22bb7aa52 160 * Step3: Taking the real part of the product of FFT output and weights.
emilmont 1:fdd22bb7aa52 161 * (c) Post-processing - DCT4 can be obtained from DCT2 output using the following equation:
emilmont 1:fdd22bb7aa52 162 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 163 * where,
emilmont 1:fdd22bb7aa52 164 * Y4 -- DCT4 output, Y2 -- DCT2 output
emilmont 1:fdd22bb7aa52 165 * (d) Multiplying the output with the normalizing factor sqrt(2/N).
emilmont 1:fdd22bb7aa52 166 */
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168 /*-------- Pre-processing ------------*/
emilmont 1:fdd22bb7aa52 169 /* Multiplying input with cos factor i.e. r(n) = 2 * x(n) * cos(pi*(2*n+1)/(4*n)) */
emilmont 1:fdd22bb7aa52 170 arm_scale_f32(pInlineBuffer, 2.0f, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 171 arm_mult_f32(pInlineBuffer, cosFact, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 172
emilmont 1:fdd22bb7aa52 173 /* ----------------------------------------------------------------
emilmont 1:fdd22bb7aa52 174 * Step1: Re-ordering of even and odd elements as,
emilmont 1:fdd22bb7aa52 175 * pState[i] = pInlineBuffer[2*i] and
emilmont 1:fdd22bb7aa52 176 * pState[N-i-1] = pInlineBuffer[2*i+1] where i = 0 to N/2
emilmont 1:fdd22bb7aa52 177 ---------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 178
emilmont 1:fdd22bb7aa52 179 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 180 pS1 = pState;
emilmont 1:fdd22bb7aa52 181
emilmont 1:fdd22bb7aa52 182 /* pS2 initialized to pState+N-1, so that it points to the end of the state buffer */
emilmont 1:fdd22bb7aa52 183 pS2 = pState + (S->N - 1u);
emilmont 1:fdd22bb7aa52 184
emilmont 1:fdd22bb7aa52 185 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 186 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 187
mbed_official 3:7a284390b0ce 188 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 189
emilmont 1:fdd22bb7aa52 190 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 191
emilmont 1:fdd22bb7aa52 192 /* Initializing the loop counter to N/2 >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 193 i = (uint32_t) S->Nby2 >> 2u;
emilmont 1:fdd22bb7aa52 194
emilmont 1:fdd22bb7aa52 195 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 196 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 197 do
emilmont 1:fdd22bb7aa52 198 {
emilmont 1:fdd22bb7aa52 199 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 200 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 201 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 202 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 203 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 204
emilmont 1:fdd22bb7aa52 205 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 206 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 207
emilmont 1:fdd22bb7aa52 208 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 209 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 210
emilmont 1:fdd22bb7aa52 211 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 212 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 215 i--;
emilmont 1:fdd22bb7aa52 216 } while(i > 0u);
emilmont 1:fdd22bb7aa52 217
emilmont 1:fdd22bb7aa52 218 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 219 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 220
emilmont 1:fdd22bb7aa52 221 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 222 pS1 = pState;
emilmont 1:fdd22bb7aa52 223
emilmont 1:fdd22bb7aa52 224 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 225 i = (uint32_t) S->N >> 2u;
emilmont 1:fdd22bb7aa52 226
emilmont 1:fdd22bb7aa52 227 /* Processing with loop unrolling 4 times as N is always multiple of 4.
emilmont 1:fdd22bb7aa52 228 * Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 229 do
emilmont 1:fdd22bb7aa52 230 {
emilmont 1:fdd22bb7aa52 231 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 232 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 233 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 234 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 235 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 236
emilmont 1:fdd22bb7aa52 237 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 238 i--;
emilmont 1:fdd22bb7aa52 239 } while(i > 0u);
emilmont 1:fdd22bb7aa52 240
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 243 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 244 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 245 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 246 arm_rfft_f32(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 247
emilmont 1:fdd22bb7aa52 248 /*----------------------------------------------------------------------
emilmont 2:da51fb522205 249 * Step3: Multiply the FFT output with the weights.
emilmont 2:da51fb522205 250 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 251 arm_cmplx_mult_cmplx_f32(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 252
emilmont 1:fdd22bb7aa52 253 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 254 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 255 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 256 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 257 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 258
emilmont 1:fdd22bb7aa52 259 /* Initializing the loop counter to N >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 260 i = ((uint32_t) S->N - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 261
emilmont 1:fdd22bb7aa52 262 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 263 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 266 pS1 = pState;
emilmont 1:fdd22bb7aa52 267
emilmont 1:fdd22bb7aa52 268 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 269 in = *pS1++ * (float32_t) 0.5;
emilmont 1:fdd22bb7aa52 270 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 271 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 274 pS1++;
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 277 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 278 do
emilmont 1:fdd22bb7aa52 279 {
emilmont 1:fdd22bb7aa52 280 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 281 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 282 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 283 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 284 /* points to the next real value */
emilmont 1:fdd22bb7aa52 285 pS1++;
emilmont 1:fdd22bb7aa52 286
emilmont 1:fdd22bb7aa52 287 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 288 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 289 pS1++;
emilmont 1:fdd22bb7aa52 290
emilmont 1:fdd22bb7aa52 291 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 292 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 293 pS1++;
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 296 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 297 pS1++;
emilmont 1:fdd22bb7aa52 298
emilmont 1:fdd22bb7aa52 299 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 300 i--;
emilmont 1:fdd22bb7aa52 301 } while(i > 0u);
emilmont 1:fdd22bb7aa52 302
emilmont 1:fdd22bb7aa52 303 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 304 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 305 i = ((uint32_t) S->N - 1u) % 0x4u;
emilmont 1:fdd22bb7aa52 306
emilmont 1:fdd22bb7aa52 307 while(i > 0u)
emilmont 1:fdd22bb7aa52 308 {
emilmont 1:fdd22bb7aa52 309 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 310 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 311 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 312 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 313 /* points to the next real value */
emilmont 1:fdd22bb7aa52 314 pS1++;
emilmont 1:fdd22bb7aa52 315
emilmont 1:fdd22bb7aa52 316 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 317 i--;
emilmont 1:fdd22bb7aa52 318 }
emilmont 1:fdd22bb7aa52 319
emilmont 1:fdd22bb7aa52 320
emilmont 1:fdd22bb7aa52 321 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 322
emilmont 1:fdd22bb7aa52 323 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 324 i = (uint32_t) S->N >> 2u;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 327 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 /* Processing with loop unrolling 4 times as N is always multiple of 4. Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 330 do
emilmont 1:fdd22bb7aa52 331 {
emilmont 1:fdd22bb7aa52 332 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 333 in = *pbuff;
emilmont 1:fdd22bb7aa52 334 *pbuff++ = in * S->normalize;
emilmont 1:fdd22bb7aa52 335
emilmont 1:fdd22bb7aa52 336 in = *pbuff;
emilmont 1:fdd22bb7aa52 337 *pbuff++ = in * S->normalize;
emilmont 1:fdd22bb7aa52 338
emilmont 1:fdd22bb7aa52 339 in = *pbuff;
emilmont 1:fdd22bb7aa52 340 *pbuff++ = in * S->normalize;
emilmont 1:fdd22bb7aa52 341
emilmont 1:fdd22bb7aa52 342 in = *pbuff;
emilmont 1:fdd22bb7aa52 343 *pbuff++ = in * S->normalize;
emilmont 1:fdd22bb7aa52 344
emilmont 1:fdd22bb7aa52 345 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 346 i--;
emilmont 1:fdd22bb7aa52 347 } while(i > 0u);
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349
emilmont 1:fdd22bb7aa52 350 #else
emilmont 1:fdd22bb7aa52 351
emilmont 1:fdd22bb7aa52 352 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354 /* Initializing the loop counter to N/2 */
emilmont 1:fdd22bb7aa52 355 i = (uint32_t) S->Nby2;
emilmont 1:fdd22bb7aa52 356
emilmont 1:fdd22bb7aa52 357 do
emilmont 1:fdd22bb7aa52 358 {
emilmont 1:fdd22bb7aa52 359 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 360 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 361 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 362 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 363 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 366 i--;
emilmont 1:fdd22bb7aa52 367 } while(i > 0u);
emilmont 1:fdd22bb7aa52 368
emilmont 1:fdd22bb7aa52 369 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 370 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 371
emilmont 1:fdd22bb7aa52 372 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 373 pS1 = pState;
emilmont 1:fdd22bb7aa52 374
emilmont 1:fdd22bb7aa52 375 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 376 i = (uint32_t) S->N;
emilmont 1:fdd22bb7aa52 377
emilmont 1:fdd22bb7aa52 378 do
emilmont 1:fdd22bb7aa52 379 {
emilmont 1:fdd22bb7aa52 380 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 381 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 382
emilmont 1:fdd22bb7aa52 383 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 384 i--;
emilmont 1:fdd22bb7aa52 385 } while(i > 0u);
emilmont 1:fdd22bb7aa52 386
emilmont 1:fdd22bb7aa52 387
emilmont 1:fdd22bb7aa52 388 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 389 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 390 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 391 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 392 arm_rfft_f32(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 393
emilmont 1:fdd22bb7aa52 394 /*----------------------------------------------------------------------
emilmont 2:da51fb522205 395 * Step3: Multiply the FFT output with the weights.
emilmont 2:da51fb522205 396 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 397 arm_cmplx_mult_cmplx_f32(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 398
emilmont 1:fdd22bb7aa52 399 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 400 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 401 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 402 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 403 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 404
emilmont 1:fdd22bb7aa52 405 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 406 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 407
emilmont 1:fdd22bb7aa52 408 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 409 pS1 = pState;
emilmont 1:fdd22bb7aa52 410
emilmont 1:fdd22bb7aa52 411 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 412 in = *pS1++ * (float32_t) 0.5;
emilmont 1:fdd22bb7aa52 413 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 414 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 415
emilmont 1:fdd22bb7aa52 416 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 417 pS1++;
emilmont 1:fdd22bb7aa52 418
emilmont 1:fdd22bb7aa52 419 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 420 i = ((uint32_t) S->N - 1u);
emilmont 1:fdd22bb7aa52 421
emilmont 1:fdd22bb7aa52 422 do
emilmont 1:fdd22bb7aa52 423 {
emilmont 1:fdd22bb7aa52 424 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 425 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 426 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 427 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 428 /* points to the next real value */
emilmont 1:fdd22bb7aa52 429 pS1++;
emilmont 1:fdd22bb7aa52 430
emilmont 1:fdd22bb7aa52 431
emilmont 1:fdd22bb7aa52 432 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 433 i--;
emilmont 1:fdd22bb7aa52 434 } while(i > 0u);
emilmont 1:fdd22bb7aa52 435
emilmont 1:fdd22bb7aa52 436
emilmont 1:fdd22bb7aa52 437 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 438
emilmont 1:fdd22bb7aa52 439 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 440 i = (uint32_t) S->N;
emilmont 1:fdd22bb7aa52 441
emilmont 1:fdd22bb7aa52 442 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 443 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 444
emilmont 1:fdd22bb7aa52 445 do
emilmont 1:fdd22bb7aa52 446 {
emilmont 1:fdd22bb7aa52 447 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 448 in = *pbuff;
emilmont 1:fdd22bb7aa52 449 *pbuff++ = in * S->normalize;
emilmont 1:fdd22bb7aa52 450
emilmont 1:fdd22bb7aa52 451 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 452 i--;
emilmont 1:fdd22bb7aa52 453 } while(i > 0u);
emilmont 1:fdd22bb7aa52 454
mbed_official 3:7a284390b0ce 455 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 456
emilmont 1:fdd22bb7aa52 457 }
emilmont 1:fdd22bb7aa52 458
emilmont 1:fdd22bb7aa52 459 /**
emilmont 1:fdd22bb7aa52 460 * @} end of DCT4_IDCT4 group
emilmont 1:fdd22bb7aa52 461 */