The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/ComplexMathFunctions/arm_cmplx_mult_real_q31.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_real_q31.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Q31 complex by real 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 | * @addtogroup CmplxByRealMult |
xorjoep | 1:24714b45cd1b | 37 | * @{ |
xorjoep | 1:24714b45cd1b | 38 | */ |
xorjoep | 1:24714b45cd1b | 39 | |
xorjoep | 1:24714b45cd1b | 40 | |
xorjoep | 1:24714b45cd1b | 41 | /** |
xorjoep | 1:24714b45cd1b | 42 | * @brief Q31 complex-by-real multiplication |
xorjoep | 1:24714b45cd1b | 43 | * @param[in] *pSrcCmplx points to the complex input vector |
xorjoep | 1:24714b45cd1b | 44 | * @param[in] *pSrcReal points to the real input vector |
xorjoep | 1:24714b45cd1b | 45 | * @param[out] *pCmplxDst points to the complex output vector |
xorjoep | 1:24714b45cd1b | 46 | * @param[in] numSamples number of samples in each vector |
xorjoep | 1:24714b45cd1b | 47 | * @return none. |
xorjoep | 1:24714b45cd1b | 48 | * |
xorjoep | 1:24714b45cd1b | 49 | * <b>Scaling and Overflow Behavior:</b> |
xorjoep | 1:24714b45cd1b | 50 | * \par |
xorjoep | 1:24714b45cd1b | 51 | * The function uses saturating arithmetic. |
xorjoep | 1:24714b45cd1b | 52 | * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated. |
xorjoep | 1:24714b45cd1b | 53 | */ |
xorjoep | 1:24714b45cd1b | 54 | |
xorjoep | 1:24714b45cd1b | 55 | void arm_cmplx_mult_real_q31( |
xorjoep | 1:24714b45cd1b | 56 | q31_t * pSrcCmplx, |
xorjoep | 1:24714b45cd1b | 57 | q31_t * pSrcReal, |
xorjoep | 1:24714b45cd1b | 58 | q31_t * pCmplxDst, |
xorjoep | 1:24714b45cd1b | 59 | uint32_t numSamples) |
xorjoep | 1:24714b45cd1b | 60 | { |
xorjoep | 1:24714b45cd1b | 61 | q31_t inA1; /* Temporary variable to store input value */ |
xorjoep | 1:24714b45cd1b | 62 | |
xorjoep | 1:24714b45cd1b | 63 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 64 | |
xorjoep | 1:24714b45cd1b | 65 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
xorjoep | 1:24714b45cd1b | 66 | uint32_t blkCnt; /* loop counters */ |
xorjoep | 1:24714b45cd1b | 67 | q31_t inA2, inA3, inA4; /* Temporary variables to hold input data */ |
xorjoep | 1:24714b45cd1b | 68 | q31_t inB1, inB2; /* Temporary variabels to hold input data */ |
xorjoep | 1:24714b45cd1b | 69 | q31_t out1, out2, out3, out4; /* Temporary variables to hold output data */ |
xorjoep | 1:24714b45cd1b | 70 | |
xorjoep | 1:24714b45cd1b | 71 | /* loop Unrolling */ |
xorjoep | 1:24714b45cd1b | 72 | blkCnt = numSamples >> 2U; |
xorjoep | 1:24714b45cd1b | 73 | |
xorjoep | 1:24714b45cd1b | 74 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
xorjoep | 1:24714b45cd1b | 75 | ** a second loop below computes the remaining 1 to 3 samples. */ |
xorjoep | 1:24714b45cd1b | 76 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 77 | { |
xorjoep | 1:24714b45cd1b | 78 | /* C[2 * i] = A[2 * i] * B[i]. */ |
xorjoep | 1:24714b45cd1b | 79 | /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */ |
xorjoep | 1:24714b45cd1b | 80 | /* read real input from complex input buffer */ |
xorjoep | 1:24714b45cd1b | 81 | inA1 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 82 | inA2 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 83 | /* read input from real input bufer */ |
xorjoep | 1:24714b45cd1b | 84 | inB1 = *pSrcReal++; |
xorjoep | 1:24714b45cd1b | 85 | inB2 = *pSrcReal++; |
xorjoep | 1:24714b45cd1b | 86 | /* read imaginary input from complex input buffer */ |
xorjoep | 1:24714b45cd1b | 87 | inA3 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 88 | inA4 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 89 | |
xorjoep | 1:24714b45cd1b | 90 | /* multiply complex input with real input */ |
xorjoep | 1:24714b45cd1b | 91 | out1 = ((q63_t) inA1 * inB1) >> 32; |
xorjoep | 1:24714b45cd1b | 92 | out2 = ((q63_t) inA2 * inB1) >> 32; |
xorjoep | 1:24714b45cd1b | 93 | out3 = ((q63_t) inA3 * inB2) >> 32; |
xorjoep | 1:24714b45cd1b | 94 | out4 = ((q63_t) inA4 * inB2) >> 32; |
xorjoep | 1:24714b45cd1b | 95 | |
xorjoep | 1:24714b45cd1b | 96 | /* sature the result */ |
xorjoep | 1:24714b45cd1b | 97 | out1 = __SSAT(out1, 31); |
xorjoep | 1:24714b45cd1b | 98 | out2 = __SSAT(out2, 31); |
xorjoep | 1:24714b45cd1b | 99 | out3 = __SSAT(out3, 31); |
xorjoep | 1:24714b45cd1b | 100 | out4 = __SSAT(out4, 31); |
xorjoep | 1:24714b45cd1b | 101 | |
xorjoep | 1:24714b45cd1b | 102 | /* get result in 1.31 format */ |
xorjoep | 1:24714b45cd1b | 103 | out1 = out1 << 1; |
xorjoep | 1:24714b45cd1b | 104 | out2 = out2 << 1; |
xorjoep | 1:24714b45cd1b | 105 | out3 = out3 << 1; |
xorjoep | 1:24714b45cd1b | 106 | out4 = out4 << 1; |
xorjoep | 1:24714b45cd1b | 107 | |
xorjoep | 1:24714b45cd1b | 108 | /* store the result to destination buffer */ |
xorjoep | 1:24714b45cd1b | 109 | *pCmplxDst++ = out1; |
xorjoep | 1:24714b45cd1b | 110 | *pCmplxDst++ = out2; |
xorjoep | 1:24714b45cd1b | 111 | *pCmplxDst++ = out3; |
xorjoep | 1:24714b45cd1b | 112 | *pCmplxDst++ = out4; |
xorjoep | 1:24714b45cd1b | 113 | |
xorjoep | 1:24714b45cd1b | 114 | /* read real input from complex input buffer */ |
xorjoep | 1:24714b45cd1b | 115 | inA1 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 116 | inA2 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 117 | /* read input from real input bufer */ |
xorjoep | 1:24714b45cd1b | 118 | inB1 = *pSrcReal++; |
xorjoep | 1:24714b45cd1b | 119 | inB2 = *pSrcReal++; |
xorjoep | 1:24714b45cd1b | 120 | /* read imaginary input from complex input buffer */ |
xorjoep | 1:24714b45cd1b | 121 | inA3 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 122 | inA4 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 123 | |
xorjoep | 1:24714b45cd1b | 124 | /* multiply complex input with real input */ |
xorjoep | 1:24714b45cd1b | 125 | out1 = ((q63_t) inA1 * inB1) >> 32; |
xorjoep | 1:24714b45cd1b | 126 | out2 = ((q63_t) inA2 * inB1) >> 32; |
xorjoep | 1:24714b45cd1b | 127 | out3 = ((q63_t) inA3 * inB2) >> 32; |
xorjoep | 1:24714b45cd1b | 128 | out4 = ((q63_t) inA4 * inB2) >> 32; |
xorjoep | 1:24714b45cd1b | 129 | |
xorjoep | 1:24714b45cd1b | 130 | /* sature the result */ |
xorjoep | 1:24714b45cd1b | 131 | out1 = __SSAT(out1, 31); |
xorjoep | 1:24714b45cd1b | 132 | out2 = __SSAT(out2, 31); |
xorjoep | 1:24714b45cd1b | 133 | out3 = __SSAT(out3, 31); |
xorjoep | 1:24714b45cd1b | 134 | out4 = __SSAT(out4, 31); |
xorjoep | 1:24714b45cd1b | 135 | |
xorjoep | 1:24714b45cd1b | 136 | /* get result in 1.31 format */ |
xorjoep | 1:24714b45cd1b | 137 | out1 = out1 << 1; |
xorjoep | 1:24714b45cd1b | 138 | out2 = out2 << 1; |
xorjoep | 1:24714b45cd1b | 139 | out3 = out3 << 1; |
xorjoep | 1:24714b45cd1b | 140 | out4 = out4 << 1; |
xorjoep | 1:24714b45cd1b | 141 | |
xorjoep | 1:24714b45cd1b | 142 | /* store the result to destination buffer */ |
xorjoep | 1:24714b45cd1b | 143 | *pCmplxDst++ = out1; |
xorjoep | 1:24714b45cd1b | 144 | *pCmplxDst++ = out2; |
xorjoep | 1:24714b45cd1b | 145 | *pCmplxDst++ = out3; |
xorjoep | 1:24714b45cd1b | 146 | *pCmplxDst++ = out4; |
xorjoep | 1:24714b45cd1b | 147 | |
xorjoep | 1:24714b45cd1b | 148 | /* Decrement the numSamples loop counter */ |
xorjoep | 1:24714b45cd1b | 149 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 150 | } |
xorjoep | 1:24714b45cd1b | 151 | |
xorjoep | 1:24714b45cd1b | 152 | /* If the numSamples is not a multiple of 4, compute any remaining output samples here. |
xorjoep | 1:24714b45cd1b | 153 | ** No loop unrolling is used. */ |
xorjoep | 1:24714b45cd1b | 154 | blkCnt = numSamples % 0x4U; |
xorjoep | 1:24714b45cd1b | 155 | |
xorjoep | 1:24714b45cd1b | 156 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 157 | { |
xorjoep | 1:24714b45cd1b | 158 | /* C[2 * i] = A[2 * i] * B[i]. */ |
xorjoep | 1:24714b45cd1b | 159 | /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */ |
xorjoep | 1:24714b45cd1b | 160 | /* read real input from complex input buffer */ |
xorjoep | 1:24714b45cd1b | 161 | inA1 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 162 | inA2 = *pSrcCmplx++; |
xorjoep | 1:24714b45cd1b | 163 | /* read input from real input bufer */ |
xorjoep | 1:24714b45cd1b | 164 | inB1 = *pSrcReal++; |
xorjoep | 1:24714b45cd1b | 165 | |
xorjoep | 1:24714b45cd1b | 166 | /* multiply complex input with real input */ |
xorjoep | 1:24714b45cd1b | 167 | out1 = ((q63_t) inA1 * inB1) >> 32; |
xorjoep | 1:24714b45cd1b | 168 | out2 = ((q63_t) inA2 * inB1) >> 32; |
xorjoep | 1:24714b45cd1b | 169 | |
xorjoep | 1:24714b45cd1b | 170 | /* sature the result */ |
xorjoep | 1:24714b45cd1b | 171 | out1 = __SSAT(out1, 31); |
xorjoep | 1:24714b45cd1b | 172 | out2 = __SSAT(out2, 31); |
xorjoep | 1:24714b45cd1b | 173 | |
xorjoep | 1:24714b45cd1b | 174 | /* get result in 1.31 format */ |
xorjoep | 1:24714b45cd1b | 175 | out1 = out1 << 1; |
xorjoep | 1:24714b45cd1b | 176 | out2 = out2 << 1; |
xorjoep | 1:24714b45cd1b | 177 | |
xorjoep | 1:24714b45cd1b | 178 | /* store the result to destination buffer */ |
xorjoep | 1:24714b45cd1b | 179 | *pCmplxDst++ = out1; |
xorjoep | 1:24714b45cd1b | 180 | *pCmplxDst++ = out2; |
xorjoep | 1:24714b45cd1b | 181 | |
xorjoep | 1:24714b45cd1b | 182 | /* Decrement the numSamples loop counter */ |
xorjoep | 1:24714b45cd1b | 183 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 184 | } |
xorjoep | 1:24714b45cd1b | 185 | |
xorjoep | 1:24714b45cd1b | 186 | #else |
xorjoep | 1:24714b45cd1b | 187 | |
xorjoep | 1:24714b45cd1b | 188 | /* Run the below code for Cortex-M0 */ |
xorjoep | 1:24714b45cd1b | 189 | |
xorjoep | 1:24714b45cd1b | 190 | while (numSamples > 0U) |
xorjoep | 1:24714b45cd1b | 191 | { |
xorjoep | 1:24714b45cd1b | 192 | /* realOut = realA * realB. */ |
xorjoep | 1:24714b45cd1b | 193 | /* imagReal = imagA * realB. */ |
xorjoep | 1:24714b45cd1b | 194 | inA1 = *pSrcReal++; |
xorjoep | 1:24714b45cd1b | 195 | /* store the result in the destination buffer. */ |
xorjoep | 1:24714b45cd1b | 196 | *pCmplxDst++ = |
xorjoep | 1:24714b45cd1b | 197 | (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31); |
xorjoep | 1:24714b45cd1b | 198 | *pCmplxDst++ = |
xorjoep | 1:24714b45cd1b | 199 | (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31); |
xorjoep | 1:24714b45cd1b | 200 | |
xorjoep | 1:24714b45cd1b | 201 | /* Decrement the numSamples loop counter */ |
xorjoep | 1:24714b45cd1b | 202 | numSamples--; |
xorjoep | 1:24714b45cd1b | 203 | } |
xorjoep | 1:24714b45cd1b | 204 | |
xorjoep | 1:24714b45cd1b | 205 | #endif /* #if defined (ARM_MATH_DSP) */ |
xorjoep | 1:24714b45cd1b | 206 | |
xorjoep | 1:24714b45cd1b | 207 | } |
xorjoep | 1:24714b45cd1b | 208 | |
xorjoep | 1:24714b45cd1b | 209 | /** |
xorjoep | 1:24714b45cd1b | 210 | * @} end of CmplxByRealMult group |
xorjoep | 1:24714b45cd1b | 211 | */ |