Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / CMSIS / DSP / Source / ComplexMathFunctions / arm_cmplx_mag_squared_f32.c
blob59127a2298928e4798b1097598c16619b24bd108
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mag_squared_f32.c
4 * Description: Floating-point complex magnitude squared
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_squared Complex Magnitude Squared
38 * Computes the magnitude squared 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.
48 * The underlying algorithm is used:
50 * <pre>
51 * for(n=0; n<numSamples; n++) {
52 * pDst[n] = pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2;
53 * }
54 * </pre>
56 * There are separate functions for floating-point, Q15, and Q31 data types.
59 /**
60 * @addtogroup cmplx_mag_squared
61 * @{
65 /**
66 * @brief Floating-point complex magnitude squared
67 * @param[in] *pSrc points to the complex input vector
68 * @param[out] *pDst points to the real output vector
69 * @param[in] numSamples number of complex samples in the input vector
70 * @return none.
73 void arm_cmplx_mag_squared_f32(
74 float32_t * pSrc,
75 float32_t * pDst,
76 uint32_t numSamples)
78 float32_t real, imag; /* Temporary variables to store real and imaginary values */
79 uint32_t blkCnt; /* loop counter */
81 #if defined (ARM_MATH_DSP)
82 float32_t real1, real2, real3, real4; /* Temporary variables to hold real values */
83 float32_t imag1, imag2, imag3, imag4; /* Temporary variables to hold imaginary values */
84 float32_t mul1, mul2, mul3, mul4; /* Temporary variables */
85 float32_t mul5, mul6, mul7, mul8; /* Temporary variables */
86 float32_t out1, out2, out3, out4; /* Temporary variables to hold output values */
88 /*loop Unrolling */
89 blkCnt = numSamples >> 2U;
91 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
92 ** a second loop below computes the remaining 1 to 3 samples. */
93 while (blkCnt > 0U)
95 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
96 /* read real input sample from source buffer */
97 real1 = pSrc[0];
98 /* read imaginary input sample from source buffer */
99 imag1 = pSrc[1];
101 /* calculate power of real value */
102 mul1 = real1 * real1;
104 /* read real input sample from source buffer */
105 real2 = pSrc[2];
107 /* calculate power of imaginary value */
108 mul2 = imag1 * imag1;
110 /* read imaginary input sample from source buffer */
111 imag2 = pSrc[3];
113 /* calculate power of real value */
114 mul3 = real2 * real2;
116 /* read real input sample from source buffer */
117 real3 = pSrc[4];
119 /* calculate power of imaginary value */
120 mul4 = imag2 * imag2;
122 /* read imaginary input sample from source buffer */
123 imag3 = pSrc[5];
125 /* calculate power of real value */
126 mul5 = real3 * real3;
127 /* calculate power of imaginary value */
128 mul6 = imag3 * imag3;
130 /* read real input sample from source buffer */
131 real4 = pSrc[6];
133 /* accumulate real and imaginary powers */
134 out1 = mul1 + mul2;
136 /* read imaginary input sample from source buffer */
137 imag4 = pSrc[7];
139 /* accumulate real and imaginary powers */
140 out2 = mul3 + mul4;
142 /* calculate power of real value */
143 mul7 = real4 * real4;
144 /* calculate power of imaginary value */
145 mul8 = imag4 * imag4;
147 /* store output to destination */
148 pDst[0] = out1;
150 /* accumulate real and imaginary powers */
151 out3 = mul5 + mul6;
153 /* store output to destination */
154 pDst[1] = out2;
156 /* accumulate real and imaginary powers */
157 out4 = mul7 + mul8;
159 /* store output to destination */
160 pDst[2] = out3;
162 /* increment destination pointer by 8 to process next samples */
163 pSrc += 8U;
165 /* store output to destination */
166 pDst[3] = out4;
168 /* increment destination pointer by 4 to process next samples */
169 pDst += 4U;
171 /* Decrement the loop counter */
172 blkCnt--;
175 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
176 ** No loop unrolling is used. */
177 blkCnt = numSamples % 0x4U;
179 #else
181 /* Run the below code for Cortex-M0 */
183 blkCnt = numSamples;
185 #endif /* #if defined (ARM_MATH_DSP) */
187 while (blkCnt > 0U)
189 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
190 real = *pSrc++;
191 imag = *pSrc++;
193 /* out = (real * real) + (imag * imag) */
194 /* store the result in the destination buffer. */
195 *pDst++ = (real * real) + (imag * imag);
197 /* Decrement the loop counter */
198 blkCnt--;
203 * @} end of cmplx_mag_squared group