arm_cmplx_mag_f64.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mag_f64.c
  4. * Description: Floating-point complex magnitude
  5. *
  6. * $Date: 13 September 2021
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/complex_math_functions.h"
  29. /**
  30. @ingroup groupCmplxMath
  31. */
  32. /**
  33. @defgroup cmplx_mag Complex Magnitude
  34. Computes the magnitude of 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 where the result should be written.
  37. <code>numSamples</code> specifies the number of complex samples
  38. in the input array and the data is stored in an interleaved fashion
  39. (real, imag, real, imag, ...).
  40. The input array has a total of <code>2*numSamples</code> values;
  41. the output array has a total of <code>numSamples</code> values.
  42. The underlying algorithm is used:
  43. <pre>
  44. for (n = 0; n < numSamples; n++) {
  45. pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2);
  46. }
  47. </pre>
  48. There are separate functions for floating-point, Q15, and Q31 data types.
  49. */
  50. /**
  51. @addtogroup cmplx_mag
  52. @{
  53. */
  54. /**
  55. @brief Floating-point complex magnitude.
  56. @param[in] pSrc points to input vector
  57. @param[out] pDst points to output vector
  58. @param[in] numSamples number of samples in each vector
  59. @return none
  60. */
  61. void arm_cmplx_mag_f64(
  62. const float64_t * pSrc,
  63. float64_t * pDst,
  64. uint32_t numSamples)
  65. {
  66. uint32_t blkCnt; /* loop counter */
  67. float64_t real, imag; /* Temporary variables to hold input values */
  68. /* Initialize blkCnt with number of samples */
  69. blkCnt = numSamples;
  70. while (blkCnt > 0U)
  71. {
  72. /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
  73. real = *pSrc++;
  74. imag = *pSrc++;
  75. /* store result in destination buffer. */
  76. *pDst++ = sqrt((real * real) + (imag * imag));
  77. /* Decrement loop counter */
  78. blkCnt--;
  79. }
  80. }
  81. /**
  82. @} end of cmplx_mag group
  83. */