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
src/Cortex-M4-M3/ComplexMathFunctions/arm_cmplx_dot_prod_f32.c@0:1014af42efd9, 2011-03-10 (annotated)
- Committer:
- simon
- Date:
- Thu Mar 10 15:07:50 2011 +0000
- Revision:
- 0:1014af42efd9
Who changed what in which revision?
User | Revision | Line number | New 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_dot_prod_f32.c |
simon | 0:1014af42efd9 | 9 | * |
simon | 0:1014af42efd9 | 10 | * Description: Floating-point complex dot product |
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 | * @defgroup cmplx_dot_prod Complex Dot Product |
simon | 0:1014af42efd9 | 35 | * |
simon | 0:1014af42efd9 | 36 | * Computes the dot product of two complex vectors. |
simon | 0:1014af42efd9 | 37 | * The vectors are multiplied element-by-element and then summed. |
simon | 0:1014af42efd9 | 38 | * |
simon | 0:1014af42efd9 | 39 | * The <code>pSrcA</code> points to the first complex input vector and |
simon | 0:1014af42efd9 | 40 | * <code>pSrcB</code> points to the second complex input vector. |
simon | 0:1014af42efd9 | 41 | * <code>numSamples</code> specifies the number of complex samples |
simon | 0:1014af42efd9 | 42 | * and the data in each array is stored in an interleaved fashion |
simon | 0:1014af42efd9 | 43 | * (real, imag, real, imag, ...). |
simon | 0:1014af42efd9 | 44 | * Each array has a total of <code>2*numSamples</code> values. |
simon | 0:1014af42efd9 | 45 | * |
simon | 0:1014af42efd9 | 46 | * The underlying algorithm is used: |
simon | 0:1014af42efd9 | 47 | * <pre> |
simon | 0:1014af42efd9 | 48 | * realResult=0; |
simon | 0:1014af42efd9 | 49 | * imagResult=0; |
simon | 0:1014af42efd9 | 50 | * for(n=0; n<numSamples; n++) { |
simon | 0:1014af42efd9 | 51 | * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1]; |
simon | 0:1014af42efd9 | 52 | * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0]; |
simon | 0:1014af42efd9 | 53 | * } |
simon | 0:1014af42efd9 | 54 | * </pre> |
simon | 0:1014af42efd9 | 55 | * |
simon | 0:1014af42efd9 | 56 | * There are separate functions for floating-point, Q15, and Q31 data types. |
simon | 0:1014af42efd9 | 57 | */ |
simon | 0:1014af42efd9 | 58 | |
simon | 0:1014af42efd9 | 59 | /** |
simon | 0:1014af42efd9 | 60 | * @addtogroup cmplx_dot_prod |
simon | 0:1014af42efd9 | 61 | * @{ |
simon | 0:1014af42efd9 | 62 | */ |
simon | 0:1014af42efd9 | 63 | |
simon | 0:1014af42efd9 | 64 | /** |
simon | 0:1014af42efd9 | 65 | * @brief Floating-point complex dot product |
simon | 0:1014af42efd9 | 66 | * @param *pSrcA points to the first input vector |
simon | 0:1014af42efd9 | 67 | * @param *pSrcB points to the second input vector |
simon | 0:1014af42efd9 | 68 | * @param numSamples number of complex samples in each vector |
simon | 0:1014af42efd9 | 69 | * @param *realResult real part of the result returned here |
simon | 0:1014af42efd9 | 70 | * @param *imagResult imaginary part of the result returned here |
simon | 0:1014af42efd9 | 71 | * @return none. |
simon | 0:1014af42efd9 | 72 | */ |
simon | 0:1014af42efd9 | 73 | |
simon | 0:1014af42efd9 | 74 | void arm_cmplx_dot_prod_f32( |
simon | 0:1014af42efd9 | 75 | float32_t * pSrcA, |
simon | 0:1014af42efd9 | 76 | float32_t * pSrcB, |
simon | 0:1014af42efd9 | 77 | uint32_t numSamples, |
simon | 0:1014af42efd9 | 78 | float32_t * realResult, |
simon | 0:1014af42efd9 | 79 | float32_t * imagResult) |
simon | 0:1014af42efd9 | 80 | { |
simon | 0:1014af42efd9 | 81 | float32_t real_sum = 0.0f, imag_sum = 0.0f; /* Temporary result storage */ |
simon | 0:1014af42efd9 | 82 | uint32_t blkCnt; /* loop counter */ |
simon | 0:1014af42efd9 | 83 | |
simon | 0:1014af42efd9 | 84 | /*loop Unrolling */ |
simon | 0:1014af42efd9 | 85 | blkCnt = numSamples >> 2u; |
simon | 0:1014af42efd9 | 86 | |
simon | 0:1014af42efd9 | 87 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
simon | 0:1014af42efd9 | 88 | ** a second loop below computes the remaining 1 to 3 samples. */ |
simon | 0:1014af42efd9 | 89 | while(blkCnt > 0u) |
simon | 0:1014af42efd9 | 90 | { |
simon | 0:1014af42efd9 | 91 | /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ |
simon | 0:1014af42efd9 | 92 | real_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 93 | /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ |
simon | 0:1014af42efd9 | 94 | imag_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 95 | |
simon | 0:1014af42efd9 | 96 | real_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 97 | imag_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 98 | |
simon | 0:1014af42efd9 | 99 | real_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 100 | imag_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 101 | |
simon | 0:1014af42efd9 | 102 | real_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 103 | imag_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 104 | |
simon | 0:1014af42efd9 | 105 | /* Decrement the loop counter */ |
simon | 0:1014af42efd9 | 106 | blkCnt--; |
simon | 0:1014af42efd9 | 107 | } |
simon | 0:1014af42efd9 | 108 | |
simon | 0:1014af42efd9 | 109 | /* If the numSamples is not a multiple of 4, compute any remaining output samples here. |
simon | 0:1014af42efd9 | 110 | ** No loop unrolling is used. */ |
simon | 0:1014af42efd9 | 111 | blkCnt = numSamples % 0x4u; |
simon | 0:1014af42efd9 | 112 | |
simon | 0:1014af42efd9 | 113 | while(blkCnt > 0u) |
simon | 0:1014af42efd9 | 114 | { |
simon | 0:1014af42efd9 | 115 | /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ |
simon | 0:1014af42efd9 | 116 | real_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 117 | /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ |
simon | 0:1014af42efd9 | 118 | imag_sum += (*pSrcA++) * (*pSrcB++); |
simon | 0:1014af42efd9 | 119 | |
simon | 0:1014af42efd9 | 120 | |
simon | 0:1014af42efd9 | 121 | /* Decrement the loop counter */ |
simon | 0:1014af42efd9 | 122 | blkCnt--; |
simon | 0:1014af42efd9 | 123 | } |
simon | 0:1014af42efd9 | 124 | |
simon | 0:1014af42efd9 | 125 | /* Store the real and imaginary results in the destination buffers */ |
simon | 0:1014af42efd9 | 126 | *realResult = real_sum; |
simon | 0:1014af42efd9 | 127 | *imagResult = imag_sum; |
simon | 0:1014af42efd9 | 128 | } |
simon | 0:1014af42efd9 | 129 | |
simon | 0:1014af42efd9 | 130 | /** |
simon | 0:1014af42efd9 | 131 | * @} end of cmplx_dot_prod group |
simon | 0:1014af42efd9 | 132 | */ |