1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_cmplx_mag_f32.c
10 * Description: Floating-point complex magnitude.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
28 * ---------------------------------------------------------------------------- */
33 * @ingroup groupCmplxMath
37 * @defgroup cmplx_mag Complex Magnitude
39 * Computes the magnitude of the elements of a complex data vector.
41 * The <code>pSrc</code> points to the source data and
42 * <code>pDst</code> points to the where the result should be written.
43 * <code>numSamples</code> specifies the number of complex samples
44 * in the input array and the data is stored in an interleaved fashion
45 * (real, imag, real, imag, ...).
46 * The input array has a total of <code>2*numSamples</code> values;
47 * the output array has a total of <code>numSamples</code> values.
48 * The underlying algorithm is used:
51 * for(n=0; n<numSamples; n++) {
52 * pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2);
56 * There are separate functions for floating-point, Q15, and Q31 data types.
60 * @addtogroup cmplx_mag
64 * @brief Floating-point complex magnitude.
65 * @param[in] *pSrc points to complex input buffer
66 * @param[out] *pDst points to real output buffer
67 * @param[in] numSamples number of complex samples in the input vector
73 void arm_cmplx_mag_f32(
78 float32_t realIn, imagIn; /* Temporary variables to hold input values */
82 /* Run the below code for Cortex-M4 and Cortex-M3 */
83 uint32_t blkCnt; /* loop counter */
86 blkCnt = numSamples >> 2u;
88 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
89 ** a second loop below computes the remaining 1 to 3 samples. */
93 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
96 /* store the result in the destination buffer. */
97 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
101 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
105 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
109 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
112 /* Decrement the loop counter */
116 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
117 ** No loop unrolling is used. */
118 blkCnt = numSamples % 0x4u;
122 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
125 /* store the result in the destination buffer. */
126 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
128 /* Decrement the loop counter */
134 /* Run the below code for Cortex-M0 */
136 while(numSamples > 0u)
138 /* out = sqrt((real * real) + (imag * imag)) */
141 /* store the result in the destination buffer. */
142 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
144 /* Decrement the loop counter */
148 #endif /* #ifndef ARM_MATH_CM0 */
153 * @} end of cmplx_mag group