Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / CMSIS / DSP / Source / ComplexMathFunctions / arm_cmplx_mag_f32.c
blob95aaf1eea661b3a40a1e8a13f9485f0a74fdd9f5
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mag_f32.c
4 * Description: Floating-point complex magnitude
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
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.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupCmplxMath
35 /**
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:
49 * <pre>
50 * for(n=0; n<numSamples; n++) {
51 * pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2);
52 * }
53 * </pre>
55 * There are separate functions for floating-point, Q15, and Q31 data types.
58 /**
59 * @addtogroup cmplx_mag
60 * @{
62 /**
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
67 * @return none.
72 void arm_cmplx_mag_f32(
73 float32_t * pSrc,
74 float32_t * pDst,
75 uint32_t numSamples)
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 */
84 /*loop Unrolling */
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. */
89 while (blkCnt > 0U)
92 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
93 realIn = *pSrc++;
94 imagIn = *pSrc++;
95 /* store the result in the destination buffer. */
96 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
98 realIn = *pSrc++;
99 imagIn = *pSrc++;
100 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
102 realIn = *pSrc++;
103 imagIn = *pSrc++;
104 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
106 realIn = *pSrc++;
107 imagIn = *pSrc++;
108 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
111 /* Decrement the loop counter */
112 blkCnt--;
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;
119 while (blkCnt > 0U)
121 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
122 realIn = *pSrc++;
123 imagIn = *pSrc++;
124 /* store the result in the destination buffer. */
125 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
127 /* Decrement the loop counter */
128 blkCnt--;
131 #else
133 /* Run the below code for Cortex-M0 */
135 while (numSamples > 0U)
137 /* out = sqrt((real * real) + (imag * imag)) */
138 realIn = *pSrc++;
139 imagIn = *pSrc++;
140 /* store the result in the destination buffer. */
141 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
143 /* Decrement the loop counter */
144 numSamples--;
147 #endif /* #if defined (ARM_MATH_DSP) */
152 * @} end of cmplx_mag group