]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/dsp/cmsis_dsp/ComplexMathFunctions/arm_cmplx_dot_prod_f32.c
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_cmplx_dot_prod_f32.c
10 * Description: Floating-point complex dot product
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
23 * - Neither the name of ARM LIMITED nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 * ---------------------------------------------------------------------------- */
44 * @ingroup groupCmplxMath
48 * @defgroup cmplx_dot_prod Complex Dot Product
50 * Computes the dot product of two complex vectors.
51 * The vectors are multiplied element-by-element and then summed.
53 * The <code>pSrcA</code> points to the first complex input vector and
54 * <code>pSrcB</code> points to the second complex input vector.
55 * <code>numSamples</code> specifies the number of complex samples
56 * and the data in each array is stored in an interleaved fashion
57 * (real, imag, real, imag, ...).
58 * Each array has a total of <code>2*numSamples</code> values.
60 * The underlying algorithm is used:
64 * for(n=0; n<numSamples; n++) {
65 * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1];
66 * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0];
70 * There are separate functions for floating-point, Q15, and Q31 data types.
74 * @addtogroup cmplx_dot_prod
79 * @brief Floating-point complex dot product
80 * @param *pSrcA points to the first input vector
81 * @param *pSrcB points to the second input vector
82 * @param numSamples number of complex samples in each vector
83 * @param *realResult real part of the result returned here
84 * @param *imagResult imaginary part of the result returned here
88 void arm_cmplx_dot_prod_f32(
92 float32_t
* realResult
,
93 float32_t
* imagResult
)
95 float32_t real_sum
= 0.0f
, imag_sum
= 0.0f
; /* Temporary result storage */
97 #ifndef ARM_MATH_CM0_FAMILY
99 /* Run the below code for Cortex-M4 and Cortex-M3 */
100 uint32_t blkCnt
; /* loop counter */
103 blkCnt
= numSamples
>> 2u;
105 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
106 ** a second loop below computes the remaining 1 to 3 samples. */
109 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
110 real_sum
+= (*pSrcA
++) * (*pSrcB
++);
111 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
112 imag_sum
+= (*pSrcA
++) * (*pSrcB
++);
114 real_sum
+= (*pSrcA
++) * (*pSrcB
++);
115 imag_sum
+= (*pSrcA
++) * (*pSrcB
++);
117 real_sum
+= (*pSrcA
++) * (*pSrcB
++);
118 imag_sum
+= (*pSrcA
++) * (*pSrcB
++);
120 real_sum
+= (*pSrcA
++) * (*pSrcB
++);
121 imag_sum
+= (*pSrcA
++) * (*pSrcB
++);
123 /* Decrement the loop counter */
127 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
128 ** No loop unrolling is used. */
129 blkCnt
= numSamples
% 0x4u
;
133 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
134 real_sum
+= (*pSrcA
++) * (*pSrcB
++);
135 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
136 imag_sum
+= (*pSrcA
++) * (*pSrcB
++);
139 /* Decrement the loop counter */
145 /* Run the below code for Cortex-M0 */
147 while(numSamples
> 0u)
149 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
150 real_sum
+= (*pSrcA
++) * (*pSrcB
++);
151 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
152 imag_sum
+= (*pSrcA
++) * (*pSrcB
++);
155 /* Decrement the loop counter */
159 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
161 /* Store the real and imaginary results in the destination buffers */
162 *realResult
= real_sum
;
163 *imagResult
= imag_sum
;
167 * @} end of cmplx_dot_prod group