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.
Fork of mbed-dsp by
arm_cmplx_mag_f32.c
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010-2013 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 17. January 2013 00005 * $Revision: V1.4.1 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_cmplx_mag_f32.c 00009 * 00010 * Description: Floating-point complex magnitude. 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions 00016 * are met: 00017 * - Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in 00021 * the documentation and/or other materials provided with the 00022 * distribution. 00023 * - Neither the name of ARM LIMITED nor the names of its contributors 00024 * may be used to endorse or promote products derived from this 00025 * software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00028 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00029 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00030 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00031 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00033 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00034 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00036 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00037 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * ---------------------------------------------------------------------------- */ 00040 00041 #include "arm_math.h" 00042 00043 /** 00044 * @ingroup groupCmplxMath 00045 */ 00046 00047 /** 00048 * @defgroup cmplx_mag Complex Magnitude 00049 * 00050 * Computes the magnitude of the elements of a complex data vector. 00051 * 00052 * The <code>pSrc</code> points to the source data and 00053 * <code>pDst</code> points to the where the result should be written. 00054 * <code>numSamples</code> specifies the number of complex samples 00055 * in the input array and the data is stored in an interleaved fashion 00056 * (real, imag, real, imag, ...). 00057 * The input array has a total of <code>2*numSamples</code> values; 00058 * the output array has a total of <code>numSamples</code> values. 00059 * The underlying algorithm is used: 00060 * 00061 * <pre> 00062 * for(n=0; n<numSamples; n++) { 00063 * pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2); 00064 * } 00065 * </pre> 00066 * 00067 * There are separate functions for floating-point, Q15, and Q31 data types. 00068 */ 00069 00070 /** 00071 * @addtogroup cmplx_mag 00072 * @{ 00073 */ 00074 /** 00075 * @brief Floating-point complex magnitude. 00076 * @param[in] *pSrc points to complex input buffer 00077 * @param[out] *pDst points to real output buffer 00078 * @param[in] numSamples number of complex samples in the input vector 00079 * @return none. 00080 * 00081 */ 00082 00083 00084 void arm_cmplx_mag_f32( 00085 float32_t * pSrc, 00086 float32_t * pDst, 00087 uint32_t numSamples) 00088 { 00089 float32_t realIn, imagIn; /* Temporary variables to hold input values */ 00090 00091 #ifndef ARM_MATH_CM0_FAMILY 00092 00093 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00094 uint32_t blkCnt; /* loop counter */ 00095 00096 /*loop Unrolling */ 00097 blkCnt = numSamples >> 2u; 00098 00099 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00100 ** a second loop below computes the remaining 1 to 3 samples. */ 00101 while(blkCnt > 0u) 00102 { 00103 00104 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ 00105 realIn = *pSrc++; 00106 imagIn = *pSrc++; 00107 /* store the result in the destination buffer. */ 00108 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00109 00110 realIn = *pSrc++; 00111 imagIn = *pSrc++; 00112 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00113 00114 realIn = *pSrc++; 00115 imagIn = *pSrc++; 00116 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00117 00118 realIn = *pSrc++; 00119 imagIn = *pSrc++; 00120 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00121 00122 00123 /* Decrement the loop counter */ 00124 blkCnt--; 00125 } 00126 00127 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00128 ** No loop unrolling is used. */ 00129 blkCnt = numSamples % 0x4u; 00130 00131 while(blkCnt > 0u) 00132 { 00133 /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ 00134 realIn = *pSrc++; 00135 imagIn = *pSrc++; 00136 /* store the result in the destination buffer. */ 00137 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00138 00139 /* Decrement the loop counter */ 00140 blkCnt--; 00141 } 00142 00143 #else 00144 00145 /* Run the below code for Cortex-M0 */ 00146 00147 while(numSamples > 0u) 00148 { 00149 /* out = sqrt((real * real) + (imag * imag)) */ 00150 realIn = *pSrc++; 00151 imagIn = *pSrc++; 00152 /* store the result in the destination buffer. */ 00153 arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++); 00154 00155 /* Decrement the loop counter */ 00156 numSamples--; 00157 } 00158 00159 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00160 00161 } 00162 00163 /** 00164 * @} end of cmplx_mag group 00165 */
Generated on Tue Jul 12 2022 18:44:08 by
1.7.2
