CMSIS DSP library
Dependents: KL25Z_FFT_Demo Hat_Board_v5_1 KL25Z_FFT_Demo_tony KL25Z_FFT_Demo_tony ... more
Fork of mbed-dsp by
arm_cmplx_dot_prod_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_dot_prod_f32.c 00009 * 00010 * Description: Floating-point complex dot product 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_dot_prod Complex Dot Product 00049 * 00050 * Computes the dot product of two complex vectors. 00051 * The vectors are multiplied element-by-element and then summed. 00052 * 00053 * The <code>pSrcA</code> points to the first complex input vector and 00054 * <code>pSrcB</code> points to the second complex input vector. 00055 * <code>numSamples</code> specifies the number of complex samples 00056 * and the data in each array is stored in an interleaved fashion 00057 * (real, imag, real, imag, ...). 00058 * Each array has a total of <code>2*numSamples</code> values. 00059 * 00060 * The underlying algorithm is used: 00061 * <pre> 00062 * realResult=0; 00063 * imagResult=0; 00064 * for(n=0; n<numSamples; n++) { 00065 * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1]; 00066 * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0]; 00067 * } 00068 * </pre> 00069 * 00070 * There are separate functions for floating-point, Q15, and Q31 data types. 00071 */ 00072 00073 /** 00074 * @addtogroup cmplx_dot_prod 00075 * @{ 00076 */ 00077 00078 /** 00079 * @brief Floating-point complex dot product 00080 * @param *pSrcA points to the first input vector 00081 * @param *pSrcB points to the second input vector 00082 * @param numSamples number of complex samples in each vector 00083 * @param *realResult real part of the result returned here 00084 * @param *imagResult imaginary part of the result returned here 00085 * @return none. 00086 */ 00087 00088 void arm_cmplx_dot_prod_f32( 00089 float32_t * pSrcA, 00090 float32_t * pSrcB, 00091 uint32_t numSamples, 00092 float32_t * realResult, 00093 float32_t * imagResult) 00094 { 00095 float32_t real_sum = 0.0f, imag_sum = 0.0f; /* Temporary result storage */ 00096 00097 #ifndef ARM_MATH_CM0_FAMILY 00098 00099 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00100 uint32_t blkCnt; /* loop counter */ 00101 00102 /*loop Unrolling */ 00103 blkCnt = numSamples >> 2u; 00104 00105 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00106 ** a second loop below computes the remaining 1 to 3 samples. */ 00107 while(blkCnt > 0u) 00108 { 00109 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ 00110 real_sum += (*pSrcA++) * (*pSrcB++); 00111 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ 00112 imag_sum += (*pSrcA++) * (*pSrcB++); 00113 00114 real_sum += (*pSrcA++) * (*pSrcB++); 00115 imag_sum += (*pSrcA++) * (*pSrcB++); 00116 00117 real_sum += (*pSrcA++) * (*pSrcB++); 00118 imag_sum += (*pSrcA++) * (*pSrcB++); 00119 00120 real_sum += (*pSrcA++) * (*pSrcB++); 00121 imag_sum += (*pSrcA++) * (*pSrcB++); 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 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ 00134 real_sum += (*pSrcA++) * (*pSrcB++); 00135 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ 00136 imag_sum += (*pSrcA++) * (*pSrcB++); 00137 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 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ 00150 real_sum += (*pSrcA++) * (*pSrcB++); 00151 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ 00152 imag_sum += (*pSrcA++) * (*pSrcB++); 00153 00154 00155 /* Decrement the loop counter */ 00156 numSamples--; 00157 } 00158 00159 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00160 00161 /* Store the real and imaginary results in the destination buffers */ 00162 *realResult = real_sum; 00163 *imagResult = imag_sum; 00164 } 00165 00166 /** 00167 * @} end of cmplx_dot_prod group 00168 */
Generated on Tue Jul 12 2022 12:36:54 by 1.7.2