GNU Radio Manual and C++ API Reference  3.7.6.1
The Free & Open Software Radio Ecosystem
volk_32fc_s32f_power_32fc.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_volk_32fc_s32f_power_32fc_a_H
24 #define INCLUDED_volk_32fc_s32f_power_32fc_a_H
25 
26 #include <inttypes.h>
27 #include <stdio.h>
28 #include <math.h>
29 
30 //! raise a complex float to a real float power
31 static inline lv_32fc_t __volk_s32fc_s32f_power_s32fc_a(const lv_32fc_t exp, const float power){
32  const float arg = power*atan2f(lv_creal(exp), lv_cimag(exp));
33  const float mag = powf(lv_creal(exp)*lv_creal(exp) + lv_cimag(exp)*lv_cimag(exp), power/2);
34  return mag*lv_cmake(-cosf(arg), sinf(arg));
35 }
36 
37 #ifdef LV_HAVE_SSE
38 #include <xmmintrin.h>
39 
40 #ifdef LV_HAVE_LIB_SIMDMATH
41 #include <simdmath.h>
42 #endif /* LV_HAVE_LIB_SIMDMATH */
43 
44 /*!
45  \brief Takes each the input complex vector value to the specified power and stores the results in the return vector
46  \param cVector The vector where the results will be stored
47  \param aVector The complex vector of values to be taken to a power
48  \param power The power value to be applied to each data point
49  \param num_points The number of values in aVector to be taken to the specified power level and stored into cVector
50 */
51 static inline void volk_32fc_s32f_power_32fc_a_sse(lv_32fc_t* cVector, const lv_32fc_t* aVector, const float power, unsigned int num_points){
52  unsigned int number = 0;
53 
54  lv_32fc_t* cPtr = cVector;
55  const lv_32fc_t* aPtr = aVector;
56 
57 #ifdef LV_HAVE_LIB_SIMDMATH
58  const unsigned int quarterPoints = num_points / 4;
59  __m128 vPower = _mm_set_ps1(power);
60 
61  __m128 cplxValue1, cplxValue2, magnitude, phase, iValue, qValue;
62  for(;number < quarterPoints; number++){
63 
64  cplxValue1 = _mm_load_ps((float*)aPtr);
65  aPtr += 2;
66 
67  cplxValue2 = _mm_load_ps((float*)aPtr);
68  aPtr += 2;
69 
70  // Convert to polar coordinates
71 
72  // Arrange in i1i2i3i4 format
73  iValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2,0,2,0));
74  // Arrange in q1q2q3q4 format
75  qValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(3,1,3,1));
76 
77  phase = atan2f4(qValue, iValue); // Calculate the Phase
78 
79  magnitude = _mm_sqrt_ps(_mm_add_ps(_mm_mul_ps(iValue, iValue), _mm_mul_ps(qValue, qValue))); // Calculate the magnitude by square rooting the added I2 and Q2 values
80 
81  // Now calculate the power of the polar coordinate data
82  magnitude = powf4(magnitude, vPower); // Take the magnitude to the specified power
83 
84  phase = _mm_mul_ps(phase, vPower); // Multiply the phase by the specified power
85 
86  // Convert back to cartesian coordinates
87  iValue = _mm_mul_ps( cosf4(phase), magnitude); // Multiply the cos of the phase by the magnitude
88  qValue = _mm_mul_ps( sinf4(phase), magnitude); // Multiply the sin of the phase by the magnitude
89 
90  cplxValue1 = _mm_unpacklo_ps(iValue, qValue); // Interleave the lower two i & q values
91  cplxValue2 = _mm_unpackhi_ps(iValue, qValue); // Interleave the upper two i & q values
92 
93  _mm_store_ps((float*)cPtr,cplxValue1); // Store the results back into the C container
94 
95  cPtr += 2;
96 
97  _mm_store_ps((float*)cPtr,cplxValue2); // Store the results back into the C container
98 
99  cPtr += 2;
100  }
101 
102  number = quarterPoints * 4;
103 #endif /* LV_HAVE_LIB_SIMDMATH */
104 
105  for(;number < num_points; number++){
106  *cPtr++ = __volk_s32fc_s32f_power_s32fc_a((*aPtr++), power);
107  }
108 }
109 #endif /* LV_HAVE_SSE */
110 
111 #ifdef LV_HAVE_GENERIC
112  /*!
113  \brief Takes each the input complex vector value to the specified power and stores the results in the return vector
114  \param cVector The vector where the results will be stored
115  \param aVector The complex vector of values to be taken to a power
116  \param power The power value to be applied to each data point
117  \param num_points The number of values in aVector to be taken to the specified power level and stored into cVector
118  */
119 static inline void volk_32fc_s32f_power_32fc_generic(lv_32fc_t* cVector, const lv_32fc_t* aVector, const float power, unsigned int num_points){
120  lv_32fc_t* cPtr = cVector;
121  const lv_32fc_t* aPtr = aVector;
122  unsigned int number = 0;
123 
124  for(number = 0; number < num_points; number++){
125  *cPtr++ = __volk_s32fc_s32f_power_s32fc_a((*aPtr++), power);
126  }
127 }
128 #endif /* LV_HAVE_GENERIC */
129 
130 
131 
132 
133 #endif /* INCLUDED_volk_32fc_s32f_power_32fc_a_H */
static lv_32fc_t __volk_s32fc_s32f_power_s32fc_a(const lv_32fc_t exp, const float power)
raise a complex float to a real float power
Definition: volk_32fc_s32f_power_32fc.h:31
#define lv_cmake(r, i)
Definition: volk_complex.h:59
float complex lv_32fc_t
Definition: volk_complex.h:56
#define lv_creal(x)
Definition: volk_complex.h:76
#define lv_cimag(x)
Definition: volk_complex.h:78