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_squared_f32.c
4
 * Description:  Floating-point complex magnitude squared
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_squared Complex Magnitude Squared
37
 *
38
 * Computes the magnitude squared 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
 *
48
 * The underlying algorithm is used:
49
 *
50
 * <pre>
51
 * for(n=0; n<numSamples; n++) {
52
 *     pDst[n] = pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2;
53
 * }
54
 * </pre>
55
 *
56
 * There are separate functions for floating-point, Q15, and Q31 data types.
57
 */
58
 
59
/**
60
 * @addtogroup cmplx_mag_squared
61
 * @{
62
 */
63
 
64
 
65
/**
66
 * @brief  Floating-point complex magnitude squared
67
 * @param[in]  *pSrc points to the complex input vector
68
 * @param[out]  *pDst points to the real output vector
69
 * @param[in]  numSamples number of complex samples in the input vector
70
 * @return none.
71
 */
72
 
73
void arm_cmplx_mag_squared_f32(
74
  float32_t * pSrc,
75
  float32_t * pDst,
76
  uint32_t numSamples)
77
{
78
  float32_t real, imag;                          /* Temporary variables to store real and imaginary values */
79
  uint32_t blkCnt;                               /* loop counter */
80
 
81
#if defined (ARM_MATH_DSP)
82
  float32_t real1, real2, real3, real4;          /* Temporary variables to hold real values */
83
  float32_t imag1, imag2, imag3, imag4;          /* Temporary variables to hold imaginary values */
84
  float32_t mul1, mul2, mul3, mul4;              /* Temporary variables */
85
  float32_t mul5, mul6, mul7, mul8;              /* Temporary variables */
86
  float32_t out1, out2, out3, out4;              /* Temporary variables to hold output values */
87
 
88
  /*loop Unrolling */
89
  blkCnt = numSamples >> 2U;
90
 
91
  /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
92
   ** a second loop below computes the remaining 1 to 3 samples. */
93
  while (blkCnt > 0U)
94
  {
95
    /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
96
    /* read real input sample from source buffer */
97
    real1 = pSrc[0];
98
    /* read imaginary input sample from source buffer */
99
    imag1 = pSrc[1];
100
 
101
    /* calculate power of real value */
102
    mul1 = real1 * real1;
103
 
104
    /* read real input sample from source buffer */
105
    real2 = pSrc[2];
106
 
107
    /* calculate power of imaginary value */
108
    mul2 = imag1 * imag1;
109
 
110
    /* read imaginary input sample from source buffer */
111
    imag2 = pSrc[3];
112
 
113
    /* calculate power of real value */
114
    mul3 = real2 * real2;
115
 
116
    /* read real input sample from source buffer */
117
    real3 = pSrc[4];
118
 
119
    /* calculate power of imaginary value */
120
    mul4 = imag2 * imag2;
121
 
122
    /* read imaginary input sample from source buffer */
123
    imag3 = pSrc[5];
124
 
125
    /* calculate power of real value */
126
    mul5 = real3 * real3;
127
    /* calculate power of imaginary value */
128
    mul6 = imag3 * imag3;
129
 
130
    /* read real input sample from source buffer */
131
    real4 = pSrc[6];
132
 
133
    /* accumulate real and imaginary powers */
134
    out1 = mul1 + mul2;
135
 
136
    /* read imaginary input sample from source buffer */
137
    imag4 = pSrc[7];
138
 
139
    /* accumulate real and imaginary powers */
140
    out2 = mul3 + mul4;
141
 
142
    /* calculate power of real value */
143
    mul7 = real4 * real4;
144
    /* calculate power of imaginary value */
145
    mul8 = imag4 * imag4;
146
 
147
    /* store output to destination */
148
    pDst[0] = out1;
149
 
150
    /* accumulate real and imaginary powers */
151
    out3 = mul5 + mul6;
152
 
153
    /* store output to destination */
154
    pDst[1] = out2;
155
 
156
    /* accumulate real and imaginary powers */
157
    out4 = mul7 + mul8;
158
 
159
    /* store output to destination */
160
    pDst[2] = out3;
161
 
162
    /* increment destination pointer by 8 to process next samples */
163
    pSrc += 8U;
164
 
165
    /* store output to destination */
166
    pDst[3] = out4;
167
 
168
    /* increment destination pointer by 4 to process next samples */
169
    pDst += 4U;
170
 
171
    /* Decrement the loop counter */
172
    blkCnt--;
173
  }
174
 
175
  /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
176
   ** No loop unrolling is used. */
177
  blkCnt = numSamples % 0x4U;
178
 
179
#else
180
 
181
  /* Run the below code for Cortex-M0 */
182
 
183
  blkCnt = numSamples;
184
 
185
#endif /* #if defined (ARM_MATH_DSP) */
186
 
187
  while (blkCnt > 0U)
188
  {
189
    /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
190
    real = *pSrc++;
191
    imag = *pSrc++;
192
 
193
    /* out = (real * real) + (imag * imag) */
194
    /* store the result in the destination buffer. */
195
    *pDst++ = (real * real) + (imag * imag);
196
 
197
    /* Decrement the loop counter */
198
    blkCnt--;
199
  }
200
}
201
 
202
/**
203
 * @} end of cmplx_mag_squared group
204
 */