arm_cmplx_mult_real_f32.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mult_real_f32.c
  4. * Description: Floating-point complex by real 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 CmplxByRealMult Complex-by-Real Multiplication
  34. *
  35. * Multiplies a complex vector by a real 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 while the real array has a total of <code>numSamples</code>
  41. * real values.
  42. *
  43. * The underlying algorithm is used:
  44. *
  45. * <pre>
  46. * for(n=0; n<numSamples; n++) {
  47. * pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] * pSrcReal[n];
  48. * pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal[n];
  49. * }
  50. * </pre>
  51. *
  52. * There are separate functions for floating-point, Q15, and Q31 data types.
  53. */
  54. /**
  55. * @addtogroup CmplxByRealMult
  56. * @{
  57. */
  58. /**
  59. * @brief Floating-point complex-by-real multiplication
  60. * @param[in] *pSrcCmplx points to the complex input vector
  61. * @param[in] *pSrcReal points to the real input vector
  62. * @param[out] *pCmplxDst points to the complex output vector
  63. * @param[in] numSamples number of samples in each vector
  64. * @return none.
  65. */
  66. void arm_cmplx_mult_real_f32(
  67. float32_t * pSrcCmplx,
  68. float32_t * pSrcReal,
  69. float32_t * pCmplxDst,
  70. uint32_t numSamples)
  71. {
  72. float32_t in; /* Temporary variable to store input value */
  73. uint32_t blkCnt; /* loop counters */
  74. #if defined (ARM_MATH_DSP)
  75. /* Run the below code for Cortex-M4 and Cortex-M3 */
  76. float32_t inA1, inA2, inA3, inA4; /* Temporary variables to hold input data */
  77. float32_t inA5, inA6, inA7, inA8; /* Temporary variables to hold input data */
  78. float32_t inB1, inB2, inB3, inB4; /* Temporary variables to hold input data */
  79. float32_t out1, out2, out3, out4; /* Temporary variables to hold output data */
  80. float32_t out5, out6, out7, out8; /* Temporary variables to hold output data */
  81. /* loop Unrolling */
  82. blkCnt = numSamples >> 2U;
  83. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  84. ** a second loop below computes the remaining 1 to 3 samples. */
  85. while (blkCnt > 0U)
  86. {
  87. /* C[2 * i] = A[2 * i] * B[i]. */
  88. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  89. /* read input from complex input buffer */
  90. inA1 = pSrcCmplx[0];
  91. inA2 = pSrcCmplx[1];
  92. /* read input from real input buffer */
  93. inB1 = pSrcReal[0];
  94. /* read input from complex input buffer */
  95. inA3 = pSrcCmplx[2];
  96. /* multiply complex buffer real input with real buffer input */
  97. out1 = inA1 * inB1;
  98. /* read input from complex input buffer */
  99. inA4 = pSrcCmplx[3];
  100. /* multiply complex buffer imaginary input with real buffer input */
  101. out2 = inA2 * inB1;
  102. /* read input from real input buffer */
  103. inB2 = pSrcReal[1];
  104. /* read input from complex input buffer */
  105. inA5 = pSrcCmplx[4];
  106. /* multiply complex buffer real input with real buffer input */
  107. out3 = inA3 * inB2;
  108. /* read input from complex input buffer */
  109. inA6 = pSrcCmplx[5];
  110. /* read input from real input buffer */
  111. inB3 = pSrcReal[2];
  112. /* multiply complex buffer imaginary input with real buffer input */
  113. out4 = inA4 * inB2;
  114. /* read input from complex input buffer */
  115. inA7 = pSrcCmplx[6];
  116. /* multiply complex buffer real input with real buffer input */
  117. out5 = inA5 * inB3;
  118. /* read input from complex input buffer */
  119. inA8 = pSrcCmplx[7];
  120. /* multiply complex buffer imaginary input with real buffer input */
  121. out6 = inA6 * inB3;
  122. /* read input from real input buffer */
  123. inB4 = pSrcReal[3];
  124. /* store result to destination bufer */
  125. pCmplxDst[0] = out1;
  126. /* multiply complex buffer real input with real buffer input */
  127. out7 = inA7 * inB4;
  128. /* store result to destination bufer */
  129. pCmplxDst[1] = out2;
  130. /* multiply complex buffer imaginary input with real buffer input */
  131. out8 = inA8 * inB4;
  132. /* store result to destination bufer */
  133. pCmplxDst[2] = out3;
  134. pCmplxDst[3] = out4;
  135. pCmplxDst[4] = out5;
  136. /* incremnet complex input buffer by 8 to process next samples */
  137. pSrcCmplx += 8U;
  138. /* store result to destination bufer */
  139. pCmplxDst[5] = out6;
  140. /* increment real input buffer by 4 to process next samples */
  141. pSrcReal += 4U;
  142. /* store result to destination bufer */
  143. pCmplxDst[6] = out7;
  144. pCmplxDst[7] = out8;
  145. /* increment destination buffer by 8 to process next sampels */
  146. pCmplxDst += 8U;
  147. /* Decrement the numSamples loop counter */
  148. blkCnt--;
  149. }
  150. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  151. ** No loop unrolling is used. */
  152. blkCnt = numSamples % 0x4U;
  153. #else
  154. /* Run the below code for Cortex-M0 */
  155. blkCnt = numSamples;
  156. #endif /* #if defined (ARM_MATH_DSP) */
  157. while (blkCnt > 0U)
  158. {
  159. /* C[2 * i] = A[2 * i] * B[i]. */
  160. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  161. in = *pSrcReal++;
  162. /* store the result in the destination buffer. */
  163. *pCmplxDst++ = (*pSrcCmplx++) * (in);
  164. *pCmplxDst++ = (*pSrcCmplx++) * (in);
  165. /* Decrement the numSamples loop counter */
  166. blkCnt--;
  167. }
  168. }
  169. /**
  170. * @} end of CmplxByRealMult group
  171. */