11#include < fmt/core.h>
2+ #include < cmath>
3+ #include < complex>
24#include < cstdlib>
35#include < iostream>
46#include < vector>
5- #include < complex>
7+
8+ typedef std::complex <float > cmplxf;
9+
10+ #include < volk/volk.h>
11+ #include < volk/volk_alloc.hh>
612
713
8- #include < volk/volk_complex.h>
14+ void cppmultiply (volk::vector<cmplxf>& result,
15+ volk::vector<cmplxf>& input0,
16+ volk::vector<cmplxf>& input1)
17+ {
18+ volk_32fc_x2_multiply_32fc (reinterpret_cast <lv_32fc_t *>(result.data ()),
19+ reinterpret_cast <lv_32fc_t *>(input0.data ()),
20+ reinterpret_cast <lv_32fc_t *>(input1.data ()),
21+ input0.size ());
22+ }
23+
24+ void function_test (int num_points)
25+ {
26+ volk::vector<cmplxf> in0 (num_points);
27+ volk::vector<cmplxf> in1 (num_points);
28+ volk::vector<cmplxf> out (num_points);
29+
30+ for (unsigned int ii = 0 ; ii < num_points; ++ii) {
31+ // Generate two tones
32+ float real_1 = std::cos (0 .3f * (float )ii);
33+ float imag_1 = std::sin (0 .3f * (float )ii);
34+ in0[ii] = cmplxf (real_1, imag_1);
35+ float real_2 = std::cos (0 .1f * (float )ii);
36+ float imag_2 = std::sin (0 .1f * (float )ii);
37+ in1[ii] = cmplxf (real_2, imag_2);
38+ }
39+
40+ cppmultiply (out, in0, in1);
41+
42+ for (int ii = 0 ; ii < num_points; ++ii) {
43+ cmplxf v0 = in0[ii];
44+ cmplxf v1 = in1[ii];
45+ cmplxf o = out[ii];
46+
47+ fmt::print (
48+ " in0=({:+.1f}{:+.1f}j), in1=({:+.1f}{:+.1f}j), out=({:+.1f}{:+.1f}j)\n " ,
49+ std::real (v0),
50+ std::imag (v0),
51+ std::real (v1),
52+ std::imag (v1),
53+ std::real (o),
54+ std::imag (o));
55+ }
56+ }
957
1058
1159int main (int argc, char * argv[])
1260{
61+ function_test (32 );
1362 lv_32fc_t fc_cpl[4 ];
1463 fmt::print (" float={}, complex float={}, complex float array[4]={}\n " ,
1564 sizeof (float ),
@@ -19,14 +68,13 @@ int main(int argc, char* argv[])
1968
2069 std::vector<lv_32fc_t > vec (4 );
2170 for (int i = 0 ; i < 4 ; i++) {
22- auto foo = std::complex <float >( (i + 3 ), (i + 8 ) );
71+ auto foo = std::complex <float >((i + 3 ), (i + 8 ));
2372 fmt::print (" std::complex: ({:+.1f}{:+.1f}j)\n " , std::real (foo), std::imag (foo));
24- lv_32fc_t bar = lv_32fc_t {5 , 6 };
73+ lv_32fc_t bar = lv_32fc_t { 5 , 6 };
2574 vec.at (i) = bar;
26-
2775 }
2876
29- for (auto & val : vec){
77+ for (auto & val : vec) {
3078 float r = __real__ val;
3179 float i = __imag__ val;
3280 fmt::print (" sizeof(val)={}, {:+.1f}{:+.1f}j\n " , sizeof (val), r, i);
0 commit comments