Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / lib / filter / gr_fractional_interpolator_ff.cc @ 100e6105

History | View | Annotate | Download (2.8 kB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2004,2007 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 <gr_io_signature.h>
28
#include <gr_fractional_interpolator_ff.h>
29
#include <gri_mmse_fir_interpolator.h>
30
#include <stdexcept>
31
32
// Public constructor
33
gr_fractional_interpolator_ff_sptr gr_make_fractional_interpolator_ff(float phase_shift, float interp_ratio)
34
{
35
  return gr_fractional_interpolator_ff_sptr(new gr_fractional_interpolator_ff(phase_shift, interp_ratio));
36
}
37
38
gr_fractional_interpolator_ff::gr_fractional_interpolator_ff(float phase_shift, float interp_ratio)
39
  : gr_block ("fractional_interpolator_ff",
40
              gr_make_io_signature (1, 1, sizeof (float)),
41
              gr_make_io_signature (1, 1, sizeof (float))),
42
    d_mu (phase_shift), d_mu_inc (interp_ratio), d_interp(new gri_mmse_fir_interpolator())
43
{
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");
48
49
  set_relative_rate (1.0 / interp_ratio);
50
}
51
52
gr_fractional_interpolator_ff::~gr_fractional_interpolator_ff()
53
{
54
  delete d_interp;
55
}
56
57
void
58
gr_fractional_interpolator_ff::forecast(int noutput_items, gr_vector_int &ninput_items_required)
59
{
60
  unsigned ninputs = ninput_items_required.size();
61
  for (unsigned i=0; i < ninputs; i++)
62
63
    ninput_items_required[i] =
64
      (int) ceil((noutput_items * d_mu_inc) + d_interp->ntaps());
65
}
66
67
int
68
gr_fractional_interpolator_ff::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)
72
{
73
  const float *in = (const float *) input_items[0];
74
  float *out = (float *) output_items[0];
75
76
  int         ii = 0;                                // input index
77
  int          oo = 0;                                // output index
78
79
  while (oo < noutput_items) {
80
81
    out[oo++] = d_interp->interpolate(&in[ii], d_mu);
82
83
    double s = d_mu + d_mu_inc;
84
    double f = floor (s);
85
    int incr = (int) f;
86
    d_mu = s - f;
87
    ii += incr;
88
  }
89
90
  consume_each (ii);
91
92
  return noutput_items;
93
}