Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / general / qa_gr_fxpt_vco.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2005 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 2, 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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 #include <qa_gr_fxpt_vco.h>
27 #include <gr_fxpt_vco.h>
28 #include <gr_vco.h>
29 #include <cppunit/TestAssert.h>
30 #include <iostream>
31 #include <stdio.h>
32 #include <unistd.h>
33 #include <math.h>
34
35 static const float SIN_COS_TOLERANCE = 1e-5;
36
37 static const float SIN_COS_K = 0.42;
38 static const float SIN_COS_AMPL = 0.8;
39
40 static const int SIN_COS_BLOCK_SIZE = 100000;
41
42 static double max_d(double a, double b)
43 {
44   return fabs(a) > fabs(b) ? a : b;
45 }
46
47 void
48 qa_gr_fxpt_vco::t0 ()
49 {
50   gr_vco<float,float>   ref_vco;
51   gr_fxpt_vco           new_vco;
52   double max_error = 0, max_phase_error = 0;
53   float                 input[SIN_COS_BLOCK_SIZE];
54
55   for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
56           input[i] = sin(i);
57   }
58
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);
63
64     max_error = max_d (max_error, ref_cos-new_cos);
65
66     ref_vco.adjust_phase (input[i]);
67     new_vco.adjust_phase (input[i]);
68
69     CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE);
70
71     max_phase_error = max_d (max_phase_error, ref_vco.get_phase()-new_vco.get_phase());
72   }
73   // printf ("Fxpt  max error %.9f, max phase error %.9f\n", max_error, max_phase_error);
74 }
75
76
77 void
78 qa_gr_fxpt_vco::t1 ()
79 {
80   gr_vco<float,float>   ref_vco;
81   gr_fxpt_vco           new_vco;
82   float                 ref_block[SIN_COS_BLOCK_SIZE];
83   float                 new_block[SIN_COS_BLOCK_SIZE];
84   float                 input[SIN_COS_BLOCK_SIZE];
85   double max_error = 0;
86
87   for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){
88           input[i] = sin(i);
89   }
90
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);
93
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]);
97   }
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());
100 }
101
102 void
103 qa_gr_fxpt_vco::t2 ()
104 {
105 }
106
107 void
108 qa_gr_fxpt_vco::t3 ()
109 {
110 }