arm_cmplx_conj_f32.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_f32.c
  4. * Description: Floating-point complex conjugate
  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 cmplx_conj Complex Conjugate
  34. *
  35. * Conjugates the elements of a complex data vector.
  36. *
  37. * The <code>pSrc</code> points to the source data and
  38. * <code>pDst</code> points to the where the result should be written.
  39. * <code>numSamples</code> specifies the number of complex samples
  40. * and the data in each array is stored in an interleaved fashion
  41. * (real, imag, real, imag, ...).
  42. * Each array has a total of <code>2*numSamples</code> values.
  43. * The underlying algorithm is used:
  44. *
  45. * <pre>
  46. * for(n=0; n<numSamples; n++) {
  47. * pDst[(2*n)+0)] = pSrc[(2*n)+0]; // real part
  48. * pDst[(2*n)+1)] = -pSrc[(2*n)+1]; // imag part
  49. * }
  50. * </pre>
  51. *
  52. * There are separate functions for floating-point, Q15, and Q31 data types.
  53. */
  54. /**
  55. * @addtogroup cmplx_conj
  56. * @{
  57. */
  58. /**
  59. * @brief Floating-point complex conjugate.
  60. * @param *pSrc points to the input vector
  61. * @param *pDst points to the output vector
  62. * @param numSamples number of complex samples in each vector
  63. * @return none.
  64. */
  65. void arm_cmplx_conj_f32(
  66. float32_t * pSrc,
  67. float32_t * pDst,
  68. uint32_t numSamples)
  69. {
  70. uint32_t blkCnt; /* loop counter */
  71. #if defined (ARM_MATH_DSP)
  72. /* Run the below code for Cortex-M4 and Cortex-M3 */
  73. float32_t inR1, inR2, inR3, inR4;
  74. float32_t inI1, inI2, inI3, inI4;
  75. /*loop Unrolling */
  76. blkCnt = numSamples >> 2U;
  77. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  78. ** a second loop below computes the remaining 1 to 3 samples. */
  79. while (blkCnt > 0U)
  80. {
  81. /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  82. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  83. /* read real input samples */
  84. inR1 = pSrc[0];
  85. /* store real samples to destination */
  86. pDst[0] = inR1;
  87. inR2 = pSrc[2];
  88. pDst[2] = inR2;
  89. inR3 = pSrc[4];
  90. pDst[4] = inR3;
  91. inR4 = pSrc[6];
  92. pDst[6] = inR4;
  93. /* read imaginary input samples */
  94. inI1 = pSrc[1];
  95. inI2 = pSrc[3];
  96. /* conjugate input */
  97. inI1 = -inI1;
  98. /* read imaginary input samples */
  99. inI3 = pSrc[5];
  100. /* conjugate input */
  101. inI2 = -inI2;
  102. /* read imaginary input samples */
  103. inI4 = pSrc[7];
  104. /* conjugate input */
  105. inI3 = -inI3;
  106. /* store imaginary samples to destination */
  107. pDst[1] = inI1;
  108. pDst[3] = inI2;
  109. /* conjugate input */
  110. inI4 = -inI4;
  111. /* store imaginary samples to destination */
  112. pDst[5] = inI3;
  113. /* increment source pointer by 8 to process next sampels */
  114. pSrc += 8U;
  115. /* store imaginary sample to destination */
  116. pDst[7] = inI4;
  117. /* increment destination pointer by 8 to store next samples */
  118. pDst += 8U;
  119. /* Decrement the loop counter */
  120. blkCnt--;
  121. }
  122. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  123. ** No loop unrolling is used. */
  124. blkCnt = numSamples % 0x4U;
  125. #else
  126. /* Run the below code for Cortex-M0 */
  127. blkCnt = numSamples;
  128. #endif /* #if defined (ARM_MATH_DSP) */
  129. while (blkCnt > 0U)
  130. {
  131. /* realOut + j (imagOut) = realIn + j (-1) imagIn */
  132. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  133. *pDst++ = *pSrc++;
  134. *pDst++ = -*pSrc++;
  135. /* Decrement the loop counter */
  136. blkCnt--;
  137. }
  138. }
  139. /**
  140. * @} end of cmplx_conj group
  141. */