1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mag_f32.c
4 * Description: Floating-point complex magnitude
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
32 * @ingroup groupCmplxMath
36 * @defgroup cmplx_mag Complex Magnitude
38 * Computes the magnitude of the elements of a complex data vector.
40 * The <code>pSrc</code> points to the source data and
41 * <code>pDst</code> points to the where the result should be written.
42 * <code>numSamples</code> specifies the number of complex samples
43 * in the input array and the data is stored in an interleaved fashion
44 * (real, imag, real, imag, ...).
45 * The input array has a total of <code>2*numSamples</code> values;
46 * the output array has a total of <code>numSamples</code> values.
47 * The underlying algorithm is used:
50 * for(n=0; n<numSamples; n++) {
51 * pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2);
55 * There are separate functions for floating-point, Q15, and Q31 data types.
59 * @addtogroup cmplx_mag
63 * @brief Floating-point complex magnitude.
64 * @param[in] *pSrc points to complex input buffer
65 * @param[out] *pDst points to real output buffer
66 * @param[in] numSamples number of complex samples in the input vector
72 void arm_cmplx_mag_f32(
77 float32_t realIn
, imagIn
; /* Temporary variables to hold input values */
79 #if defined (ARM_MATH_DSP)
81 /* Run the below code for Cortex-M4 and Cortex-M3 */
82 uint32_t blkCnt
; /* loop counter */
85 blkCnt
= numSamples
>> 2U;
87 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
88 ** a second loop below computes the remaining 1 to 3 samples. */
92 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
95 /* store the result in the destination buffer. */
96 arm_sqrt_f32((realIn
* realIn
) + (imagIn
* imagIn
), pDst
++);
100 arm_sqrt_f32((realIn
* realIn
) + (imagIn
* imagIn
), pDst
++);
104 arm_sqrt_f32((realIn
* realIn
) + (imagIn
* imagIn
), pDst
++);
108 arm_sqrt_f32((realIn
* realIn
) + (imagIn
* imagIn
), pDst
++);
111 /* Decrement the loop counter */
115 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
116 ** No loop unrolling is used. */
117 blkCnt
= numSamples
% 0x4U
;
121 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
124 /* store the result in the destination buffer. */
125 arm_sqrt_f32((realIn
* realIn
) + (imagIn
* imagIn
), pDst
++);
127 /* Decrement the loop counter */
133 /* Run the below code for Cortex-M0 */
135 while (numSamples
> 0U)
137 /* out = sqrt((real * real) + (imag * imag)) */
140 /* store the result in the destination buffer. */
141 arm_sqrt_f32((realIn
* realIn
) + (imagIn
* imagIn
), pDst
++);
143 /* Decrement the loop counter */
147 #endif /* #if defined (ARM_MATH_DSP) */
152 * @} end of cmplx_mag group