The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Thu Jun 21 11:56:27 2018 +0000
Revision:
3:4098b9d3d571
Parent:
1:24714b45cd1b
headers is a folder not a library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xorjoep 1:24714b45cd1b 1 /* ----------------------------------------------------------------------
xorjoep 1:24714b45cd1b 2 * Project: CMSIS DSP Library
xorjoep 1:24714b45cd1b 3 * Title: arm_cmplx_dot_prod_f32.c
xorjoep 1:24714b45cd1b 4 * Description: Floating-point complex dot product
xorjoep 1:24714b45cd1b 5 *
xorjoep 1:24714b45cd1b 6 * $Date: 27. January 2017
xorjoep 1:24714b45cd1b 7 * $Revision: V.1.5.1
xorjoep 1:24714b45cd1b 8 *
xorjoep 1:24714b45cd1b 9 * Target Processor: Cortex-M cores
xorjoep 1:24714b45cd1b 10 * -------------------------------------------------------------------- */
xorjoep 1:24714b45cd1b 11 /*
xorjoep 1:24714b45cd1b 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
xorjoep 1:24714b45cd1b 13 *
xorjoep 1:24714b45cd1b 14 * SPDX-License-Identifier: Apache-2.0
xorjoep 1:24714b45cd1b 15 *
xorjoep 1:24714b45cd1b 16 * Licensed under the Apache License, Version 2.0 (the License); you may
xorjoep 1:24714b45cd1b 17 * not use this file except in compliance with the License.
xorjoep 1:24714b45cd1b 18 * You may obtain a copy of the License at
xorjoep 1:24714b45cd1b 19 *
xorjoep 1:24714b45cd1b 20 * www.apache.org/licenses/LICENSE-2.0
xorjoep 1:24714b45cd1b 21 *
xorjoep 1:24714b45cd1b 22 * Unless required by applicable law or agreed to in writing, software
xorjoep 1:24714b45cd1b 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
xorjoep 1:24714b45cd1b 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
xorjoep 1:24714b45cd1b 25 * See the License for the specific language governing permissions and
xorjoep 1:24714b45cd1b 26 * limitations under the License.
xorjoep 1:24714b45cd1b 27 */
xorjoep 1:24714b45cd1b 28
xorjoep 1:24714b45cd1b 29 #include "arm_math.h"
xorjoep 1:24714b45cd1b 30
xorjoep 1:24714b45cd1b 31 /**
xorjoep 1:24714b45cd1b 32 * @ingroup groupCmplxMath
xorjoep 1:24714b45cd1b 33 */
xorjoep 1:24714b45cd1b 34
xorjoep 1:24714b45cd1b 35 /**
xorjoep 1:24714b45cd1b 36 * @defgroup cmplx_dot_prod Complex Dot Product
xorjoep 1:24714b45cd1b 37 *
xorjoep 1:24714b45cd1b 38 * Computes the dot product of two complex vectors.
xorjoep 1:24714b45cd1b 39 * The vectors are multiplied element-by-element and then summed.
xorjoep 1:24714b45cd1b 40 *
xorjoep 1:24714b45cd1b 41 * The <code>pSrcA</code> points to the first complex input vector and
xorjoep 1:24714b45cd1b 42 * <code>pSrcB</code> points to the second complex input vector.
xorjoep 1:24714b45cd1b 43 * <code>numSamples</code> specifies the number of complex samples
xorjoep 1:24714b45cd1b 44 * and the data in each array is stored in an interleaved fashion
xorjoep 1:24714b45cd1b 45 * (real, imag, real, imag, ...).
xorjoep 1:24714b45cd1b 46 * Each array has a total of <code>2*numSamples</code> values.
xorjoep 1:24714b45cd1b 47 *
xorjoep 1:24714b45cd1b 48 * The underlying algorithm is used:
xorjoep 1:24714b45cd1b 49 * <pre>
xorjoep 1:24714b45cd1b 50 * realResult=0;
xorjoep 1:24714b45cd1b 51 * imagResult=0;
xorjoep 1:24714b45cd1b 52 * for(n=0; n<numSamples; n++) {
xorjoep 1:24714b45cd1b 53 * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1];
xorjoep 1:24714b45cd1b 54 * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0];
xorjoep 1:24714b45cd1b 55 * }
xorjoep 1:24714b45cd1b 56 * </pre>
xorjoep 1:24714b45cd1b 57 *
xorjoep 1:24714b45cd1b 58 * There are separate functions for floating-point, Q15, and Q31 data types.
xorjoep 1:24714b45cd1b 59 */
xorjoep 1:24714b45cd1b 60
xorjoep 1:24714b45cd1b 61 /**
xorjoep 1:24714b45cd1b 62 * @addtogroup cmplx_dot_prod
xorjoep 1:24714b45cd1b 63 * @{
xorjoep 1:24714b45cd1b 64 */
xorjoep 1:24714b45cd1b 65
xorjoep 1:24714b45cd1b 66 /**
xorjoep 1:24714b45cd1b 67 * @brief Floating-point complex dot product
xorjoep 1:24714b45cd1b 68 * @param *pSrcA points to the first input vector
xorjoep 1:24714b45cd1b 69 * @param *pSrcB points to the second input vector
xorjoep 1:24714b45cd1b 70 * @param numSamples number of complex samples in each vector
xorjoep 1:24714b45cd1b 71 * @param *realResult real part of the result returned here
xorjoep 1:24714b45cd1b 72 * @param *imagResult imaginary part of the result returned here
xorjoep 1:24714b45cd1b 73 * @return none.
xorjoep 1:24714b45cd1b 74 */
xorjoep 1:24714b45cd1b 75
xorjoep 1:24714b45cd1b 76 void arm_cmplx_dot_prod_f32(
xorjoep 1:24714b45cd1b 77 float32_t * pSrcA,
xorjoep 1:24714b45cd1b 78 float32_t * pSrcB,
xorjoep 1:24714b45cd1b 79 uint32_t numSamples,
xorjoep 1:24714b45cd1b 80 float32_t * realResult,
xorjoep 1:24714b45cd1b 81 float32_t * imagResult)
xorjoep 1:24714b45cd1b 82 {
xorjoep 1:24714b45cd1b 83 float32_t real_sum = 0.0f, imag_sum = 0.0f; /* Temporary result storage */
xorjoep 1:24714b45cd1b 84 float32_t a0,b0,c0,d0;
xorjoep 1:24714b45cd1b 85
xorjoep 1:24714b45cd1b 86 #if defined (ARM_MATH_DSP)
xorjoep 1:24714b45cd1b 87
xorjoep 1:24714b45cd1b 88 /* Run the below code for Cortex-M4 and Cortex-M3 */
xorjoep 1:24714b45cd1b 89 uint32_t blkCnt; /* loop counter */
xorjoep 1:24714b45cd1b 90
xorjoep 1:24714b45cd1b 91 /*loop Unrolling */
xorjoep 1:24714b45cd1b 92 blkCnt = numSamples >> 2U;
xorjoep 1:24714b45cd1b 93
xorjoep 1:24714b45cd1b 94 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
xorjoep 1:24714b45cd1b 95 ** a second loop below computes the remaining 1 to 3 samples. */
xorjoep 1:24714b45cd1b 96 while (blkCnt > 0U)
xorjoep 1:24714b45cd1b 97 {
xorjoep 1:24714b45cd1b 98 a0 = *pSrcA++;
xorjoep 1:24714b45cd1b 99 b0 = *pSrcA++;
xorjoep 1:24714b45cd1b 100 c0 = *pSrcB++;
xorjoep 1:24714b45cd1b 101 d0 = *pSrcB++;
xorjoep 1:24714b45cd1b 102
xorjoep 1:24714b45cd1b 103 real_sum += a0 * c0;
xorjoep 1:24714b45cd1b 104 imag_sum += a0 * d0;
xorjoep 1:24714b45cd1b 105 real_sum -= b0 * d0;
xorjoep 1:24714b45cd1b 106 imag_sum += b0 * c0;
xorjoep 1:24714b45cd1b 107
xorjoep 1:24714b45cd1b 108 a0 = *pSrcA++;
xorjoep 1:24714b45cd1b 109 b0 = *pSrcA++;
xorjoep 1:24714b45cd1b 110 c0 = *pSrcB++;
xorjoep 1:24714b45cd1b 111 d0 = *pSrcB++;
xorjoep 1:24714b45cd1b 112
xorjoep 1:24714b45cd1b 113 real_sum += a0 * c0;
xorjoep 1:24714b45cd1b 114 imag_sum += a0 * d0;
xorjoep 1:24714b45cd1b 115 real_sum -= b0 * d0;
xorjoep 1:24714b45cd1b 116 imag_sum += b0 * c0;
xorjoep 1:24714b45cd1b 117
xorjoep 1:24714b45cd1b 118 a0 = *pSrcA++;
xorjoep 1:24714b45cd1b 119 b0 = *pSrcA++;
xorjoep 1:24714b45cd1b 120 c0 = *pSrcB++;
xorjoep 1:24714b45cd1b 121 d0 = *pSrcB++;
xorjoep 1:24714b45cd1b 122
xorjoep 1:24714b45cd1b 123 real_sum += a0 * c0;
xorjoep 1:24714b45cd1b 124 imag_sum += a0 * d0;
xorjoep 1:24714b45cd1b 125 real_sum -= b0 * d0;
xorjoep 1:24714b45cd1b 126 imag_sum += b0 * c0;
xorjoep 1:24714b45cd1b 127
xorjoep 1:24714b45cd1b 128 a0 = *pSrcA++;
xorjoep 1:24714b45cd1b 129 b0 = *pSrcA++;
xorjoep 1:24714b45cd1b 130 c0 = *pSrcB++;
xorjoep 1:24714b45cd1b 131 d0 = *pSrcB++;
xorjoep 1:24714b45cd1b 132
xorjoep 1:24714b45cd1b 133 real_sum += a0 * c0;
xorjoep 1:24714b45cd1b 134 imag_sum += a0 * d0;
xorjoep 1:24714b45cd1b 135 real_sum -= b0 * d0;
xorjoep 1:24714b45cd1b 136 imag_sum += b0 * c0;
xorjoep 1:24714b45cd1b 137
xorjoep 1:24714b45cd1b 138 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 139 blkCnt--;
xorjoep 1:24714b45cd1b 140 }
xorjoep 1:24714b45cd1b 141
xorjoep 1:24714b45cd1b 142 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
xorjoep 1:24714b45cd1b 143 ** No loop unrolling is used. */
xorjoep 1:24714b45cd1b 144 blkCnt = numSamples & 0x3U;
xorjoep 1:24714b45cd1b 145
xorjoep 1:24714b45cd1b 146 while (blkCnt > 0U)
xorjoep 1:24714b45cd1b 147 {
xorjoep 1:24714b45cd1b 148 a0 = *pSrcA++;
xorjoep 1:24714b45cd1b 149 b0 = *pSrcA++;
xorjoep 1:24714b45cd1b 150 c0 = *pSrcB++;
xorjoep 1:24714b45cd1b 151 d0 = *pSrcB++;
xorjoep 1:24714b45cd1b 152
xorjoep 1:24714b45cd1b 153 real_sum += a0 * c0;
xorjoep 1:24714b45cd1b 154 imag_sum += a0 * d0;
xorjoep 1:24714b45cd1b 155 real_sum -= b0 * d0;
xorjoep 1:24714b45cd1b 156 imag_sum += b0 * c0;
xorjoep 1:24714b45cd1b 157
xorjoep 1:24714b45cd1b 158 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 159 blkCnt--;
xorjoep 1:24714b45cd1b 160 }
xorjoep 1:24714b45cd1b 161
xorjoep 1:24714b45cd1b 162 #else
xorjoep 1:24714b45cd1b 163
xorjoep 1:24714b45cd1b 164 /* Run the below code for Cortex-M0 */
xorjoep 1:24714b45cd1b 165
xorjoep 1:24714b45cd1b 166 while (numSamples > 0U)
xorjoep 1:24714b45cd1b 167 {
xorjoep 1:24714b45cd1b 168 a0 = *pSrcA++;
xorjoep 1:24714b45cd1b 169 b0 = *pSrcA++;
xorjoep 1:24714b45cd1b 170 c0 = *pSrcB++;
xorjoep 1:24714b45cd1b 171 d0 = *pSrcB++;
xorjoep 1:24714b45cd1b 172
xorjoep 1:24714b45cd1b 173 real_sum += a0 * c0;
xorjoep 1:24714b45cd1b 174 imag_sum += a0 * d0;
xorjoep 1:24714b45cd1b 175 real_sum -= b0 * d0;
xorjoep 1:24714b45cd1b 176 imag_sum += b0 * c0;
xorjoep 1:24714b45cd1b 177
xorjoep 1:24714b45cd1b 178 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 179 numSamples--;
xorjoep 1:24714b45cd1b 180 }
xorjoep 1:24714b45cd1b 181
xorjoep 1:24714b45cd1b 182 #endif /* #if defined (ARM_MATH_DSP) */
xorjoep 1:24714b45cd1b 183
xorjoep 1:24714b45cd1b 184 /* Store the real and imaginary results in the destination buffers */
xorjoep 1:24714b45cd1b 185 *realResult = real_sum;
xorjoep 1:24714b45cd1b 186 *imagResult = imag_sum;
xorjoep 1:24714b45cd1b 187 }
xorjoep 1:24714b45cd1b 188
xorjoep 1:24714b45cd1b 189 /**
xorjoep 1:24714b45cd1b 190 * @} end of cmplx_dot_prod group
xorjoep 1:24714b45cd1b 191 */