arm_cmplx_mult_cmplx_f32.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mult_cmplx_f32.c
  4. * Description: Floating-point complex-by-complex multiplication
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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. * @defgroup CmplxByCmplxMult Complex-by-Complex Multiplication
  34. *
  35. * Multiplies a complex vector by another complex vector and generates a complex result.
  36. * The data in the complex arrays is stored in an interleaved fashion
  37. * (real, imag, real, imag, ...).
  38. * The parameter <code>numSamples</code> represents the number of complex
  39. * samples processed. The complex arrays have a total of <code>2*numSamples</code>
  40. * real values.
  41. *
  42. * The underlying algorithm is used:
  43. *
  44. * <pre>
  45. * for(n=0; n<numSamples; n++) {
  46. * pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] * pSrcB[(2*n)+1];
  47. * pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] * pSrcB[(2*n)+0];
  48. * }
  49. * </pre>
  50. *
  51. * There are separate functions for floating-point, Q15, and Q31 data types.
  52. */
  53. /**
  54. * @addtogroup CmplxByCmplxMult
  55. * @{
  56. */
  57. /**
  58. * @brief Floating-point complex-by-complex multiplication
  59. * @param[in] *pSrcA points to the first input vector
  60. * @param[in] *pSrcB points to the second input vector
  61. * @param[out] *pDst points to the output vector
  62. * @param[in] numSamples number of complex samples in each vector
  63. * @return none.
  64. */
  65. void arm_cmplx_mult_cmplx_f32(
  66. float32_t * pSrcA,
  67. float32_t * pSrcB,
  68. float32_t * pDst,
  69. uint32_t numSamples)
  70. {
  71. float32_t a1, b1, c1, d1; /* Temporary variables to store real and imaginary values */
  72. uint32_t blkCnt; /* loop counters */
  73. #if defined (ARM_MATH_DSP)
  74. /* Run the below code for Cortex-M4 and Cortex-M3 */
  75. float32_t a2, b2, c2, d2; /* Temporary variables to store real and imaginary values */
  76. float32_t acc1, acc2, acc3, acc4;
  77. /* loop Unrolling */
  78. blkCnt = numSamples >> 2U;
  79. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  80. ** a second loop below computes the remaining 1 to 3 samples. */
  81. while (blkCnt > 0U)
  82. {
  83. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  84. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  85. a1 = *pSrcA; /* A[2 * i] */
  86. c1 = *pSrcB; /* B[2 * i] */
  87. b1 = *(pSrcA + 1); /* A[2 * i + 1] */
  88. acc1 = a1 * c1; /* acc1 = A[2 * i] * B[2 * i] */
  89. a2 = *(pSrcA + 2); /* A[2 * i + 2] */
  90. acc2 = (b1 * c1); /* acc2 = A[2 * i + 1] * B[2 * i] */
  91. d1 = *(pSrcB + 1); /* B[2 * i + 1] */
  92. c2 = *(pSrcB + 2); /* B[2 * i + 2] */
  93. acc1 -= b1 * d1; /* acc1 = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1] */
  94. d2 = *(pSrcB + 3); /* B[2 * i + 3] */
  95. acc3 = a2 * c2; /* acc3 = A[2 * i + 2] * B[2 * i + 2] */
  96. b2 = *(pSrcA + 3); /* A[2 * i + 3] */
  97. acc2 += (a1 * d1); /* acc2 = A[2 * i + 1] * B[2 * i] + A[2 * i] * B[2 * i + 1] */
  98. a1 = *(pSrcA + 4); /* A[2 * i + 4] */
  99. acc4 = (a2 * d2); /* acc4 = A[2 * i + 2] * B[2 * i + 3] */
  100. c1 = *(pSrcB + 4); /* B[2 * i + 4] */
  101. acc3 -= (b2 * d2); /* acc3 = A[2 * i + 2] * B[2 * i + 2] - A[2 * i + 3] * B[2 * i + 3] */
  102. *pDst = acc1; /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1] */
  103. b1 = *(pSrcA + 5); /* A[2 * i + 5] */
  104. acc4 += b2 * c2; /* acc4 = A[2 * i + 2] * B[2 * i + 3] + A[2 * i + 3] * B[2 * i + 2] */
  105. *(pDst + 1) = acc2; /* C[2 * i + 1] = A[2 * i + 1] * B[2 * i] + A[2 * i] * B[2 * i + 1] */
  106. acc1 = (a1 * c1);
  107. d1 = *(pSrcB + 5);
  108. acc2 = (b1 * c1);
  109. *(pDst + 2) = acc3;
  110. *(pDst + 3) = acc4;
  111. a2 = *(pSrcA + 6);
  112. acc1 -= (b1 * d1);
  113. c2 = *(pSrcB + 6);
  114. acc2 += (a1 * d1);
  115. b2 = *(pSrcA + 7);
  116. acc3 = (a2 * c2);
  117. d2 = *(pSrcB + 7);
  118. acc4 = (b2 * c2);
  119. *(pDst + 4) = acc1;
  120. pSrcA += 8U;
  121. acc3 -= (b2 * d2);
  122. acc4 += (a2 * d2);
  123. *(pDst + 5) = acc2;
  124. pSrcB += 8U;
  125. *(pDst + 6) = acc3;
  126. *(pDst + 7) = acc4;
  127. pDst += 8U;
  128. /* Decrement the numSamples loop counter */
  129. blkCnt--;
  130. }
  131. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  132. ** No loop unrolling is used. */
  133. blkCnt = numSamples % 0x4U;
  134. #else
  135. /* Run the below code for Cortex-M0 */
  136. blkCnt = numSamples;
  137. #endif /* #if defined (ARM_MATH_DSP) */
  138. while (blkCnt > 0U)
  139. {
  140. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  141. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  142. a1 = *pSrcA++;
  143. b1 = *pSrcA++;
  144. c1 = *pSrcB++;
  145. d1 = *pSrcB++;
  146. /* store the result in the destination buffer. */
  147. *pDst++ = (a1 * c1) - (b1 * d1);
  148. *pDst++ = (a1 * d1) + (b1 * c1);
  149. /* Decrement the numSamples loop counter */
  150. blkCnt--;
  151. }
  152. }
  153. /**
  154. * @} end of CmplxByCmplxMult group
  155. */