The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/ComplexMathFunctions/arm_cmplx_mult_cmplx_f32.c@3:4098b9d3d571, 2018-06-21 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 1:24714b45cd1b | 1 | /* ---------------------------------------------------------------------- |
xorjoep | 1:24714b45cd1b | 2 | * Project: CMSIS DSP Library |
xorjoep | 1:24714b45cd1b | 3 | * Title: arm_cmplx_mult_cmplx_f32.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Floating-point complex-by-complex multiplication |
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 CmplxByCmplxMult Complex-by-Complex Multiplication |
xorjoep | 1:24714b45cd1b | 37 | * |
xorjoep | 1:24714b45cd1b | 38 | * Multiplies a complex vector by another complex vector and generates a complex result. |
xorjoep | 1:24714b45cd1b | 39 | * The data in the complex arrays is stored in an interleaved fashion |
xorjoep | 1:24714b45cd1b | 40 | * (real, imag, real, imag, ...). |
xorjoep | 1:24714b45cd1b | 41 | * The parameter <code>numSamples</code> represents the number of complex |
xorjoep | 1:24714b45cd1b | 42 | * samples processed. The complex arrays have a total of <code>2*numSamples</code> |
xorjoep | 1:24714b45cd1b | 43 | * real values. |
xorjoep | 1:24714b45cd1b | 44 | * |
xorjoep | 1:24714b45cd1b | 45 | * The underlying algorithm is used: |
xorjoep | 1:24714b45cd1b | 46 | * |
xorjoep | 1:24714b45cd1b | 47 | * <pre> |
xorjoep | 1:24714b45cd1b | 48 | * for(n=0; n<numSamples; n++) { |
xorjoep | 1:24714b45cd1b | 49 | * pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] * pSrcB[(2*n)+1]; |
xorjoep | 1:24714b45cd1b | 50 | * pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] * pSrcB[(2*n)+0]; |
xorjoep | 1:24714b45cd1b | 51 | * } |
xorjoep | 1:24714b45cd1b | 52 | * </pre> |
xorjoep | 1:24714b45cd1b | 53 | * |
xorjoep | 1:24714b45cd1b | 54 | * There are separate functions for floating-point, Q15, and Q31 data types. |
xorjoep | 1:24714b45cd1b | 55 | */ |
xorjoep | 1:24714b45cd1b | 56 | |
xorjoep | 1:24714b45cd1b | 57 | /** |
xorjoep | 1:24714b45cd1b | 58 | * @addtogroup CmplxByCmplxMult |
xorjoep | 1:24714b45cd1b | 59 | * @{ |
xorjoep | 1:24714b45cd1b | 60 | */ |
xorjoep | 1:24714b45cd1b | 61 | |
xorjoep | 1:24714b45cd1b | 62 | |
xorjoep | 1:24714b45cd1b | 63 | /** |
xorjoep | 1:24714b45cd1b | 64 | * @brief Floating-point complex-by-complex multiplication |
xorjoep | 1:24714b45cd1b | 65 | * @param[in] *pSrcA points to the first input vector |
xorjoep | 1:24714b45cd1b | 66 | * @param[in] *pSrcB points to the second input vector |
xorjoep | 1:24714b45cd1b | 67 | * @param[out] *pDst points to the output vector |
xorjoep | 1:24714b45cd1b | 68 | * @param[in] numSamples number of complex samples in each vector |
xorjoep | 1:24714b45cd1b | 69 | * @return none. |
xorjoep | 1:24714b45cd1b | 70 | */ |
xorjoep | 1:24714b45cd1b | 71 | |
xorjoep | 1:24714b45cd1b | 72 | void arm_cmplx_mult_cmplx_f32( |
xorjoep | 1:24714b45cd1b | 73 | float32_t * pSrcA, |
xorjoep | 1:24714b45cd1b | 74 | float32_t * pSrcB, |
xorjoep | 1:24714b45cd1b | 75 | float32_t * pDst, |
xorjoep | 1:24714b45cd1b | 76 | uint32_t numSamples) |
xorjoep | 1:24714b45cd1b | 77 | { |
xorjoep | 1:24714b45cd1b | 78 | float32_t a1, b1, c1, d1; /* Temporary variables to store real and imaginary values */ |
xorjoep | 1:24714b45cd1b | 79 | uint32_t blkCnt; /* loop counters */ |
xorjoep | 1:24714b45cd1b | 80 | |
xorjoep | 1:24714b45cd1b | 81 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 82 | |
xorjoep | 1:24714b45cd1b | 83 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
xorjoep | 1:24714b45cd1b | 84 | float32_t a2, b2, c2, d2; /* Temporary variables to store real and imaginary values */ |
xorjoep | 1:24714b45cd1b | 85 | float32_t acc1, acc2, acc3, acc4; |
xorjoep | 1:24714b45cd1b | 86 | |
xorjoep | 1:24714b45cd1b | 87 | |
xorjoep | 1:24714b45cd1b | 88 | /* loop Unrolling */ |
xorjoep | 1:24714b45cd1b | 89 | blkCnt = numSamples >> 2U; |
xorjoep | 1:24714b45cd1b | 90 | |
xorjoep | 1:24714b45cd1b | 91 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
xorjoep | 1:24714b45cd1b | 92 | ** a second loop below computes the remaining 1 to 3 samples. */ |
xorjoep | 1:24714b45cd1b | 93 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 94 | { |
xorjoep | 1:24714b45cd1b | 95 | /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ |
xorjoep | 1:24714b45cd1b | 96 | /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ |
xorjoep | 1:24714b45cd1b | 97 | a1 = *pSrcA; /* A[2 * i] */ |
xorjoep | 1:24714b45cd1b | 98 | c1 = *pSrcB; /* B[2 * i] */ |
xorjoep | 1:24714b45cd1b | 99 | |
xorjoep | 1:24714b45cd1b | 100 | b1 = *(pSrcA + 1); /* A[2 * i + 1] */ |
xorjoep | 1:24714b45cd1b | 101 | acc1 = a1 * c1; /* acc1 = A[2 * i] * B[2 * i] */ |
xorjoep | 1:24714b45cd1b | 102 | |
xorjoep | 1:24714b45cd1b | 103 | a2 = *(pSrcA + 2); /* A[2 * i + 2] */ |
xorjoep | 1:24714b45cd1b | 104 | acc2 = (b1 * c1); /* acc2 = A[2 * i + 1] * B[2 * i] */ |
xorjoep | 1:24714b45cd1b | 105 | |
xorjoep | 1:24714b45cd1b | 106 | d1 = *(pSrcB + 1); /* B[2 * i + 1] */ |
xorjoep | 1:24714b45cd1b | 107 | c2 = *(pSrcB + 2); /* B[2 * i + 2] */ |
xorjoep | 1:24714b45cd1b | 108 | acc1 -= b1 * d1; /* acc1 = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1] */ |
xorjoep | 1:24714b45cd1b | 109 | |
xorjoep | 1:24714b45cd1b | 110 | d2 = *(pSrcB + 3); /* B[2 * i + 3] */ |
xorjoep | 1:24714b45cd1b | 111 | acc3 = a2 * c2; /* acc3 = A[2 * i + 2] * B[2 * i + 2] */ |
xorjoep | 1:24714b45cd1b | 112 | |
xorjoep | 1:24714b45cd1b | 113 | b2 = *(pSrcA + 3); /* A[2 * i + 3] */ |
xorjoep | 1:24714b45cd1b | 114 | acc2 += (a1 * d1); /* acc2 = A[2 * i + 1] * B[2 * i] + A[2 * i] * B[2 * i + 1] */ |
xorjoep | 1:24714b45cd1b | 115 | |
xorjoep | 1:24714b45cd1b | 116 | a1 = *(pSrcA + 4); /* A[2 * i + 4] */ |
xorjoep | 1:24714b45cd1b | 117 | acc4 = (a2 * d2); /* acc4 = A[2 * i + 2] * B[2 * i + 3] */ |
xorjoep | 1:24714b45cd1b | 118 | |
xorjoep | 1:24714b45cd1b | 119 | c1 = *(pSrcB + 4); /* B[2 * i + 4] */ |
xorjoep | 1:24714b45cd1b | 120 | acc3 -= (b2 * d2); /* acc3 = A[2 * i + 2] * B[2 * i + 2] - A[2 * i + 3] * B[2 * i + 3] */ |
xorjoep | 1:24714b45cd1b | 121 | *pDst = acc1; /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1] */ |
xorjoep | 1:24714b45cd1b | 122 | |
xorjoep | 1:24714b45cd1b | 123 | b1 = *(pSrcA + 5); /* A[2 * i + 5] */ |
xorjoep | 1:24714b45cd1b | 124 | acc4 += b2 * c2; /* acc4 = A[2 * i + 2] * B[2 * i + 3] + A[2 * i + 3] * B[2 * i + 2] */ |
xorjoep | 1:24714b45cd1b | 125 | |
xorjoep | 1:24714b45cd1b | 126 | *(pDst + 1) = acc2; /* C[2 * i + 1] = A[2 * i + 1] * B[2 * i] + A[2 * i] * B[2 * i + 1] */ |
xorjoep | 1:24714b45cd1b | 127 | acc1 = (a1 * c1); |
xorjoep | 1:24714b45cd1b | 128 | |
xorjoep | 1:24714b45cd1b | 129 | d1 = *(pSrcB + 5); |
xorjoep | 1:24714b45cd1b | 130 | acc2 = (b1 * c1); |
xorjoep | 1:24714b45cd1b | 131 | |
xorjoep | 1:24714b45cd1b | 132 | *(pDst + 2) = acc3; |
xorjoep | 1:24714b45cd1b | 133 | *(pDst + 3) = acc4; |
xorjoep | 1:24714b45cd1b | 134 | |
xorjoep | 1:24714b45cd1b | 135 | a2 = *(pSrcA + 6); |
xorjoep | 1:24714b45cd1b | 136 | acc1 -= (b1 * d1); |
xorjoep | 1:24714b45cd1b | 137 | |
xorjoep | 1:24714b45cd1b | 138 | c2 = *(pSrcB + 6); |
xorjoep | 1:24714b45cd1b | 139 | acc2 += (a1 * d1); |
xorjoep | 1:24714b45cd1b | 140 | |
xorjoep | 1:24714b45cd1b | 141 | b2 = *(pSrcA + 7); |
xorjoep | 1:24714b45cd1b | 142 | acc3 = (a2 * c2); |
xorjoep | 1:24714b45cd1b | 143 | |
xorjoep | 1:24714b45cd1b | 144 | d2 = *(pSrcB + 7); |
xorjoep | 1:24714b45cd1b | 145 | acc4 = (b2 * c2); |
xorjoep | 1:24714b45cd1b | 146 | |
xorjoep | 1:24714b45cd1b | 147 | *(pDst + 4) = acc1; |
xorjoep | 1:24714b45cd1b | 148 | pSrcA += 8U; |
xorjoep | 1:24714b45cd1b | 149 | |
xorjoep | 1:24714b45cd1b | 150 | acc3 -= (b2 * d2); |
xorjoep | 1:24714b45cd1b | 151 | acc4 += (a2 * d2); |
xorjoep | 1:24714b45cd1b | 152 | |
xorjoep | 1:24714b45cd1b | 153 | *(pDst + 5) = acc2; |
xorjoep | 1:24714b45cd1b | 154 | pSrcB += 8U; |
xorjoep | 1:24714b45cd1b | 155 | |
xorjoep | 1:24714b45cd1b | 156 | *(pDst + 6) = acc3; |
xorjoep | 1:24714b45cd1b | 157 | *(pDst + 7) = acc4; |
xorjoep | 1:24714b45cd1b | 158 | |
xorjoep | 1:24714b45cd1b | 159 | pDst += 8U; |
xorjoep | 1:24714b45cd1b | 160 | |
xorjoep | 1:24714b45cd1b | 161 | /* Decrement the numSamples loop counter */ |
xorjoep | 1:24714b45cd1b | 162 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 163 | } |
xorjoep | 1:24714b45cd1b | 164 | |
xorjoep | 1:24714b45cd1b | 165 | /* If the numSamples is not a multiple of 4, compute any remaining output samples here. |
xorjoep | 1:24714b45cd1b | 166 | ** No loop unrolling is used. */ |
xorjoep | 1:24714b45cd1b | 167 | blkCnt = numSamples % 0x4U; |
xorjoep | 1:24714b45cd1b | 168 | |
xorjoep | 1:24714b45cd1b | 169 | #else |
xorjoep | 1:24714b45cd1b | 170 | |
xorjoep | 1:24714b45cd1b | 171 | /* Run the below code for Cortex-M0 */ |
xorjoep | 1:24714b45cd1b | 172 | blkCnt = numSamples; |
xorjoep | 1:24714b45cd1b | 173 | |
xorjoep | 1:24714b45cd1b | 174 | #endif /* #if defined (ARM_MATH_DSP) */ |
xorjoep | 1:24714b45cd1b | 175 | |
xorjoep | 1:24714b45cd1b | 176 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 177 | { |
xorjoep | 1:24714b45cd1b | 178 | /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ |
xorjoep | 1:24714b45cd1b | 179 | /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ |
xorjoep | 1:24714b45cd1b | 180 | a1 = *pSrcA++; |
xorjoep | 1:24714b45cd1b | 181 | b1 = *pSrcA++; |
xorjoep | 1:24714b45cd1b | 182 | c1 = *pSrcB++; |
xorjoep | 1:24714b45cd1b | 183 | d1 = *pSrcB++; |
xorjoep | 1:24714b45cd1b | 184 | |
xorjoep | 1:24714b45cd1b | 185 | /* store the result in the destination buffer. */ |
xorjoep | 1:24714b45cd1b | 186 | *pDst++ = (a1 * c1) - (b1 * d1); |
xorjoep | 1:24714b45cd1b | 187 | *pDst++ = (a1 * d1) + (b1 * c1); |
xorjoep | 1:24714b45cd1b | 188 | |
xorjoep | 1:24714b45cd1b | 189 | /* Decrement the numSamples loop counter */ |
xorjoep | 1:24714b45cd1b | 190 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 191 | } |
xorjoep | 1:24714b45cd1b | 192 | } |
xorjoep | 1:24714b45cd1b | 193 | |
xorjoep | 1:24714b45cd1b | 194 | /** |
xorjoep | 1:24714b45cd1b | 195 | * @} end of CmplxByCmplxMult group |
xorjoep | 1:24714b45cd1b | 196 | */ |