gnuradio-core: trial "fix" for QA failure with debian gcc 4.4.4
[debian/gnuradio] / gnuradio-core / src / lib / filter / qa_gri_mmse_fir_interpolator.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002,2010 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 3, 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 #include <cppunit/TestAssert.h>
24 #include <qa_gri_mmse_fir_interpolator.h>
25 #include <gri_mmse_fir_interpolator.h>
26 #include <stdio.h>
27 #include <cmath>
28 #include <cstring>
29
30 #define NELEM(x) (sizeof (x) / sizeof (x[0]))
31
32
33 static float
34 test_fcn (double index)
35 {
36   return (2 * sin (index * 0.25 * 2 * M_PI + 0.125 * M_PI)
37           + 3 * sin (index * 0.077 * 2 * M_PI + 0.3 * M_PI));
38 }
39
40
41 void
42 qa_gri_mmse_fir_interpolator::t1 ()
43 {
44   static const unsigned N = 100;
45
46   float input_raw[N + 10 + 4*16/sizeof(float)];
47   memset(input_raw, 0, sizeof(input_raw));
48   float *input = &input_raw[2*16/sizeof(float)];
49
50   for (unsigned i = 0; i < NELEM(input); i++)
51     input[i] = test_fcn ((double) i);
52
53   gri_mmse_fir_interpolator     intr;
54   float inv_nsteps = 1.0 / intr.nsteps ();
55
56   for (unsigned i = 0; i < N; i++){
57     for (unsigned imu = 0; imu <= intr.nsteps (); imu += 1){
58       float expected = test_fcn ((i + 3) + imu * inv_nsteps);
59       float actual = intr.interpolate (&input[i], imu * inv_nsteps);
60
61       CPPUNIT_ASSERT_DOUBLES_EQUAL (expected, actual, 0.004);
62       // printf ("%9.6f  %9.6f  %9.6f\n", expected, actual, expected - actual);
63     }
64   }
65 }
66