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.
 
 
 
 
 

188 lines
5.8 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_q31.c
  9. *
  10. * Description: Q31 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 Q31 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.31 by 1.31 multiplications are performed with 64-bit precision and then shifted to 16.48 format.
  61. * The internal real and imaginary accumulators are in 16.48 format and provide 15 guard bits.
  62. * Additions are nonsaturating and no overflow will occur as long as <code>numSamples</code> is less than 32768.
  63. * The return results <code>realResult</code> and <code>imagResult</code> are in 16.48 format.
  64. * Input down scaling is not required.
  65. */
  66. void arm_cmplx_dot_prod_q31(
  67. q31_t * pSrcA,
  68. q31_t * pSrcB,
  69. uint32_t numSamples,
  70. q63_t * realResult,
  71. q63_t * imagResult)
  72. {
  73. q63_t real_sum = 0, imag_sum = 0; /* Temporary result storage */
  74. q31_t a0,b0,c0,d0;
  75. #ifndef ARM_MATH_CM0_FAMILY
  76. /* Run the below code for Cortex-M4 and Cortex-M3 */
  77. uint32_t blkCnt; /* loop counter */
  78. /*loop Unrolling */
  79. blkCnt = numSamples >> 2u;
  80. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  81. ** a second loop below computes the remaining 1 to 3 samples. */
  82. while(blkCnt > 0u)
  83. {
  84. a0 = *pSrcA++;
  85. b0 = *pSrcA++;
  86. c0 = *pSrcB++;
  87. d0 = *pSrcB++;
  88. real_sum += ((q63_t)a0 * c0) >> 14;
  89. imag_sum += ((q63_t)a0 * d0) >> 14;
  90. real_sum -= ((q63_t)b0 * d0) >> 14;
  91. imag_sum += ((q63_t)b0 * c0) >> 14;
  92. a0 = *pSrcA++;
  93. b0 = *pSrcA++;
  94. c0 = *pSrcB++;
  95. d0 = *pSrcB++;
  96. real_sum += ((q63_t)a0 * c0) >> 14;
  97. imag_sum += ((q63_t)a0 * d0) >> 14;
  98. real_sum -= ((q63_t)b0 * d0) >> 14;
  99. imag_sum += ((q63_t)b0 * c0) >> 14;
  100. a0 = *pSrcA++;
  101. b0 = *pSrcA++;
  102. c0 = *pSrcB++;
  103. d0 = *pSrcB++;
  104. real_sum += ((q63_t)a0 * c0) >> 14;
  105. imag_sum += ((q63_t)a0 * d0) >> 14;
  106. real_sum -= ((q63_t)b0 * d0) >> 14;
  107. imag_sum += ((q63_t)b0 * c0) >> 14;
  108. a0 = *pSrcA++;
  109. b0 = *pSrcA++;
  110. c0 = *pSrcB++;
  111. d0 = *pSrcB++;
  112. real_sum += ((q63_t)a0 * c0) >> 14;
  113. imag_sum += ((q63_t)a0 * d0) >> 14;
  114. real_sum -= ((q63_t)b0 * d0) >> 14;
  115. imag_sum += ((q63_t)b0 * c0) >> 14;
  116. /* Decrement the loop counter */
  117. blkCnt--;
  118. }
  119. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  120. ** No loop unrolling is used. */
  121. blkCnt = numSamples % 0x4u;
  122. while(blkCnt > 0u)
  123. {
  124. a0 = *pSrcA++;
  125. b0 = *pSrcA++;
  126. c0 = *pSrcB++;
  127. d0 = *pSrcB++;
  128. real_sum += ((q63_t)a0 * c0) >> 14;
  129. imag_sum += ((q63_t)a0 * d0) >> 14;
  130. real_sum -= ((q63_t)b0 * d0) >> 14;
  131. imag_sum += ((q63_t)b0 * c0) >> 14;
  132. /* Decrement the loop counter */
  133. blkCnt--;
  134. }
  135. #else
  136. /* Run the below code for Cortex-M0 */
  137. while(numSamples > 0u)
  138. {
  139. a0 = *pSrcA++;
  140. b0 = *pSrcA++;
  141. c0 = *pSrcB++;
  142. d0 = *pSrcB++;
  143. real_sum += ((q63_t)a0 * c0) >> 14;
  144. imag_sum += ((q63_t)a0 * d0) >> 14;
  145. real_sum -= ((q63_t)b0 * d0) >> 14;
  146. imag_sum += ((q63_t)b0 * c0) >> 14;
  147. /* Decrement the loop counter */
  148. numSamples--;
  149. }
  150. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  151. /* Store the real and imaginary results in 16.48 format */
  152. *realResult = real_sum;
  153. *imagResult = imag_sum;
  154. }
  155. /**
  156. * @} end of cmplx_dot_prod group
  157. */