Subversion Repositories dashGPS

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------
2
 * Project:      CMSIS DSP Library
3
 * Title:        arm_cmplx_mag_f32.c
4
 * Description:  Floating-point complex magnitude
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
 
29
#include "arm_math.h"
30
 
31
/**
32
 * @ingroup groupCmplxMath
33
 */
34
 
35
/**
36
 * @defgroup cmplx_mag Complex Magnitude
37
 *
38
 * Computes the magnitude of the elements of a complex data vector.
39
 *
40
 * The <code>pSrc</code> points to the source data and
41
 * <code>pDst</code> points to the where the result should be written.
42
 * <code>numSamples</code> specifies the number of complex samples
43
 * in the input array and the data is stored in an interleaved fashion
44
 * (real, imag, real, imag, ...).
45
 * The input array has a total of <code>2*numSamples</code> values;
46
 * the output array has a total of <code>numSamples</code> values.
47
 * The underlying algorithm is used:
48
 *
49
 * <pre>
50
 * for(n=0; n<numSamples; n++) {
51
 *     pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2);
52
 * }
53
 * </pre>
54
 *
55
 * There are separate functions for floating-point, Q15, and Q31 data types.
56
 */
57
 
58
/**
59
 * @addtogroup cmplx_mag
60
 * @{
61
 */
62
/**
63
 * @brief Floating-point complex magnitude.
64
 * @param[in]       *pSrc points to complex input buffer
65
 * @param[out]      *pDst points to real output buffer
66
 * @param[in]       numSamples number of complex samples in the input vector
67
 * @return none.
68
 *
69
 */
70
 
71
 
72
void arm_cmplx_mag_f32(
73
  float32_t * pSrc,
74
  float32_t * pDst,
75
  uint32_t numSamples)
76
{
77
  float32_t realIn, imagIn;                      /* Temporary variables to hold input values */
78
 
79
#if defined (ARM_MATH_DSP)
80
 
81
  /* Run the below code for Cortex-M4 and Cortex-M3 */
82
  uint32_t blkCnt;                               /* loop counter */
83
 
84
  /*loop Unrolling */
85
  blkCnt = numSamples >> 2U;
86
 
87
  /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
88
   ** a second loop below computes the remaining 1 to 3 samples. */
89
  while (blkCnt > 0U)
90
  {
91
 
92
    /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
93
    realIn = *pSrc++;
94
    imagIn = *pSrc++;
95
    /* store the result in the destination buffer. */
96
    arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
97
 
98
    realIn = *pSrc++;
99
    imagIn = *pSrc++;
100
    arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
101
 
102
    realIn = *pSrc++;
103
    imagIn = *pSrc++;
104
    arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
105
 
106
    realIn = *pSrc++;
107
    imagIn = *pSrc++;
108
    arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
109
 
110
 
111
    /* Decrement the loop counter */
112
    blkCnt--;
113
  }
114
 
115
  /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
116
   ** No loop unrolling is used. */
117
  blkCnt = numSamples % 0x4U;
118
 
119
  while (blkCnt > 0U)
120
  {
121
    /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
122
    realIn = *pSrc++;
123
    imagIn = *pSrc++;
124
    /* store the result in the destination buffer. */
125
    arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
126
 
127
    /* Decrement the loop counter */
128
    blkCnt--;
129
  }
130
 
131
#else
132
 
133
  /* Run the below code for Cortex-M0 */
134
 
135
  while (numSamples > 0U)
136
  {
137
    /* out = sqrt((real * real) + (imag * imag)) */
138
    realIn = *pSrc++;
139
    imagIn = *pSrc++;
140
    /* store the result in the destination buffer. */
141
    arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
142
 
143
    /* Decrement the loop counter */
144
    numSamples--;
145
  }
146
 
147
#endif /* #if defined (ARM_MATH_DSP) */
148
 
149
}
150
 
151
/**
152
 * @} end of cmplx_mag group
153
 */