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_f32.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_cmplx_mag_f32.c 00004 * Description: Floating-point complex magnitude 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 * @defgroup cmplx_mag Complex Magnitude 00037 * 00038 * Computes the magnitude of the elements of a complex data vector. 00039 * 00040 * The <code>pSrc</code> points to the source data and 00041 * <code>pDst</code> points to the where the result should be written. 00042 * <code>numSamples</code> specifies the number of complex samples 00043 * in the input array and the data is stored in an interleaved fashion 00044 * (real, imag, real, imag, ...). 00045 * The input array has a total of <code>2*numSamples</code> values; 00046 * the output array has a total of <code>numSamples</code> values. 00047 * The underlying algorithm is used: 00048 * 00049 * <pre> 00050 * for(n=0; n<numSamples; n++) { 00051 * pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2); 00052 * } 00053 * </pre> 00054 * 00055 * There are separate functions for floating-point, Q15, and Q31 data types. 00056 */ 00057 00058 /** 00059 * @addtogroup cmplx_mag 00060 * @{ 00061 */ 00062 /** 00063 * @brief Floating-point complex magnitude. 00064 * @param[in] *pSrc points to complex input buffer 00065 * @param[out] *pDst points to real output buffer 00066 * @param[in] numSamples number of complex samples in the input vector 00067 * @return none. 00068 * 00069 */ 00070 00071 00072 void arm_cmplx_mag_f32( 00073 float32_t * pSrc, 00074 float32_t * pDst, 00075 uint32_t numSamples) 00076 { 00077 float32_t realIn, imagIn; /* Temporary variables to hold input values */ 00078 00079 #if defined (ARM_MATH_DSP) 00080 00081 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00082 uint32_t blkCnt; /* loop counter */ 00083 00084 /*loop Unrolling */ 00085 blkCnt = numSamples >> 2U; 00086 00087 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00088 ** a second loop below computes the remaining 1 to 3 samples. */ 00089 while (blkCnt > 0U) 00090 { 00091 00092 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ 00093 realIn = *pSrc++; 00094 imagIn = *pSrc++; 00095 /* store the result in the destination buffer. */ 00096 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00097 00098 realIn = *pSrc++; 00099 imagIn = *pSrc++; 00100 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00101 00102 realIn = *pSrc++; 00103 imagIn = *pSrc++; 00104 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00105 00106 realIn = *pSrc++; 00107 imagIn = *pSrc++; 00108 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00109 00110 00111 /* Decrement the loop counter */ 00112 blkCnt--; 00113 } 00114 00115 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00116 ** No loop unrolling is used. */ 00117 blkCnt = numSamples % 0x4U; 00118 00119 while (blkCnt > 0U) 00120 { 00121 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ 00122 realIn = *pSrc++; 00123 imagIn = *pSrc++; 00124 /* store the result in the destination buffer. */ 00125 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00126 00127 /* Decrement the loop counter */ 00128 blkCnt--; 00129 } 00130 00131 #else 00132 00133 /* Run the below code for Cortex-M0 */ 00134 00135 while (numSamples > 0U) 00136 { 00137 /* out = sqrt((real * real) + (imag * imag)) */ 00138 realIn = *pSrc++; 00139 imagIn = *pSrc++; 00140 /* store the result in the destination buffer. */ 00141 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00142 00143 /* Decrement the loop counter */ 00144 numSamples--; 00145 } 00146 00147 #endif /* #if defined (ARM_MATH_DSP) */ 00148 00149 } 00150 00151 /** 00152 * @} end of cmplx_mag group 00153 */ 00154
Generated on Tue Jul 12 2022 16:46:23 by
 1.7.2
 1.7.2