Subversion Repositories canSerial

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------
2
 * Project:      CMSIS DSP Library
3
 * Title:        arm_cmplx_mult_real_f32.c
4
 * Description:  Floating-point complex by real multiplication
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 CmplxByRealMult Complex-by-Real Multiplication
37
 *
38
 * Multiplies a complex vector by a real vector and generates a complex result.
39
 * The data in the complex arrays is stored in an interleaved fashion
40
 * (real, imag, real, imag, ...).
41
 * The parameter <code>numSamples</code> represents the number of complex
42
 * samples processed.  The complex arrays have a total of <code>2*numSamples</code>
43
 * real values while the real array has a total of <code>numSamples</code>
44
 * real values.
45
 *
46
 * The underlying algorithm is used:
47
 *
48
 * <pre>
49
 * for(n=0; n<numSamples; n++) {
50
 *     pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] * pSrcReal[n];
51
 *     pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal[n];
52
 * }
53
 * </pre>
54
 *
55
 * There are separate functions for floating-point, Q15, and Q31 data types.
56
 */
57
 
58
/**
59
 * @addtogroup CmplxByRealMult
60
 * @{
61
 */
62
 
63
 
64
/**
65
 * @brief  Floating-point complex-by-real multiplication
66
 * @param[in]  *pSrcCmplx points to the complex input vector
67
 * @param[in]  *pSrcReal points to the real input vector
68
 * @param[out]  *pCmplxDst points to the complex output vector
69
 * @param[in]  numSamples number of samples in each vector
70
 * @return none.
71
 */
72
 
73
void arm_cmplx_mult_real_f32(
74
  float32_t * pSrcCmplx,
75
  float32_t * pSrcReal,
76
  float32_t * pCmplxDst,
77
  uint32_t numSamples)
78
{
79
  float32_t in;                                  /* Temporary variable to store input value */
80
  uint32_t blkCnt;                               /* loop counters */
81
 
82
#if defined (ARM_MATH_DSP)
83
 
84
  /* Run the below code for Cortex-M4 and Cortex-M3 */
85
  float32_t inA1, inA2, inA3, inA4;              /* Temporary variables to hold input data */
86
  float32_t inA5, inA6, inA7, inA8;              /* Temporary variables to hold input data */
87
  float32_t inB1, inB2, inB3, inB4;              /* Temporary variables to hold input data */
88
  float32_t out1, out2, out3, out4;              /* Temporary variables to hold output data */
89
  float32_t out5, out6, out7, out8;              /* Temporary variables to hold output data */
90
 
91
  /* loop Unrolling */
92
  blkCnt = numSamples >> 2U;
93
 
94
  /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
95
   ** a second loop below computes the remaining 1 to 3 samples. */
96
  while (blkCnt > 0U)
97
  {
98
    /* C[2 * i] = A[2 * i] * B[i].            */
99
    /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
100
    /* read input from complex input buffer */
101
    inA1 = pSrcCmplx[0];
102
    inA2 = pSrcCmplx[1];
103
    /* read input from real input buffer */
104
    inB1 = pSrcReal[0];
105
 
106
    /* read input from complex input buffer */
107
    inA3 = pSrcCmplx[2];
108
 
109
    /* multiply complex buffer real input with real buffer input */
110
    out1 = inA1 * inB1;
111
 
112
    /* read input from complex input buffer */
113
    inA4 = pSrcCmplx[3];
114
 
115
    /* multiply complex buffer imaginary input with real buffer input */
116
    out2 = inA2 * inB1;
117
 
118
    /* read input from real input buffer */
119
    inB2 = pSrcReal[1];
120
    /* read input from complex input buffer */
121
    inA5 = pSrcCmplx[4];
122
 
123
    /* multiply complex buffer real input with real buffer input */
124
    out3 = inA3 * inB2;
125
 
126
    /* read input from complex input buffer */
127
    inA6 = pSrcCmplx[5];
128
    /* read input from real input buffer */
129
    inB3 = pSrcReal[2];
130
 
131
    /* multiply complex buffer imaginary input with real buffer input */
132
    out4 = inA4 * inB2;
133
 
134
    /* read input from complex input buffer */
135
    inA7 = pSrcCmplx[6];
136
 
137
    /* multiply complex buffer real input with real buffer input */
138
    out5 = inA5 * inB3;
139
 
140
    /* read input from complex input buffer */
141
    inA8 = pSrcCmplx[7];
142
 
143
    /* multiply complex buffer imaginary input with real buffer input */
144
    out6 = inA6 * inB3;
145
 
146
    /* read input from real input buffer */
147
    inB4 = pSrcReal[3];
148
 
149
    /* store result to destination bufer */
150
    pCmplxDst[0] = out1;
151
 
152
    /* multiply complex buffer real input with real buffer input */
153
    out7 = inA7 * inB4;
154
 
155
    /* store result to destination bufer */
156
    pCmplxDst[1] = out2;
157
 
158
    /* multiply complex buffer imaginary input with real buffer input */
159
    out8 = inA8 * inB4;
160
 
161
    /* store result to destination bufer */
162
    pCmplxDst[2] = out3;
163
    pCmplxDst[3] = out4;
164
    pCmplxDst[4] = out5;
165
 
166
    /* incremnet complex input buffer by 8 to process next samples */
167
    pSrcCmplx += 8U;
168
 
169
    /* store result to destination bufer */
170
    pCmplxDst[5] = out6;
171
 
172
    /* increment real input buffer by 4 to process next samples */
173
    pSrcReal += 4U;
174
 
175
    /* store result to destination bufer */
176
    pCmplxDst[6] = out7;
177
    pCmplxDst[7] = out8;
178
 
179
    /* increment destination buffer by 8 to process next sampels */
180
    pCmplxDst += 8U;
181
 
182
    /* Decrement the numSamples loop counter */
183
    blkCnt--;
184
  }
185
 
186
  /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
187
   ** No loop unrolling is used. */
188
  blkCnt = numSamples % 0x4U;
189
 
190
#else
191
 
192
  /* Run the below code for Cortex-M0 */
193
  blkCnt = numSamples;
194
 
195
#endif /* #if defined (ARM_MATH_DSP) */
196
 
197
  while (blkCnt > 0U)
198
  {
199
    /* C[2 * i] = A[2 * i] * B[i].            */
200
    /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
201
    in = *pSrcReal++;
202
    /* store the result in the destination buffer. */
203
    *pCmplxDst++ = (*pSrcCmplx++) * (in);
204
    *pCmplxDst++ = (*pSrcCmplx++) * (in);
205
 
206
    /* Decrement the numSamples loop counter */
207
    blkCnt--;
208
  }
209
}
210
 
211
/**
212
 * @} end of CmplxByRealMult group
213
 */