Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* ---------------------------------------------------------------------- |
2 | * Project: CMSIS DSP Library |
||
3 | * Title: arm_cmplx_mag_squared_q31.c |
||
4 | * Description: Q31 complex magnitude squared |
||
5 | * |
||
6 | * $Date: 27. January 2017 |
||
7 | * $Revision: V.1.5.1 |
||
8 | * |
||
9 | * Target Processor: Cortex-M cores |
||
10 | * -------------------------------------------------------------------- */ |
||
11 | /* |
||
12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
||
13 | * |
||
14 | * SPDX-License-Identifier: Apache-2.0 |
||
15 | * |
||
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 |
||
19 | * |
||
20 | * www.apache.org/licenses/LICENSE-2.0 |
||
21 | * |
||
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. |
||
27 | */ |
||
28 | |||
29 | #include "arm_math.h" |
||
30 | |||
31 | /** |
||
32 | * @ingroup groupCmplxMath |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * @addtogroup cmplx_mag_squared |
||
37 | * @{ |
||
38 | */ |
||
39 | |||
40 | |||
41 | /** |
||
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 |
||
46 | * @return none. |
||
47 | * |
||
48 | * <b>Scaling and Overflow Behavior:</b> |
||
49 | * \par |
||
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. |
||
52 | */ |
||
53 | |||
54 | void arm_cmplx_mag_squared_q31( |
||
55 | q31_t * pSrc, |
||
56 | q31_t * pDst, |
||
57 | uint32_t numSamples) |
||
58 | { |
||
59 | q31_t real, imag; /* Temporary variables to store real and imaginary values */ |
||
60 | q31_t acc0, acc1; /* Accumulators */ |
||
61 | |||
62 | #if defined (ARM_MATH_DSP) |
||
63 | |||
64 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
||
65 | uint32_t blkCnt; /* loop counter */ |
||
66 | |||
67 | /* loop Unrolling */ |
||
68 | blkCnt = numSamples >> 2U; |
||
69 | |||
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. */ |
||
72 | while (blkCnt > 0U) |
||
73 | { |
||
74 | /* C[0] = (A[0] * A[0] + A[1] * A[1]) */ |
||
75 | real = *pSrc++; |
||
76 | imag = *pSrc++; |
||
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; |
||
81 | |||
82 | real = *pSrc++; |
||
83 | imag = *pSrc++; |
||
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; |
||
88 | |||
89 | real = *pSrc++; |
||
90 | imag = *pSrc++; |
||
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; |
||
95 | |||
96 | real = *pSrc++; |
||
97 | imag = *pSrc++; |
||
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; |
||
102 | |||
103 | /* Decrement the loop counter */ |
||
104 | blkCnt--; |
||
105 | } |
||
106 | |||
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; |
||
110 | |||
111 | while (blkCnt > 0U) |
||
112 | { |
||
113 | /* C[0] = (A[0] * A[0] + A[1] * A[1]) */ |
||
114 | real = *pSrc++; |
||
115 | imag = *pSrc++; |
||
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; |
||
120 | |||
121 | /* Decrement the loop counter */ |
||
122 | blkCnt--; |
||
123 | } |
||
124 | |||
125 | #else |
||
126 | |||
127 | /* Run the below code for Cortex-M0 */ |
||
128 | |||
129 | while (numSamples > 0U) |
||
130 | { |
||
131 | /* out = ((real * real) + (imag * imag)) */ |
||
132 | real = *pSrc++; |
||
133 | imag = *pSrc++; |
||
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; |
||
138 | |||
139 | /* Decrement the loop counter */ |
||
140 | numSamples--; |
||
141 | } |
||
142 | |||
143 | #endif /* #if defined (ARM_MATH_DSP) */ |
||
144 | |||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @} end of cmplx_mag_squared group |
||
149 | */ |