3 * Copyright 2002 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.
23 #include <qa_gr_firdes.h>
24 #include <gr_firdes.h>
25 #include <cppunit/TestAssert.h>
26 #include <gr_complex.h>
32 #define NELEM(x) (sizeof (x) / sizeof (x[0]))
38 print_taps (std::ostream &s, vector<float> &v)
41 for (unsigned int i = 0; i < v.size (); i++){
42 printf ("tap[%2d] = %16.7e\n", i, v[i]);
48 check_symmetry (vector<float> &v)
53 for (int i = 0; i < m; i++)
54 CPPUNIT_ASSERT_DOUBLES_EQUAL (v[i], v[n - i - 1], 1e-9);
57 const static float t1_exp[53] = {
113 const static float t2_exp[53] = {
169 const static float t3_exp[107] = {
280 const static float t4_exp[] = { // low pass
333 const static float t5_exp[] = { //high pass
385 const static float t6_exp[] = { // bandpass
489 gr_firdes::low_pass ( 1.0,
493 gr_firdes::WIN_HAMMING);
495 // cout << "ntaps: " << taps.size () << endl;
496 // print_taps (cout, taps);
498 CPPUNIT_ASSERT_EQUAL (NELEM (t1_exp), taps.size ());
499 for (unsigned int i = 0; i < taps.size (); i++)
500 CPPUNIT_ASSERT_DOUBLES_EQUAL (t1_exp[i], taps[i], 1e-9);
502 check_symmetry (taps);
509 gr_firdes::high_pass ( 1.0,
513 gr_firdes::WIN_HAMMING);
515 // cout << "ntaps: " << taps.size () << endl;
516 // print_taps (cout, taps);
518 CPPUNIT_ASSERT_EQUAL (NELEM (t2_exp), taps.size ());
520 for (unsigned int i = 0; i < taps.size (); i++)
521 CPPUNIT_ASSERT_DOUBLES_EQUAL (t2_exp[i], taps[i], 1e-9);
523 check_symmetry (taps);
530 gr_firdes::band_pass ( 1.0,
535 gr_firdes::WIN_HAMMING);
537 // cout << "ntaps: " << taps.size () << endl;
538 // print_taps (cout, taps);
540 CPPUNIT_ASSERT_EQUAL (NELEM (t3_exp), taps.size ());
542 for (unsigned int i = 0; i < taps.size (); i++)
543 CPPUNIT_ASSERT_DOUBLES_EQUAL (t3_exp[i], taps[i], 1e-7);
545 check_symmetry (taps);
552 gr_firdes::low_pass_2 ( 1.0,
557 gr_firdes::WIN_HAMMING);
559 // std::cout << "ntaps: " << taps.size () << std::endl;
560 // print_taps (std::cout, taps);
562 CPPUNIT_ASSERT_EQUAL (NELEM (t4_exp), taps.size ());
563 for (unsigned int i = 0; i < taps.size (); i++)
564 CPPUNIT_ASSERT_DOUBLES_EQUAL (t4_exp[i], taps[i], 1e-9);
567 check_symmetry (taps);
574 gr_firdes::high_pass_2 ( 1.0,
579 gr_firdes::WIN_HAMMING);
581 // std::cout << "ntaps: " << taps.size () << std::endl;
582 // print_taps (std::cout, taps);
584 CPPUNIT_ASSERT_EQUAL (NELEM (t5_exp), taps.size ());
586 for (unsigned int i = 0; i < taps.size (); i++)
587 CPPUNIT_ASSERT_DOUBLES_EQUAL (t5_exp[i], taps[i], 1e-9);
589 check_symmetry (taps);
596 gr_firdes::band_pass_2 ( 1.0,
602 gr_firdes::WIN_HAMMING);
604 // std::cout << "ntaps: " << taps.size () << std::endl;
605 // print_taps (std::cout, taps);
607 CPPUNIT_ASSERT_EQUAL (NELEM (t6_exp), taps.size ());
609 for (unsigned int i = 0; i < taps.size (); i++)
610 CPPUNIT_ASSERT_DOUBLES_EQUAL (t6_exp[i], taps[i], 1e-7);
612 check_symmetry (taps);