3 * Copyright 2004,2007 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.
27 #include <gr_io_signature.h>
28 #include <gr_fractional_interpolator_cc.h>
29 #include <gri_mmse_fir_interpolator_cc.h>
33 gr_fractional_interpolator_cc_sptr gr_make_fractional_interpolator_cc(float phase_shift, float interp_ratio)
35 return gr_fractional_interpolator_cc_sptr(new gr_fractional_interpolator_cc(phase_shift, interp_ratio));
38 gr_fractional_interpolator_cc::gr_fractional_interpolator_cc(float phase_shift, float interp_ratio)
39 : gr_block ("fractional_interpolator_cc",
40 gr_make_io_signature (1, 1, sizeof (gr_complex)),
41 gr_make_io_signature (1, 1, sizeof (gr_complex))),
42 d_mu (phase_shift), d_mu_inc (interp_ratio), d_interp(new gri_mmse_fir_interpolator_cc())
44 if (interp_ratio <= 0)
45 throw std::out_of_range ("interpolation ratio must be > 0");
46 if (phase_shift < 0 || phase_shift > 1)
47 throw std::out_of_range ("phase shift ratio must be > 0 and < 1");
49 set_relative_rate (1.0 / interp_ratio);
52 gr_fractional_interpolator_cc::~gr_fractional_interpolator_cc()
58 gr_fractional_interpolator_cc::forecast(int noutput_items, gr_vector_int &ninput_items_required)
60 unsigned ninputs = ninput_items_required.size();
61 for (unsigned i=0; i < ninputs; i++)
63 ninput_items_required[i] =
64 (int) ceil((noutput_items * d_mu_inc) + d_interp->ntaps());
68 gr_fractional_interpolator_cc::general_work(int noutput_items,
69 gr_vector_int &ninput_items,
70 gr_vector_const_void_star &input_items,
71 gr_vector_void_star &output_items)
73 const gr_complex *in = (const gr_complex *) input_items[0];
74 gr_complex *out = (gr_complex *) output_items[0];
76 int ii = 0; // input index
77 int oo = 0; // output index
79 while (oo < noutput_items) {
81 out[oo++] = d_interp->interpolate(&in[ii], d_mu);
83 double s = d_mu + d_mu_inc;