arm_cmplx_dot_prod_q15.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_dot_prod_q15.c
  4. * Description: Processing function for the Q15 Complex Dot product
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "arm_math.h"
  29. /**
  30. @ingroup groupCmplxMath
  31. */
  32. /**
  33. @addtogroup cmplx_dot_prod
  34. @{
  35. */
  36. /**
  37. @brief Q15 complex dot product.
  38. @param[in] pSrcA points to the first input vector
  39. @param[in] pSrcB points to the second input vector
  40. @param[in] numSamples number of samples in each vector
  41. @param[out] realResult real part of the result returned here
  42. @param[out] imagResult imaginary part of the result returned her
  43. @return none
  44. @par Scaling and Overflow Behavior
  45. The function is implemented using an internal 64-bit accumulator.
  46. The intermediate 1.15 by 1.15 multiplications are performed with full precision and yield a 2.30 result.
  47. These are accumulated in a 64-bit accumulator with 34.30 precision.
  48. As a final step, the accumulators are converted to 8.24 format.
  49. The return results <code>realResult</code> and <code>imagResult</code> are in 8.24 format.
  50. */
  51. void arm_cmplx_dot_prod_q15(
  52. const q15_t * pSrcA,
  53. const q15_t * pSrcB,
  54. uint32_t numSamples,
  55. q31_t * realResult,
  56. q31_t * imagResult)
  57. {
  58. uint32_t blkCnt; /* Loop counter */
  59. q63_t real_sum = 0, imag_sum = 0; /* Temporary result variables */
  60. q15_t a0,b0,c0,d0;
  61. #if defined (ARM_MATH_LOOPUNROLL)
  62. /* Loop unrolling: Compute 4 outputs at a time */
  63. blkCnt = numSamples >> 2U;
  64. while (blkCnt > 0U)
  65. {
  66. a0 = *pSrcA++;
  67. b0 = *pSrcA++;
  68. c0 = *pSrcB++;
  69. d0 = *pSrcB++;
  70. real_sum += (q31_t)a0 * c0;
  71. imag_sum += (q31_t)a0 * d0;
  72. real_sum -= (q31_t)b0 * d0;
  73. imag_sum += (q31_t)b0 * c0;
  74. a0 = *pSrcA++;
  75. b0 = *pSrcA++;
  76. c0 = *pSrcB++;
  77. d0 = *pSrcB++;
  78. real_sum += (q31_t)a0 * c0;
  79. imag_sum += (q31_t)a0 * d0;
  80. real_sum -= (q31_t)b0 * d0;
  81. imag_sum += (q31_t)b0 * c0;
  82. a0 = *pSrcA++;
  83. b0 = *pSrcA++;
  84. c0 = *pSrcB++;
  85. d0 = *pSrcB++;
  86. real_sum += (q31_t)a0 * c0;
  87. imag_sum += (q31_t)a0 * d0;
  88. real_sum -= (q31_t)b0 * d0;
  89. imag_sum += (q31_t)b0 * c0;
  90. a0 = *pSrcA++;
  91. b0 = *pSrcA++;
  92. c0 = *pSrcB++;
  93. d0 = *pSrcB++;
  94. real_sum += (q31_t)a0 * c0;
  95. imag_sum += (q31_t)a0 * d0;
  96. real_sum -= (q31_t)b0 * d0;
  97. imag_sum += (q31_t)b0 * c0;
  98. /* Decrement loop counter */
  99. blkCnt--;
  100. }
  101. /* Loop unrolling: Compute remaining outputs */
  102. blkCnt = numSamples % 0x4U;
  103. #else
  104. /* Initialize blkCnt with number of samples */
  105. blkCnt = numSamples;
  106. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  107. while (blkCnt > 0U)
  108. {
  109. a0 = *pSrcA++;
  110. b0 = *pSrcA++;
  111. c0 = *pSrcB++;
  112. d0 = *pSrcB++;
  113. real_sum += (q31_t)a0 * c0;
  114. imag_sum += (q31_t)a0 * d0;
  115. real_sum -= (q31_t)b0 * d0;
  116. imag_sum += (q31_t)b0 * c0;
  117. /* Decrement loop counter */
  118. blkCnt--;
  119. }
  120. /* Store real and imaginary result in 8.24 format */
  121. /* Convert real data in 34.30 to 8.24 by 6 right shifts */
  122. *realResult = (q31_t) (real_sum >> 6);
  123. /* Convert imaginary data in 34.30 to 8.24 by 6 right shifts */
  124. *imagResult = (q31_t) (imag_sum >> 6);
  125. }
  126. /**
  127. @} end of cmplx_dot_prod group
  128. */