CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Committer:
simon
Date:
Thu Mar 10 15:07:50 2011 +0000
Revision:
0:1014af42efd9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:1014af42efd9 1 /* ----------------------------------------------------------------------
simon 0:1014af42efd9 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
simon 0:1014af42efd9 3 *
simon 0:1014af42efd9 4 * $Date: 29. November 2010
simon 0:1014af42efd9 5 * $Revision: V1.0.3
simon 0:1014af42efd9 6 *
simon 0:1014af42efd9 7 * Project: CMSIS DSP Library
simon 0:1014af42efd9 8 * Title: arm_cmplx_mult_cmplx_q31.c
simon 0:1014af42efd9 9 *
simon 0:1014af42efd9 10 * Description: Q31 complex-by-complex multiplication
simon 0:1014af42efd9 11 *
simon 0:1014af42efd9 12 * Target Processor: Cortex-M4/Cortex-M3
simon 0:1014af42efd9 13 *
simon 0:1014af42efd9 14 * Version 1.0.3 2010/11/29
simon 0:1014af42efd9 15 * Re-organized the CMSIS folders and updated documentation.
simon 0:1014af42efd9 16 *
simon 0:1014af42efd9 17 * Version 1.0.2 2010/11/11
simon 0:1014af42efd9 18 * Documentation updated.
simon 0:1014af42efd9 19 *
simon 0:1014af42efd9 20 * Version 1.0.1 2010/10/05
simon 0:1014af42efd9 21 * Production release and review comments incorporated.
simon 0:1014af42efd9 22 *
simon 0:1014af42efd9 23 * Version 1.0.0 2010/09/20
simon 0:1014af42efd9 24 * Production release and review comments incorporated.
simon 0:1014af42efd9 25 * -------------------------------------------------------------------- */
simon 0:1014af42efd9 26
simon 0:1014af42efd9 27 #include "arm_math.h"
simon 0:1014af42efd9 28
simon 0:1014af42efd9 29 /**
simon 0:1014af42efd9 30 * @ingroup groupCmplxMath
simon 0:1014af42efd9 31 */
simon 0:1014af42efd9 32
simon 0:1014af42efd9 33 /**
simon 0:1014af42efd9 34 * @addtogroup CmplxByCmplxMult
simon 0:1014af42efd9 35 * @{
simon 0:1014af42efd9 36 */
simon 0:1014af42efd9 37
simon 0:1014af42efd9 38
simon 0:1014af42efd9 39 /**
simon 0:1014af42efd9 40 * @brief Q31 complex-by-complex multiplication
simon 0:1014af42efd9 41 * @param[in] *pSrcA points to the first input vector
simon 0:1014af42efd9 42 * @param[in] *pSrcB points to the second input vector
simon 0:1014af42efd9 43 * @param[out] *pDst points to the output vector
simon 0:1014af42efd9 44 * @param[in] numSamples number of complex samples in each vector
simon 0:1014af42efd9 45 * @return none.
simon 0:1014af42efd9 46 *
simon 0:1014af42efd9 47 * <b>Scaling and Overflow Behavior:</b>
simon 0:1014af42efd9 48 * \par
simon 0:1014af42efd9 49 * The function implements 1.31 by 1.31 multiplications and finally output is converted into 3.29 format.
simon 0:1014af42efd9 50 * Input down scaling is not required.
simon 0:1014af42efd9 51 */
simon 0:1014af42efd9 52
simon 0:1014af42efd9 53 void arm_cmplx_mult_cmplx_q31(
simon 0:1014af42efd9 54 q31_t * pSrcA,
simon 0:1014af42efd9 55 q31_t * pSrcB,
simon 0:1014af42efd9 56 q31_t * pDst,
simon 0:1014af42efd9 57 uint32_t numSamples)
simon 0:1014af42efd9 58 {
simon 0:1014af42efd9 59 q31_t a, b, c, d; /* Temporary variables to store real and imaginary values */
simon 0:1014af42efd9 60 uint32_t blkCnt; /* loop counters */
simon 0:1014af42efd9 61
simon 0:1014af42efd9 62 /* loop Unrolling */
simon 0:1014af42efd9 63 blkCnt = numSamples >> 2u;
simon 0:1014af42efd9 64
simon 0:1014af42efd9 65 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
simon 0:1014af42efd9 66 ** a second loop below computes the remaining 1 to 3 samples. */
simon 0:1014af42efd9 67 while(blkCnt > 0u)
simon 0:1014af42efd9 68 {
simon 0:1014af42efd9 69 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
simon 0:1014af42efd9 70 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
simon 0:1014af42efd9 71 a = *pSrcA++;
simon 0:1014af42efd9 72 b = *pSrcA++;
simon 0:1014af42efd9 73 c = *pSrcB++;
simon 0:1014af42efd9 74 d = *pSrcB++;
simon 0:1014af42efd9 75
simon 0:1014af42efd9 76 /* store the real result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 77 *pDst++ = (q31_t) ((((q63_t) a * c) >> 33) - (((q63_t) b * d) >> 33));
simon 0:1014af42efd9 78 /* store the imag result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 79 *pDst++ = (q31_t) ((((q63_t) a * d) >> 33) + (((q63_t) b * c) >> 33));
simon 0:1014af42efd9 80
simon 0:1014af42efd9 81 a = *pSrcA++;
simon 0:1014af42efd9 82 b = *pSrcA++;
simon 0:1014af42efd9 83 c = *pSrcB++;
simon 0:1014af42efd9 84 d = *pSrcB++;
simon 0:1014af42efd9 85
simon 0:1014af42efd9 86 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 87 *pDst++ = (q31_t) ((((q63_t) a * c) >> 33) - (((q63_t) b * d) >> 33));
simon 0:1014af42efd9 88 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 89 *pDst++ = (q31_t) ((((q63_t) a * d) >> 33) + (((q63_t) b * c) >> 33));
simon 0:1014af42efd9 90
simon 0:1014af42efd9 91 a = *pSrcA++;
simon 0:1014af42efd9 92 b = *pSrcA++;
simon 0:1014af42efd9 93 c = *pSrcB++;
simon 0:1014af42efd9 94 d = *pSrcB++;
simon 0:1014af42efd9 95
simon 0:1014af42efd9 96 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 97 *pDst++ = (q31_t) ((((q63_t) a * c) >> 33) - (((q63_t) b * d) >> 33));
simon 0:1014af42efd9 98 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 99 *pDst++ = (q31_t) ((((q63_t) a * d) >> 33) + (((q63_t) b * c) >> 33));
simon 0:1014af42efd9 100
simon 0:1014af42efd9 101 a = *pSrcA++;
simon 0:1014af42efd9 102 b = *pSrcA++;
simon 0:1014af42efd9 103 c = *pSrcB++;
simon 0:1014af42efd9 104 d = *pSrcB++;
simon 0:1014af42efd9 105
simon 0:1014af42efd9 106 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 107 *pDst++ = (q31_t) ((((q63_t) a * c) >> 33) - (((q63_t) b * d) >> 33));
simon 0:1014af42efd9 108 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 109 *pDst++ = (q31_t) ((((q63_t) a * d) >> 33) + (((q63_t) b * c) >> 33));
simon 0:1014af42efd9 110
simon 0:1014af42efd9 111 /* Decrement the blockSize loop counter */
simon 0:1014af42efd9 112 blkCnt--;
simon 0:1014af42efd9 113 }
simon 0:1014af42efd9 114
simon 0:1014af42efd9 115 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
simon 0:1014af42efd9 116 ** No loop unrolling is used. */
simon 0:1014af42efd9 117 blkCnt = numSamples % 0x4u;
simon 0:1014af42efd9 118
simon 0:1014af42efd9 119 while(blkCnt > 0u)
simon 0:1014af42efd9 120 {
simon 0:1014af42efd9 121 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
simon 0:1014af42efd9 122 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
simon 0:1014af42efd9 123 a = *pSrcA++;
simon 0:1014af42efd9 124 b = *pSrcA++;
simon 0:1014af42efd9 125 c = *pSrcB++;
simon 0:1014af42efd9 126 d = *pSrcB++;
simon 0:1014af42efd9 127
simon 0:1014af42efd9 128 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 129 *pDst++ = (q31_t) ((((q63_t) a * c) >> 33) - (((q63_t) b * d) >> 33));
simon 0:1014af42efd9 130 /* store the result in 3.29 format in the destination buffer. */
simon 0:1014af42efd9 131 *pDst++ = (q31_t) ((((q63_t) a * d) >> 33) + (((q63_t) b * c) >> 33));
simon 0:1014af42efd9 132
simon 0:1014af42efd9 133 /* Decrement the blockSize loop counter */
simon 0:1014af42efd9 134 blkCnt--;
simon 0:1014af42efd9 135 }
simon 0:1014af42efd9 136 }
simon 0:1014af42efd9 137
simon 0:1014af42efd9 138 /**
simon 0:1014af42efd9 139 * @} end of CmplxByCmplxMult group
simon 0:1014af42efd9 140 */