1 /* -*- c++ -*- */
2 /*
3 * Copyright 2002,2012,2018 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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <gnuradio/fft/fft.h>
28 #include <gnuradio/filter/mmse_fir_interpolator_ff.h>
29 #include <gnuradio/math.h>
30 #include <volk/volk.h>
31 #include <boost/test/unit_test.hpp>
32 #include <cmath>
33 #include <cstdio>
34
35 namespace gr {
36 namespace filter {
37
test_fcn(double index)38 static float test_fcn(double index)
39 {
40 return (2 * sin(index * 0.25 * 2 * GR_M_PI + 0.125 * GR_M_PI) +
41 3 * sin(index * 0.077 * 2 * GR_M_PI + 0.3 * GR_M_PI));
42 }
43
BOOST_AUTO_TEST_CASE(t1)44 BOOST_AUTO_TEST_CASE(t1)
45 {
46 // use aligned malloc and make sure that everything in this
47 // buffer is properly initialized.
48 static const unsigned N = 100;
49 float* input = (float*)volk_malloc((N + 10) * sizeof(float), volk_get_alignment());
50
51 for (unsigned i = 0; i < N + 10; i++)
52 input[i] = test_fcn((double)i);
53
54 mmse_fir_interpolator_ff intr;
55 float inv_nsteps = 1.0 / intr.nsteps();
56
57 for (unsigned i = 0; i < N; i++) {
58 for (unsigned imu = 0; imu <= intr.nsteps(); imu += 1) {
59 float expected = test_fcn((i + 3) + imu * inv_nsteps);
60 float actual = intr.interpolate(&input[i], imu * inv_nsteps);
61
62 BOOST_CHECK(std::abs(expected - actual) <= 0.004);
63 // printf ("%9.6f %9.6f %9.6f\n", expected, actual, expected - actual);
64 }
65 }
66 volk_free(input);
67 }
68
69 } /* namespace filter */
70 } /* namespace gr */
71