arm_cmplx_conj_f32.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_f32.c
  4. * Description: Floating-point complex conjugate
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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. Conjugates the elements of a complex data vector.
  35. The <code>pSrc</code> points to the source data and
  36. <code>pDst</code> points to the destination data where the result should be written.
  37. <code>numSamples</code> specifies the number of complex samples
  38. and the data in each array is stored in an interleaved fashion
  39. (real, imag, real, imag, ...).
  40. Each array has a total of <code>2*numSamples</code> values.
  41. The underlying algorithm is used:
  42. <pre>
  43. for (n = 0; n < numSamples; n++) {
  44. pDst[(2*n) ] = pSrc[(2*n) ]; // real part
  45. pDst[(2*n)+1] = -pSrc[(2*n)+1]; // imag part
  46. }
  47. </pre>
  48. There are separate functions for floating-point, Q15, and Q31 data types.
  49. */
  50. /**
  51. @addtogroup cmplx_conj
  52. @{
  53. */
  54. /**
  55. @brief Floating-point complex conjugate.
  56. @param[in] pSrc points to the input vector
  57. @param[out] pDst points to the output vector
  58. @param[in] numSamples number of samples in each vector
  59. @return none
  60. */
  61. void arm_cmplx_conj_f32(
  62. const float32_t * pSrc,
  63. float32_t * pDst,
  64. uint32_t numSamples)
  65. {
  66. uint32_t blkCnt; /* Loop counter */
  67. #if defined(ARM_MATH_NEON)
  68. float32x4_t zero;
  69. float32x4x2_t vec;
  70. zero = vdupq_n_f32(0.0);
  71. /* Compute 4 outputs at a time */
  72. blkCnt = numSamples >> 2U;
  73. while (blkCnt > 0U)
  74. {
  75. /* C[0]+jC[1] = A[0]+(-1)*jA[1] */
  76. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  77. vec = vld2q_f32(pSrc);
  78. vec.val[1] = vsubq_f32(zero,vec.val[1]);
  79. vst2q_f32(pDst,vec);
  80. /* Increment pointers */
  81. pSrc += 8;
  82. pDst += 8;
  83. /* Decrement the loop counter */
  84. blkCnt--;
  85. }
  86. /* Tail */
  87. blkCnt = numSamples & 0x3;
  88. #else
  89. #if defined (ARM_MATH_LOOPUNROLL)
  90. /* Loop unrolling: Compute 4 outputs at a time */
  91. blkCnt = numSamples >> 2U;
  92. while (blkCnt > 0U)
  93. {
  94. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  95. /* Calculate Complex Conjugate and store result in destination buffer. */
  96. *pDst++ = *pSrc++;
  97. *pDst++ = -*pSrc++;
  98. *pDst++ = *pSrc++;
  99. *pDst++ = -*pSrc++;
  100. *pDst++ = *pSrc++;
  101. *pDst++ = -*pSrc++;
  102. *pDst++ = *pSrc++;
  103. *pDst++ = -*pSrc++;
  104. /* Decrement loop counter */
  105. blkCnt--;
  106. }
  107. /* Loop unrolling: Compute remaining outputs */
  108. blkCnt = numSamples % 0x4U;
  109. #else
  110. /* Initialize blkCnt with number of samples */
  111. blkCnt = numSamples;
  112. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  113. #endif /* #if defined (ARM_MATH_NEON) */
  114. while (blkCnt > 0U)
  115. {
  116. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  117. /* Calculate Complex Conjugate and store result in destination buffer. */
  118. *pDst++ = *pSrc++;
  119. *pDst++ = -*pSrc++;
  120. /* Decrement loop counter */
  121. blkCnt--;
  122. }
  123. }
  124. /**
  125. @} end of cmplx_conj group
  126. */