A bundled STM32F10x Std Periph and CMSIS library
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

204 lignes
5.9 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_dot_prod_f32.c
  9. *
  10. * Description: Floating-point complex dot product
  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 cmplx_dot_prod Complex Dot Product
  46. *
  47. * Computes the dot product of two complex vectors.
  48. * The vectors are multiplied element-by-element and then summed.
  49. *
  50. * The <code>pSrcA</code> points to the first complex input vector and
  51. * <code>pSrcB</code> points to the second complex input vector.
  52. * <code>numSamples</code> specifies the number of complex samples
  53. * and the data in each array is stored in an interleaved fashion
  54. * (real, imag, real, imag, ...).
  55. * Each array has a total of <code>2*numSamples</code> values.
  56. *
  57. * The underlying algorithm is used:
  58. * <pre>
  59. * realResult=0;
  60. * imagResult=0;
  61. * for(n=0; n<numSamples; n++) {
  62. * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1];
  63. * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0];
  64. * }
  65. * </pre>
  66. *
  67. * There are separate functions for floating-point, Q15, and Q31 data types.
  68. */
  69. /**
  70. * @addtogroup cmplx_dot_prod
  71. * @{
  72. */
  73. /**
  74. * @brief Floating-point complex dot product
  75. * @param *pSrcA points to the first input vector
  76. * @param *pSrcB points to the second input vector
  77. * @param numSamples number of complex samples in each vector
  78. * @param *realResult real part of the result returned here
  79. * @param *imagResult imaginary part of the result returned here
  80. * @return none.
  81. */
  82. void arm_cmplx_dot_prod_f32(
  83. float32_t * pSrcA,
  84. float32_t * pSrcB,
  85. uint32_t numSamples,
  86. float32_t * realResult,
  87. float32_t * imagResult)
  88. {
  89. float32_t real_sum = 0.0f, imag_sum = 0.0f; /* Temporary result storage */
  90. float32_t a0,b0,c0,d0;
  91. #ifndef ARM_MATH_CM0_FAMILY
  92. /* Run the below code for Cortex-M4 and Cortex-M3 */
  93. uint32_t blkCnt; /* loop counter */
  94. /*loop Unrolling */
  95. blkCnt = numSamples >> 2u;
  96. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  97. ** a second loop below computes the remaining 1 to 3 samples. */
  98. while(blkCnt > 0u)
  99. {
  100. a0 = *pSrcA++;
  101. b0 = *pSrcA++;
  102. c0 = *pSrcB++;
  103. d0 = *pSrcB++;
  104. real_sum += a0 * c0;
  105. imag_sum += a0 * d0;
  106. real_sum -= b0 * d0;
  107. imag_sum += b0 * c0;
  108. a0 = *pSrcA++;
  109. b0 = *pSrcA++;
  110. c0 = *pSrcB++;
  111. d0 = *pSrcB++;
  112. real_sum += a0 * c0;
  113. imag_sum += a0 * d0;
  114. real_sum -= b0 * d0;
  115. imag_sum += b0 * c0;
  116. a0 = *pSrcA++;
  117. b0 = *pSrcA++;
  118. c0 = *pSrcB++;
  119. d0 = *pSrcB++;
  120. real_sum += a0 * c0;
  121. imag_sum += a0 * d0;
  122. real_sum -= b0 * d0;
  123. imag_sum += b0 * c0;
  124. a0 = *pSrcA++;
  125. b0 = *pSrcA++;
  126. c0 = *pSrcB++;
  127. d0 = *pSrcB++;
  128. real_sum += a0 * c0;
  129. imag_sum += a0 * d0;
  130. real_sum -= b0 * d0;
  131. imag_sum += b0 * c0;
  132. /* Decrement the loop counter */
  133. blkCnt--;
  134. }
  135. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  136. ** No loop unrolling is used. */
  137. blkCnt = numSamples & 0x3u;
  138. while(blkCnt > 0u)
  139. {
  140. a0 = *pSrcA++;
  141. b0 = *pSrcA++;
  142. c0 = *pSrcB++;
  143. d0 = *pSrcB++;
  144. real_sum += a0 * c0;
  145. imag_sum += a0 * d0;
  146. real_sum -= b0 * d0;
  147. imag_sum += b0 * c0;
  148. /* Decrement the loop counter */
  149. blkCnt--;
  150. }
  151. #else
  152. /* Run the below code for Cortex-M0 */
  153. while(numSamples > 0u)
  154. {
  155. a0 = *pSrcA++;
  156. b0 = *pSrcA++;
  157. c0 = *pSrcB++;
  158. d0 = *pSrcB++;
  159. real_sum += a0 * c0;
  160. imag_sum += a0 * d0;
  161. real_sum -= b0 * d0;
  162. imag_sum += b0 * c0;
  163. /* Decrement the loop counter */
  164. numSamples--;
  165. }
  166. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  167. /* Store the real and imaginary results in the destination buffers */
  168. *realResult = real_sum;
  169. *imagResult = imag_sum;
  170. }
  171. /**
  172. * @} end of cmplx_dot_prod group
  173. */