root / gnuradio-core / src / lib / general / qa_gr_fxpt_vco.cc @ 77a2d01c
History | View | Annotate | Download (3 kB)
| 1 | 5d69a524 | jcorgan | /* -*- c++ -*- */
|
|---|---|---|---|
| 2 | 5d69a524 | jcorgan | /*
|
| 3 | 5d69a524 | jcorgan | * Copyright 2004,2005 Free Software Foundation, Inc. |
| 4 | 5d69a524 | jcorgan | * |
| 5 | 5d69a524 | jcorgan | * This file is part of GNU Radio |
| 6 | 5d69a524 | jcorgan | * |
| 7 | 5d69a524 | jcorgan | * GNU Radio is free software; you can redistribute it and/or modify |
| 8 | 5d69a524 | jcorgan | * it under the terms of the GNU General Public License as published by |
| 9 | 937b719d | eb | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | 5d69a524 | jcorgan | * any later version. |
| 11 | 5d69a524 | jcorgan | * |
| 12 | 5d69a524 | jcorgan | * GNU Radio is distributed in the hope that it will be useful, |
| 13 | 5d69a524 | jcorgan | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | 5d69a524 | jcorgan | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | 5d69a524 | jcorgan | * GNU General Public License for more details. |
| 16 | 5d69a524 | jcorgan | * |
| 17 | 5d69a524 | jcorgan | * You should have received a copy of the GNU General Public License |
| 18 | 5d69a524 | jcorgan | * along with GNU Radio; see the file COPYING. If not, write to |
| 19 | 86f5c924 | eb | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | 86f5c924 | eb | * Boston, MA 02110-1301, USA. |
| 21 | 5d69a524 | jcorgan | */ |
| 22 | 5d69a524 | jcorgan | |
| 23 | 5d69a524 | jcorgan | #ifdef HAVE_CONFIG_H
|
| 24 | 5d69a524 | jcorgan | #include <config.h> |
| 25 | 5d69a524 | jcorgan | #endif
|
| 26 | 5d69a524 | jcorgan | #include <qa_gr_fxpt_vco.h> |
| 27 | 5d69a524 | jcorgan | #include <gr_fxpt_vco.h> |
| 28 | 5d69a524 | jcorgan | #include <gr_vco.h> |
| 29 | 5d69a524 | jcorgan | #include <cppunit/TestAssert.h> |
| 30 | 5d69a524 | jcorgan | #include <iostream> |
| 31 | 5d69a524 | jcorgan | #include <stdio.h> |
| 32 | 5d69a524 | jcorgan | #include <unistd.h> |
| 33 | 5d69a524 | jcorgan | #include <math.h> |
| 34 | 5d69a524 | jcorgan | |
| 35 | 5d69a524 | jcorgan | static const float SIN_COS_TOLERANCE = 1e-5; |
| 36 | 5d69a524 | jcorgan | |
| 37 | 5d69a524 | jcorgan | static const float SIN_COS_K = 0.42; |
| 38 | 5d69a524 | jcorgan | static const float SIN_COS_AMPL = 0.8; |
| 39 | 5d69a524 | jcorgan | |
| 40 | 5d69a524 | jcorgan | static const int SIN_COS_BLOCK_SIZE = 100000; |
| 41 | 5d69a524 | jcorgan | |
| 42 | 5d69a524 | jcorgan | static double max_d(double a, double b) |
| 43 | 5d69a524 | jcorgan | {
|
| 44 | 5d69a524 | jcorgan | return fabs(a) > fabs(b) ? a : b;
|
| 45 | 5d69a524 | jcorgan | } |
| 46 | 5d69a524 | jcorgan | |
| 47 | 5d69a524 | jcorgan | void
|
| 48 | 5d69a524 | jcorgan | qa_gr_fxpt_vco::t0 () |
| 49 | 5d69a524 | jcorgan | {
|
| 50 | 5d69a524 | jcorgan | gr_vco<float,float> ref_vco; |
| 51 | 5d69a524 | jcorgan | gr_fxpt_vco new_vco; |
| 52 | 5d69a524 | jcorgan | double max_error = 0, max_phase_error = 0; |
| 53 | 5d69a524 | jcorgan | float input[SIN_COS_BLOCK_SIZE];
|
| 54 | 5d69a524 | jcorgan | |
| 55 | 5d69a524 | jcorgan | for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){ |
| 56 | e4d3b484 | Josh Blum | input[i] = sin(double(i));
|
| 57 | 5d69a524 | jcorgan | } |
| 58 | 5d69a524 | jcorgan | |
| 59 | 5d69a524 | jcorgan | for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){ |
| 60 | 5d69a524 | jcorgan | float ref_cos = ref_vco.cos ();
|
| 61 | 5d69a524 | jcorgan | float new_cos = new_vco.cos ();
|
| 62 | 5d69a524 | jcorgan | CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_cos, new_cos, SIN_COS_TOLERANCE); |
| 63 | 5d69a524 | jcorgan | |
| 64 | 5d69a524 | jcorgan | max_error = max_d (max_error, ref_cos-new_cos); |
| 65 | 5d69a524 | jcorgan | |
| 66 | 5d69a524 | jcorgan | ref_vco.adjust_phase (input[i]); |
| 67 | 5d69a524 | jcorgan | new_vco.adjust_phase (input[i]); |
| 68 | 5d69a524 | jcorgan | |
| 69 | 5d69a524 | jcorgan | CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); |
| 70 | 5d69a524 | jcorgan | |
| 71 | 5d69a524 | jcorgan | max_phase_error = max_d (max_phase_error, ref_vco.get_phase()-new_vco.get_phase()); |
| 72 | 5d69a524 | jcorgan | } |
| 73 | 5d69a524 | jcorgan | // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error);
|
| 74 | 5d69a524 | jcorgan | } |
| 75 | 5d69a524 | jcorgan | |
| 76 | 5d69a524 | jcorgan | |
| 77 | 5d69a524 | jcorgan | void
|
| 78 | 5d69a524 | jcorgan | qa_gr_fxpt_vco::t1 () |
| 79 | 5d69a524 | jcorgan | {
|
| 80 | 5d69a524 | jcorgan | gr_vco<float,float> ref_vco; |
| 81 | 5d69a524 | jcorgan | gr_fxpt_vco new_vco; |
| 82 | 5d69a524 | jcorgan | float ref_block[SIN_COS_BLOCK_SIZE];
|
| 83 | 5d69a524 | jcorgan | float new_block[SIN_COS_BLOCK_SIZE];
|
| 84 | 5d69a524 | jcorgan | float input[SIN_COS_BLOCK_SIZE];
|
| 85 | 5d69a524 | jcorgan | double max_error = 0; |
| 86 | 5d69a524 | jcorgan | |
| 87 | 5d69a524 | jcorgan | for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){ |
| 88 | e4d3b484 | Josh Blum | input[i] = sin(double(i));
|
| 89 | 5d69a524 | jcorgan | } |
| 90 | 5d69a524 | jcorgan | |
| 91 | 5d69a524 | jcorgan | ref_vco.cos (ref_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL); |
| 92 | 5d69a524 | jcorgan | new_vco.cos (new_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL); |
| 93 | 5d69a524 | jcorgan | |
| 94 | 5d69a524 | jcorgan | for (int i = 0; i < SIN_COS_BLOCK_SIZE; i++){ |
| 95 | 5d69a524 | jcorgan | CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i], new_block[i], SIN_COS_TOLERANCE); |
| 96 | 5d69a524 | jcorgan | max_error = max_d (max_error, ref_block[i]-new_block[i]); |
| 97 | 5d69a524 | jcorgan | } |
| 98 | 5d69a524 | jcorgan | CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); |
| 99 | 5d69a524 | jcorgan | // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, ref_vco.get_phase()-new_vco.get_phase());
|
| 100 | 5d69a524 | jcorgan | } |
| 101 | 5d69a524 | jcorgan | |
| 102 | 5d69a524 | jcorgan | void
|
| 103 | 5d69a524 | jcorgan | qa_gr_fxpt_vco::t2 () |
| 104 | 5d69a524 | jcorgan | {
|
| 105 | 5d69a524 | jcorgan | } |
| 106 | 5d69a524 | jcorgan | |
| 107 | 5d69a524 | jcorgan | void
|
| 108 | 5d69a524 | jcorgan | qa_gr_fxpt_vco::t3 () |
| 109 | 5d69a524 | jcorgan | {
|
| 110 | 5d69a524 | jcorgan | } |