A bundled STM32F10x Std Periph and CMSIS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

226 lines
7.5 KiB

  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 12. March 2014
  5. * $Revision: V1.4.4
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_cmplx_mult_real_f32.c
  9. *
  10. * Description: Floating-point complex by real multiplication
  11. *
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. * - Neither the name of ARM LIMITED nor the names of its contributors
  24. * may be used to endorse or promote products derived from this
  25. * software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. * -------------------------------------------------------------------- */
  40. #include "arm_math.h"
  41. /**
  42. * @ingroup groupCmplxMath
  43. */
  44. /**
  45. * @defgroup CmplxByRealMult Complex-by-Real Multiplication
  46. *
  47. * Multiplies a complex vector by a real vector and generates a complex result.
  48. * The data in the complex arrays is stored in an interleaved fashion
  49. * (real, imag, real, imag, ...).
  50. * The parameter <code>numSamples</code> represents the number of complex
  51. * samples processed. The complex arrays have a total of <code>2*numSamples</code>
  52. * real values while the real array has a total of <code>numSamples</code>
  53. * real values.
  54. *
  55. * The underlying algorithm is used:
  56. *
  57. * <pre>
  58. * for(n=0; n<numSamples; n++) {
  59. * pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] * pSrcReal[n];
  60. * pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal[n];
  61. * }
  62. * </pre>
  63. *
  64. * There are separate functions for floating-point, Q15, and Q31 data types.
  65. */
  66. /**
  67. * @addtogroup CmplxByRealMult
  68. * @{
  69. */
  70. /**
  71. * @brief Floating-point complex-by-real multiplication
  72. * @param[in] *pSrcCmplx points to the complex input vector
  73. * @param[in] *pSrcReal points to the real input vector
  74. * @param[out] *pCmplxDst points to the complex output vector
  75. * @param[in] numSamples number of samples in each vector
  76. * @return none.
  77. */
  78. void arm_cmplx_mult_real_f32(
  79. float32_t * pSrcCmplx,
  80. float32_t * pSrcReal,
  81. float32_t * pCmplxDst,
  82. uint32_t numSamples)
  83. {
  84. float32_t in; /* Temporary variable to store input value */
  85. uint32_t blkCnt; /* loop counters */
  86. #ifndef ARM_MATH_CM0_FAMILY
  87. /* Run the below code for Cortex-M4 and Cortex-M3 */
  88. float32_t inA1, inA2, inA3, inA4; /* Temporary variables to hold input data */
  89. float32_t inA5, inA6, inA7, inA8; /* Temporary variables to hold input data */
  90. float32_t inB1, inB2, inB3, inB4; /* Temporary variables to hold input data */
  91. float32_t out1, out2, out3, out4; /* Temporary variables to hold output data */
  92. float32_t out5, out6, out7, out8; /* Temporary variables to hold output data */
  93. /* loop Unrolling */
  94. blkCnt = numSamples >> 2u;
  95. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  96. ** a second loop below computes the remaining 1 to 3 samples. */
  97. while(blkCnt > 0u)
  98. {
  99. /* C[2 * i] = A[2 * i] * B[i]. */
  100. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  101. /* read input from complex input buffer */
  102. inA1 = pSrcCmplx[0];
  103. inA2 = pSrcCmplx[1];
  104. /* read input from real input buffer */
  105. inB1 = pSrcReal[0];
  106. /* read input from complex input buffer */
  107. inA3 = pSrcCmplx[2];
  108. /* multiply complex buffer real input with real buffer input */
  109. out1 = inA1 * inB1;
  110. /* read input from complex input buffer */
  111. inA4 = pSrcCmplx[3];
  112. /* multiply complex buffer imaginary input with real buffer input */
  113. out2 = inA2 * inB1;
  114. /* read input from real input buffer */
  115. inB2 = pSrcReal[1];
  116. /* read input from complex input buffer */
  117. inA5 = pSrcCmplx[4];
  118. /* multiply complex buffer real input with real buffer input */
  119. out3 = inA3 * inB2;
  120. /* read input from complex input buffer */
  121. inA6 = pSrcCmplx[5];
  122. /* read input from real input buffer */
  123. inB3 = pSrcReal[2];
  124. /* multiply complex buffer imaginary input with real buffer input */
  125. out4 = inA4 * inB2;
  126. /* read input from complex input buffer */
  127. inA7 = pSrcCmplx[6];
  128. /* multiply complex buffer real input with real buffer input */
  129. out5 = inA5 * inB3;
  130. /* read input from complex input buffer */
  131. inA8 = pSrcCmplx[7];
  132. /* multiply complex buffer imaginary input with real buffer input */
  133. out6 = inA6 * inB3;
  134. /* read input from real input buffer */
  135. inB4 = pSrcReal[3];
  136. /* store result to destination bufer */
  137. pCmplxDst[0] = out1;
  138. /* multiply complex buffer real input with real buffer input */
  139. out7 = inA7 * inB4;
  140. /* store result to destination bufer */
  141. pCmplxDst[1] = out2;
  142. /* multiply complex buffer imaginary input with real buffer input */
  143. out8 = inA8 * inB4;
  144. /* store result to destination bufer */
  145. pCmplxDst[2] = out3;
  146. pCmplxDst[3] = out4;
  147. pCmplxDst[4] = out5;
  148. /* incremnet complex input buffer by 8 to process next samples */
  149. pSrcCmplx += 8u;
  150. /* store result to destination bufer */
  151. pCmplxDst[5] = out6;
  152. /* increment real input buffer by 4 to process next samples */
  153. pSrcReal += 4u;
  154. /* store result to destination bufer */
  155. pCmplxDst[6] = out7;
  156. pCmplxDst[7] = out8;
  157. /* increment destination buffer by 8 to process next sampels */
  158. pCmplxDst += 8u;
  159. /* Decrement the numSamples loop counter */
  160. blkCnt--;
  161. }
  162. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  163. ** No loop unrolling is used. */
  164. blkCnt = numSamples % 0x4u;
  165. #else
  166. /* Run the below code for Cortex-M0 */
  167. blkCnt = numSamples;
  168. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  169. while(blkCnt > 0u)
  170. {
  171. /* C[2 * i] = A[2 * i] * B[i]. */
  172. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  173. in = *pSrcReal++;
  174. /* store the result in the destination buffer. */
  175. *pCmplxDst++ = (*pSrcCmplx++) * (in);
  176. *pCmplxDst++ = (*pSrcCmplx++) * (in);
  177. /* Decrement the numSamples loop counter */
  178. blkCnt--;
  179. }
  180. }
  181. /**
  182. * @} end of CmplxByRealMult group
  183. */