Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / filter / qa_gr_rotator.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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 #include <cppunit/TestAssert.h>
24 #include <qa_gr_rotator.h>
25 #include <gr_rotator.h>
26 #include <stdio.h>
27 #include <cmath>
28 #include <gr_expj.h>
29
30
31 // error vector magnitude
32 __attribute__((unused)) static float
33 error_vector_mag(gr_complex a, gr_complex b) 
34 {
35   return abs(a-b);
36 }
37
38 void
39 qa_gr_rotator::t1 ()
40 {
41   static const unsigned int N = 100000;
42
43   gr_rotator    r;
44
45   double phase_incr = 2*M_PI / 1003;
46   double phase = 0;
47
48   // Old code: We increment then return the rotated value, thus we need to start one tick back
49   // r.set_phase(gr_complex(1,0) * conj(gr_expj(phase_incr)));
50
51   r.set_phase(gr_complex(1,0));
52   r.set_phase_incr(gr_expj(phase_incr));
53
54   for (unsigned i = 0; i < N; i++){
55     gr_complex expected = gr_expj(phase);
56     gr_complex actual = r.rotate(gr_complex(1, 0));
57
58 #if 0
59     float evm = error_vector_mag(expected, actual);
60     printf("[%6d] expected: (%8.6f, %8.6f)  actual: (%8.6f, %8.6f)  evm: %8.6f\n",
61            i, expected.real(), expected.imag(), actual.real(), actual.imag(), evm);
62 #endif
63
64     CPPUNIT_ASSERT_COMPLEXES_EQUAL(expected, actual, 0.0001);
65
66     phase += phase_incr;
67     if (phase >= 2*M_PI)
68       phase -= 2*M_PI;
69   }
70 }