diff options
author | Tom Rondeau | 2012-10-30 22:16:54 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-10-30 22:16:54 -0400 |
commit | c8b0062aeb430e9e8655014a430e5a8899278881 (patch) | |
tree | b07685a62507f62b384496316c6e53fda49712ad /gr-analog/lib | |
parent | 1c5accf1a195616f241f0a31f07e5a1847a3941d (diff) | |
download | gnuradio-c8b0062aeb430e9e8655014a430e5a8899278881.tar.gz gnuradio-c8b0062aeb430e9e8655014a430e5a8899278881.tar.bz2 gnuradio-c8b0062aeb430e9e8655014a430e5a8899278881.zip |
analog: adding rotator to gr-analog with QA.
Diffstat (limited to 'gr-analog/lib')
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/lib/qa_analog.cc | 2 | ||||
-rw-r--r-- | gr-analog/lib/qa_rotator.cc | 81 | ||||
-rw-r--r-- | gr-analog/lib/qa_rotator.h | 45 |
4 files changed, 129 insertions, 0 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index e0e621d13..c93c220cc 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -153,6 +153,7 @@ if(ENABLE_TESTING) ${CMAKE_CURRENT_SOURCE_DIR}/test_gr_analog.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_analog.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_sincos.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_rotator.cc ) add_executable(test-gr-analog ${test_gr_analog_sources}) diff --git a/gr-analog/lib/qa_analog.cc b/gr-analog/lib/qa_analog.cc index ceecb096d..c3d51863b 100644 --- a/gr-analog/lib/qa_analog.cc +++ b/gr-analog/lib/qa_analog.cc @@ -27,6 +27,7 @@ #include <qa_analog.h> #include <qa_sincos.h> +#include <qa_rotator.h> CppUnit::TestSuite * qa_gr_analog::suite() @@ -34,6 +35,7 @@ qa_gr_analog::suite() CppUnit::TestSuite *s = new CppUnit::TestSuite("gr-analog"); s->addTest(gr::analog::qa_sincos::suite()); + s->addTest(gr::analog::qa_rotator::suite()); return s; } diff --git a/gr-analog/lib/qa_rotator.cc b/gr-analog/lib/qa_rotator.cc new file mode 100644 index 000000000..b722f32c4 --- /dev/null +++ b/gr-analog/lib/qa_rotator.cc @@ -0,0 +1,81 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gruel/attributes.h> +#include <cppunit/TestAssert.h> +#include <qa_rotator.h> +#include <analog/rotator.h> +#include <stdio.h> +#include <cmath> +#include <gr_expj.h> + +namespace gr { + namespace analog { + + // error vector magnitude + __GR_ATTR_UNUSED static float + error_vector_mag(gr_complex a, gr_complex b) + { + return abs(a-b); + } + + void + qa_rotator::t1() + { + static const unsigned int N = 100000; + + rotator r; + + double phase_incr = 2*M_PI / 1003; + double phase = 0; + + // Old code: We increment then return the rotated value, thus we + // need to start one tick back + // r.set_phase(gr_complex(1,0) * conj(gr_expj(phase_incr))); + + r.set_phase(gr_complex(1,0)); + r.set_phase_incr(gr_expj(phase_incr)); + + for(unsigned i = 0; i < N; i++) { + gr_complex expected = gr_expj(phase); + gr_complex actual = r.rotate(gr_complex(1, 0)); + +#if 0 + float evm = error_vector_mag(expected, actual); + printf("[%6d] expected: (%8.6f, %8.6f) actual: (%8.6f, %8.6f) evm: %8.6f\n", + i, expected.real(), expected.imag(), actual.real(), actual.imag(), evm); +#endif + + CPPUNIT_ASSERT_COMPLEXES_EQUAL(expected, actual, 0.0001); + + phase += phase_incr; + if(phase >= 2*M_PI) + phase -= 2*M_PI; + } + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/qa_rotator.h b/gr-analog/lib/qa_rotator.h new file mode 100644 index 000000000..a22e41ec2 --- /dev/null +++ b/gr-analog/lib/qa_rotator.h @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _QA_ANALOG_ROTATOR_H_ +#define _QA_ANALOG_ROTATOR_H_ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> + +namespace gr { + namespace analog { + + class qa_rotator : public CppUnit::TestCase + { + CPPUNIT_TEST_SUITE(qa_rotator); + CPPUNIT_TEST(t1); + CPPUNIT_TEST_SUITE_END(); + + private: + void t1(); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* _QA_ANALOG_ROTATOR_H_ */ |