1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mag_squared_q31.c
4 * Description: Q31 complex magnitude squared
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 * @addtogroup cmplx_mag_squared
42 * @brief Q31 complex magnitude squared
43 * @param *pSrc points to the complex input vector
44 * @param *pDst points to the real output vector
45 * @param numSamples number of complex samples in the input vector
48 * <b>Scaling and Overflow Behavior:</b>
50 * The function implements 1.31 by 1.31 multiplications and finally output is converted into 3.29 format.
51 * Input down scaling is not required.
54 void arm_cmplx_mag_squared_q31(
59 q31_t real
, imag
; /* Temporary variables to store real and imaginary values */
60 q31_t acc0
, acc1
; /* Accumulators */
62 #if defined (ARM_MATH_DSP)
64 /* Run the below code for Cortex-M4 and Cortex-M3 */
65 uint32_t blkCnt
; /* loop counter */
68 blkCnt
= numSamples
>> 2U;
70 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
71 ** a second loop below computes the remaining 1 to 3 samples. */
74 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
77 acc0
= (q31_t
) (((q63_t
) real
* real
) >> 33);
78 acc1
= (q31_t
) (((q63_t
) imag
* imag
) >> 33);
79 /* store the result in 3.29 format in the destination buffer. */
80 *pDst
++ = acc0
+ acc1
;
84 acc0
= (q31_t
) (((q63_t
) real
* real
) >> 33);
85 acc1
= (q31_t
) (((q63_t
) imag
* imag
) >> 33);
86 /* store the result in 3.29 format in the destination buffer. */
87 *pDst
++ = acc0
+ acc1
;
91 acc0
= (q31_t
) (((q63_t
) real
* real
) >> 33);
92 acc1
= (q31_t
) (((q63_t
) imag
* imag
) >> 33);
93 /* store the result in 3.29 format in the destination buffer. */
94 *pDst
++ = acc0
+ acc1
;
98 acc0
= (q31_t
) (((q63_t
) real
* real
) >> 33);
99 acc1
= (q31_t
) (((q63_t
) imag
* imag
) >> 33);
100 /* store the result in 3.29 format in the destination buffer. */
101 *pDst
++ = acc0
+ acc1
;
103 /* Decrement the loop counter */
107 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
108 ** No loop unrolling is used. */
109 blkCnt
= numSamples
% 0x4U
;
113 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
116 acc0
= (q31_t
) (((q63_t
) real
* real
) >> 33);
117 acc1
= (q31_t
) (((q63_t
) imag
* imag
) >> 33);
118 /* store the result in 3.29 format in the destination buffer. */
119 *pDst
++ = acc0
+ acc1
;
121 /* Decrement the loop counter */
127 /* Run the below code for Cortex-M0 */
129 while (numSamples
> 0U)
131 /* out = ((real * real) + (imag * imag)) */
134 acc0
= (q31_t
) (((q63_t
) real
* real
) >> 33);
135 acc1
= (q31_t
) (((q63_t
) imag
* imag
) >> 33);
136 /* store the result in 3.29 format in the destination buffer. */
137 *pDst
++ = acc0
+ acc1
;
139 /* Decrement the loop counter */
143 #endif /* #if defined (ARM_MATH_DSP) */
148 * @} end of cmplx_mag_squared group