Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* ---------------------------------------------------------------------- |
| 2 | * Project: CMSIS DSP Library |
||
| 3 | * Title: arm_cmplx_mag_q15.c |
||
| 4 | * Description: Q15 complex magnitude |
||
| 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 |
||
| 37 | * @{ |
||
| 38 | */ |
||
| 39 | |||
| 40 | |||
| 41 | /** |
||
| 42 | * @brief Q15 complex magnitude |
||
| 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.15 by 1.15 multiplications and finally output is converted into 2.14 format. |
||
| 51 | */ |
||
| 52 | |||
| 53 | void arm_cmplx_mag_q15( |
||
| 54 | q15_t * pSrc, |
||
| 55 | q15_t * pDst, |
||
| 56 | uint32_t numSamples) |
||
| 57 | { |
||
| 58 | q31_t acc0, acc1; /* Accumulators */ |
||
| 59 | |||
| 60 | #if defined (ARM_MATH_DSP) |
||
| 61 | |||
| 62 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
||
| 63 | uint32_t blkCnt; /* loop counter */ |
||
| 64 | q31_t in1, in2, in3, in4; |
||
| 65 | q31_t acc2, acc3; |
||
| 66 | |||
| 67 | |||
| 68 | /*loop Unrolling */ |
||
| 69 | blkCnt = numSamples >> 2U; |
||
| 70 | |||
| 71 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
||
| 72 | ** a second loop below computes the remaining 1 to 3 samples. */ |
||
| 73 | while (blkCnt > 0U) |
||
| 74 | { |
||
| 75 | |||
| 76 | /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ |
||
| 77 | in1 = *__SIMD32(pSrc)++; |
||
| 78 | in2 = *__SIMD32(pSrc)++; |
||
| 79 | in3 = *__SIMD32(pSrc)++; |
||
| 80 | in4 = *__SIMD32(pSrc)++; |
||
| 81 | |||
| 82 | acc0 = __SMUAD(in1, in1); |
||
| 83 | acc1 = __SMUAD(in2, in2); |
||
| 84 | acc2 = __SMUAD(in3, in3); |
||
| 85 | acc3 = __SMUAD(in4, in4); |
||
| 86 | |||
| 87 | /* store the result in 2.14 format in the destination buffer. */ |
||
| 88 | arm_sqrt_q15((q15_t) ((acc0) >> 17), pDst++); |
||
| 89 | arm_sqrt_q15((q15_t) ((acc1) >> 17), pDst++); |
||
| 90 | arm_sqrt_q15((q15_t) ((acc2) >> 17), pDst++); |
||
| 91 | arm_sqrt_q15((q15_t) ((acc3) >> 17), pDst++); |
||
| 92 | |||
| 93 | /* Decrement the loop counter */ |
||
| 94 | blkCnt--; |
||
| 95 | } |
||
| 96 | |||
| 97 | /* If the numSamples is not a multiple of 4, compute any remaining output samples here. |
||
| 98 | ** No loop unrolling is used. */ |
||
| 99 | blkCnt = numSamples % 0x4U; |
||
| 100 | |||
| 101 | while (blkCnt > 0U) |
||
| 102 | { |
||
| 103 | /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ |
||
| 104 | in1 = *__SIMD32(pSrc)++; |
||
| 105 | acc0 = __SMUAD(in1, in1); |
||
| 106 | |||
| 107 | /* store the result in 2.14 format in the destination buffer. */ |
||
| 108 | arm_sqrt_q15((q15_t) (acc0 >> 17), pDst++); |
||
| 109 | |||
| 110 | /* Decrement the loop counter */ |
||
| 111 | blkCnt--; |
||
| 112 | } |
||
| 113 | |||
| 114 | #else |
||
| 115 | |||
| 116 | /* Run the below code for Cortex-M0 */ |
||
| 117 | q15_t real, imag; /* Temporary variables to hold input values */ |
||
| 118 | |||
| 119 | while (numSamples > 0U) |
||
| 120 | { |
||
| 121 | /* out = sqrt(real * real + imag * imag) */ |
||
| 122 | real = *pSrc++; |
||
| 123 | imag = *pSrc++; |
||
| 124 | |||
| 125 | acc0 = (real * real); |
||
| 126 | acc1 = (imag * imag); |
||
| 127 | |||
| 128 | /* store the result in 2.14 format in the destination buffer. */ |
||
| 129 | arm_sqrt_q15((q15_t) (((q63_t) acc0 + acc1) >> 17), pDst++); |
||
| 130 | |||
| 131 | /* Decrement the loop counter */ |
||
| 132 | numSamples--; |
||
| 133 | } |
||
| 134 | |||
| 135 | #endif /* #if defined (ARM_MATH_DSP) */ |
||
| 136 | |||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @} end of cmplx_mag group |
||
| 141 | */ |