3 * Copyright 2004 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.
24 * WARNING: This file is automatically generated by generate_gr_fir_filter_XXX.py
25 * Any changes made to this file will be overwritten.
32 #include <gr_interp_fir_filter_ccc.h>
33 #include <gr_fir_ccc.h>
34 #include <gr_fir_util.h>
35 #include <gr_io_signature.h>
39 gr_interp_fir_filter_ccc_sptr gr_make_interp_fir_filter_ccc (unsigned interpolation, const std::vector<gr_complex> &taps)
41 return gr_interp_fir_filter_ccc_sptr (new gr_interp_fir_filter_ccc (interpolation, taps));
45 gr_interp_fir_filter_ccc::gr_interp_fir_filter_ccc (unsigned interpolation, const std::vector<gr_complex> &taps)
46 : gr_sync_interpolator ("interp_fir_filter_ccc",
47 gr_make_io_signature (1, 1, sizeof (gr_complex)),
48 gr_make_io_signature (1, 1, sizeof (gr_complex)),
50 d_updated (false), d_firs (interpolation)
52 if (interpolation == 0)
53 throw std::out_of_range ("interpolation must be > 0");
55 std::vector<gr_complex> dummy_taps;
57 for (unsigned i = 0; i < interpolation; i++)
58 d_firs[i] = gr_fir_util::create_gr_fir_ccc (dummy_taps);
61 install_taps(d_new_taps);
64 gr_interp_fir_filter_ccc::~gr_interp_fir_filter_ccc ()
66 int interp = interpolation ();
67 for (int i = 0; i < interp; i++)
72 gr_interp_fir_filter_ccc::set_taps (const std::vector<gr_complex> &taps)
77 // round up length to a multiple of the interpolation factor
78 int n = taps.size () % interpolation ();
80 n = interpolation () - n;
82 d_new_taps.insert(d_new_taps.begin(), 0);
85 assert (d_new_taps.size () % interpolation () == 0);
90 gr_interp_fir_filter_ccc::install_taps (const std::vector<gr_complex> &taps)
92 int nfilters = interpolation ();
93 int nt = taps.size () / nfilters;
95 assert (nt * nfilters == (int) taps.size ());
97 std::vector< std::vector <gr_complex> > xtaps (nfilters);
99 for (int n = 0; n < nfilters; n++)
100 xtaps[n].resize (nt);
102 for (int i = 0; i < (int) taps.size(); i++)
103 xtaps[i % nfilters][i / nfilters] = taps[i];
105 for (int n = 0; n < nfilters; n++)
106 d_firs[n]->set_taps (xtaps[n]);
112 for (int i = 0; i < nfilters; i++){
113 std::cout << "filter[" << i << "] = ";
114 for (int j = 0; j < nt; j++)
115 std::cout << xtaps[i][j] << " ";
124 gr_interp_fir_filter_ccc::work (int noutput_items,
125 gr_vector_const_void_star &input_items,
126 gr_vector_void_star &output_items)
128 const gr_complex *in = (const gr_complex *) input_items[0];
129 gr_complex *out = (gr_complex *) output_items[0];
132 install_taps (d_new_taps);
133 return 0; // history requirements may have changed.
136 int nfilters = interpolation ();
137 int ni = noutput_items / interpolation ();
139 for (int i = 0; i < ni; i++){
140 for (int nf = 0; nf < nfilters; nf++)
141 out[nf] = d_firs[nf]->filter (&in[i]);
145 return noutput_items;