3 * Copyright 2004 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.
26 #include <qa_gr_fxpt_nco.h>
27 #include <gr_fxpt_nco.h>
29 #include <cppunit/TestAssert.h>
35 static const float SIN_COS_TOLERANCE = 1e-5;
37 //static const float SIN_COS_FREQ = 5003;
38 static const float SIN_COS_FREQ = 4096;
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_nco<float,float> ref_nco;
52 double max_error = 0, max_phase_error = 0;
54 ref_nco.set_freq ((float)(2 * M_PI / SIN_COS_FREQ));
55 new_nco.set_freq ((float)(2 * M_PI / SIN_COS_FREQ));
57 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_nco.get_freq(), new_nco.get_freq(), SIN_COS_TOLERANCE);
59 for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
60 float ref_sin = ref_nco.sin ();
61 float new_sin = new_nco.sin ();
62 //printf ("i = %6d\n", i);
63 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_sin, new_sin, SIN_COS_TOLERANCE);
65 max_error = max_d (max_error, ref_sin-new_sin);
67 float ref_cos = ref_nco.cos ();
68 float new_cos = new_nco.cos ();
69 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_cos, new_cos, SIN_COS_TOLERANCE);
71 max_error = max_d (max_error, ref_cos-new_cos);
76 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_nco.get_phase(), new_nco.get_phase(), SIN_COS_TOLERANCE);
78 max_phase_error = max_d (max_phase_error, ref_nco.get_phase()-new_nco.get_phase());
80 // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error);
86 gr_nco<float,float> ref_nco;
88 gr_complex ref_block[SIN_COS_BLOCK_SIZE];
89 gr_complex new_block[SIN_COS_BLOCK_SIZE];
92 ref_nco.set_freq ((float)(2 * M_PI / SIN_COS_FREQ));
93 new_nco.set_freq ((float)(2 * M_PI / SIN_COS_FREQ));
95 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_nco.get_freq(), new_nco.get_freq(), SIN_COS_TOLERANCE);
97 ref_nco.sincos ((gr_complex*)ref_block, SIN_COS_BLOCK_SIZE);
98 new_nco.sincos ((gr_complex*)new_block, SIN_COS_BLOCK_SIZE);
100 for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
101 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i].real(), new_block[i].real(), SIN_COS_TOLERANCE);
102 max_error = max_d (max_error, ref_block[i].real()-new_block[i].real());
104 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i].imag(), new_block[i].imag(), SIN_COS_TOLERANCE);
105 max_error = max_d (max_error, ref_block[i].imag()-new_block[i].imag());
107 CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_nco.get_phase(), new_nco.get_phase(), SIN_COS_TOLERANCE);
108 // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error);
112 qa_gr_fxpt_nco::t2 ()
117 qa_gr_fxpt_nco::t3 ()