3 * Copyright 2004,2005 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 2, 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.
26 #include <qa_gr_fxpt_vco.h>
27 #include <gr_fxpt_vco.h>
29 #include <cppunit/TestAssert.h>
35 static const float SIN_COS_TOLERANCE = 1e-5;
37 static const float SIN_COS_K = 0.42;
38 static const float SIN_COS_AMPL = 0.8;
40 static const int SIN_COS_BLOCK_SIZE = 100000;
42 static double max_d(double a, double b)
44 return fabs(a) > fabs(b) ? a : b;
50 gr_vco<float,float> ref_vco;
52 double max_error = 0, max_phase_error = 0;
53 float input[SIN_COS_BLOCK_SIZE];
55 for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
59 for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
60 float ref_cos = ref_vco.cos ();
61 float new_cos = new_vco.cos ();
62 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_cos, new_cos, SIN_COS_TOLERANCE);
64 max_error = max_d (max_error, ref_cos-new_cos);
66 ref_vco.adjust_phase (input[i]);
67 new_vco.adjust_phase (input[i]);
69 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE);
71 max_phase_error = max_d (max_phase_error, ref_vco.get_phase()-new_vco.get_phase());
73 // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error);
80 gr_vco<float,float> ref_vco;
82 float ref_block[SIN_COS_BLOCK_SIZE];
83 float new_block[SIN_COS_BLOCK_SIZE];
84 float input[SIN_COS_BLOCK_SIZE];
87 for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
91 ref_vco.cos (ref_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL);
92 new_vco.cos (new_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL);
94 for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
95 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i], new_block[i], SIN_COS_TOLERANCE);
96 max_error = max_d (max_error, ref_block[i]-new_block[i]);
98 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE);
99 // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, ref_vco.get_phase()-new_vco.get_phase());
103 qa_gr_fxpt_vco::t2 ()
108 qa_gr_fxpt_vco::t3 ()