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

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?

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