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.
 
 
 
 
 

190 lignes
5.6 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_q15.c
  9. *
  10. * Description: Processing function for the Q15 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. * @addtogroup cmplx_dot_prod
  46. * @{
  47. */
  48. /**
  49. * @brief Q15 complex dot product
  50. * @param *pSrcA points to the first input vector
  51. * @param *pSrcB points to the second input vector
  52. * @param numSamples number of complex samples in each vector
  53. * @param *realResult real part of the result returned here
  54. * @param *imagResult imaginary part of the result returned here
  55. * @return none.
  56. *
  57. * <b>Scaling and Overflow Behavior:</b>
  58. * \par
  59. * The function is implemented using an internal 64-bit accumulator.
  60. * The intermediate 1.15 by 1.15 multiplications are performed with full precision and yield a 2.30 result.
  61. * These are accumulated in a 64-bit accumulator with 34.30 precision.
  62. * As a final step, the accumulators are converted to 8.24 format.
  63. * The return results <code>realResult</code> and <code>imagResult</code> are in 8.24 format.
  64. */
  65. void arm_cmplx_dot_prod_q15(
  66. q15_t * pSrcA,
  67. q15_t * pSrcB,
  68. uint32_t numSamples,
  69. q31_t * realResult,
  70. q31_t * imagResult)
  71. {
  72. q63_t real_sum = 0, imag_sum = 0; /* Temporary result storage */
  73. q15_t a0,b0,c0,d0;
  74. #ifndef ARM_MATH_CM0_FAMILY
  75. /* Run the below code for Cortex-M4 and Cortex-M3 */
  76. uint32_t blkCnt; /* loop counter */
  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. a0 = *pSrcA++;
  84. b0 = *pSrcA++;
  85. c0 = *pSrcB++;
  86. d0 = *pSrcB++;
  87. real_sum += (q31_t)a0 * c0;
  88. imag_sum += (q31_t)a0 * d0;
  89. real_sum -= (q31_t)b0 * d0;
  90. imag_sum += (q31_t)b0 * c0;
  91. a0 = *pSrcA++;
  92. b0 = *pSrcA++;
  93. c0 = *pSrcB++;
  94. d0 = *pSrcB++;
  95. real_sum += (q31_t)a0 * c0;
  96. imag_sum += (q31_t)a0 * d0;
  97. real_sum -= (q31_t)b0 * d0;
  98. imag_sum += (q31_t)b0 * c0;
  99. a0 = *pSrcA++;
  100. b0 = *pSrcA++;
  101. c0 = *pSrcB++;
  102. d0 = *pSrcB++;
  103. real_sum += (q31_t)a0 * c0;
  104. imag_sum += (q31_t)a0 * d0;
  105. real_sum -= (q31_t)b0 * d0;
  106. imag_sum += (q31_t)b0 * c0;
  107. a0 = *pSrcA++;
  108. b0 = *pSrcA++;
  109. c0 = *pSrcB++;
  110. d0 = *pSrcB++;
  111. real_sum += (q31_t)a0 * c0;
  112. imag_sum += (q31_t)a0 * d0;
  113. real_sum -= (q31_t)b0 * d0;
  114. imag_sum += (q31_t)b0 * c0;
  115. /* Decrement the loop counter */
  116. blkCnt--;
  117. }
  118. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  119. ** No loop unrolling is used. */
  120. blkCnt = numSamples % 0x4u;
  121. while(blkCnt > 0u)
  122. {
  123. a0 = *pSrcA++;
  124. b0 = *pSrcA++;
  125. c0 = *pSrcB++;
  126. d0 = *pSrcB++;
  127. real_sum += (q31_t)a0 * c0;
  128. imag_sum += (q31_t)a0 * d0;
  129. real_sum -= (q31_t)b0 * d0;
  130. imag_sum += (q31_t)b0 * c0;
  131. /* Decrement the loop counter */
  132. blkCnt--;
  133. }
  134. #else
  135. /* Run the below code for Cortex-M0 */
  136. while(numSamples > 0u)
  137. {
  138. a0 = *pSrcA++;
  139. b0 = *pSrcA++;
  140. c0 = *pSrcB++;
  141. d0 = *pSrcB++;
  142. real_sum += a0 * c0;
  143. imag_sum += a0 * d0;
  144. real_sum -= b0 * d0;
  145. imag_sum += b0 * c0;
  146. /* Decrement the loop counter */
  147. numSamples--;
  148. }
  149. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  150. /* Store the real and imaginary results in 8.24 format */
  151. /* Convert real data in 34.30 to 8.24 by 6 right shifts */
  152. *realResult = (q31_t) (real_sum >> 6);
  153. /* Convert imaginary data in 34.30 to 8.24 by 6 right shifts */
  154. *imagResult = (q31_t) (imag_sum >> 6);
  155. }
  156. /**
  157. * @} end of cmplx_dot_prod group
  158. */