Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
arm_cmplx_mag_squared_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_cmplx_mag_squared_q31.c 00004 * Description: Q31 complex magnitude squared 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 #include "arm_math.h" 00030 00031 /** 00032 * @ingroup groupCmplxMath 00033 */ 00034 00035 /** 00036 * @addtogroup cmplx_mag_squared 00037 * @{ 00038 */ 00039 00040 00041 /** 00042 * @brief Q31 complex magnitude squared 00043 * @param *pSrc points to the complex input vector 00044 * @param *pDst points to the real output vector 00045 * @param numSamples number of complex samples in the input vector 00046 * @return none. 00047 * 00048 * <b>Scaling and Overflow Behavior:</b> 00049 * \par 00050 * The function implements 1.31 by 1.31 multiplications and finally output is converted into 3.29 format. 00051 * Input down scaling is not required. 00052 */ 00053 00054 void arm_cmplx_mag_squared_q31( 00055 q31_t * pSrc, 00056 q31_t * pDst, 00057 uint32_t numSamples) 00058 { 00059 q31_t real, imag; /* Temporary variables to store real and imaginary values */ 00060 q31_t acc0, acc1; /* Accumulators */ 00061 00062 #if defined (ARM_MATH_DSP) 00063 00064 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00065 uint32_t blkCnt; /* loop counter */ 00066 00067 /* loop Unrolling */ 00068 blkCnt = numSamples >> 2U; 00069 00070 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00071 ** a second loop below computes the remaining 1 to 3 samples. */ 00072 while (blkCnt > 0U) 00073 { 00074 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */ 00075 real = *pSrc++; 00076 imag = *pSrc++; 00077 acc0 = (q31_t) (((q63_t) real * real) >> 33); 00078 acc1 = (q31_t) (((q63_t) imag * imag) >> 33); 00079 /* store the result in 3.29 format in the destination buffer. */ 00080 *pDst++ = acc0 + acc1; 00081 00082 real = *pSrc++; 00083 imag = *pSrc++; 00084 acc0 = (q31_t) (((q63_t) real * real) >> 33); 00085 acc1 = (q31_t) (((q63_t) imag * imag) >> 33); 00086 /* store the result in 3.29 format in the destination buffer. */ 00087 *pDst++ = acc0 + acc1; 00088 00089 real = *pSrc++; 00090 imag = *pSrc++; 00091 acc0 = (q31_t) (((q63_t) real * real) >> 33); 00092 acc1 = (q31_t) (((q63_t) imag * imag) >> 33); 00093 /* store the result in 3.29 format in the destination buffer. */ 00094 *pDst++ = acc0 + acc1; 00095 00096 real = *pSrc++; 00097 imag = *pSrc++; 00098 acc0 = (q31_t) (((q63_t) real * real) >> 33); 00099 acc1 = (q31_t) (((q63_t) imag * imag) >> 33); 00100 /* store the result in 3.29 format in the destination buffer. */ 00101 *pDst++ = acc0 + acc1; 00102 00103 /* Decrement the loop counter */ 00104 blkCnt--; 00105 } 00106 00107 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00108 ** No loop unrolling is used. */ 00109 blkCnt = numSamples % 0x4U; 00110 00111 while (blkCnt > 0U) 00112 { 00113 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */ 00114 real = *pSrc++; 00115 imag = *pSrc++; 00116 acc0 = (q31_t) (((q63_t) real * real) >> 33); 00117 acc1 = (q31_t) (((q63_t) imag * imag) >> 33); 00118 /* store the result in 3.29 format in the destination buffer. */ 00119 *pDst++ = acc0 + acc1; 00120 00121 /* Decrement the loop counter */ 00122 blkCnt--; 00123 } 00124 00125 #else 00126 00127 /* Run the below code for Cortex-M0 */ 00128 00129 while (numSamples > 0U) 00130 { 00131 /* out = ((real * real) + (imag * imag)) */ 00132 real = *pSrc++; 00133 imag = *pSrc++; 00134 acc0 = (q31_t) (((q63_t) real * real) >> 33); 00135 acc1 = (q31_t) (((q63_t) imag * imag) >> 33); 00136 /* store the result in 3.29 format in the destination buffer. */ 00137 *pDst++ = acc0 + acc1; 00138 00139 /* Decrement the loop counter */ 00140 numSamples--; 00141 } 00142 00143 #endif /* #if defined (ARM_MATH_DSP) */ 00144 00145 } 00146 00147 /** 00148 * @} end of cmplx_mag_squared group 00149 */ 00150
Generated on Tue Jul 12 2022 16:46:23 by
1.7.2