1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_dot_prod_f32.c
4 * Description: Floating-point complex dot product
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
32 * @ingroup groupCmplxMath
36 * @defgroup cmplx_dot_prod Complex Dot Product
38 * Computes the dot product of two complex vectors.
39 * The vectors are multiplied element-by-element and then summed.
41 * The <code>pSrcA</code> points to the first complex input vector and
42 * <code>pSrcB</code> points to the second complex input vector.
43 * <code>numSamples</code> specifies the number of complex samples
44 * and the data in each array is stored in an interleaved fashion
45 * (real, imag, real, imag, ...).
46 * Each array has a total of <code>2*numSamples</code> values.
48 * The underlying algorithm is used:
52 * for(n=0; n<numSamples; n++) {
53 * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1];
54 * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0];
58 * There are separate functions for floating-point, Q15, and Q31 data types.
62 * @addtogroup cmplx_dot_prod
67 * @brief Floating-point complex dot product
68 * @param *pSrcA points to the first input vector
69 * @param *pSrcB points to the second input vector
70 * @param numSamples number of complex samples in each vector
71 * @param *realResult real part of the result returned here
72 * @param *imagResult imaginary part of the result returned here
76 void arm_cmplx_dot_prod_f32(
80 float32_t
* realResult
,
81 float32_t
* imagResult
)
83 float32_t real_sum
= 0.0f
, imag_sum
= 0.0f
; /* Temporary result storage */
84 float32_t a0
,b0
,c0
,d0
;
86 #if defined (ARM_MATH_DSP)
88 /* Run the below code for Cortex-M4 and Cortex-M3 */
89 uint32_t blkCnt
; /* loop counter */
92 blkCnt
= numSamples
>> 2U;
94 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
95 ** a second loop below computes the remaining 1 to 3 samples. */
138 /* Decrement the loop counter */
142 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
143 ** No loop unrolling is used. */
144 blkCnt
= numSamples
& 0x3U
;
158 /* Decrement the loop counter */
164 /* Run the below code for Cortex-M0 */
166 while (numSamples
> 0U)
178 /* Decrement the loop counter */
182 #endif /* #if defined (ARM_MATH_DSP) */
184 /* Store the real and imaginary results in the destination buffers */
185 *realResult
= real_sum
;
186 *imagResult
= imag_sum
;
190 * @} end of cmplx_dot_prod group