3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
23 #include <cppunit/TestAssert.h>
24 #include <qa_gr_rotator.h>
25 #include <gr_rotator.h>
31 // error vector magnitude
32 __attribute__((unused)) static float
33 error_vector_mag(gr_complex a, gr_complex b)
41 static const unsigned int N = 100000;
45 double phase_incr = 2*M_PI / 1003;
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)));
51 r.set_phase(gr_complex(1,0));
52 r.set_phase_incr(gr_expj(phase_incr));
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));
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);
64 CPPUNIT_ASSERT_COMPLEXES_EQUAL(expected, actual, 0.0001);