File: lpf.cpp

package info (click to toggle)
gqrx-sdr 2.3.1-2~bpo70%2B1
  • links: PTS
  • area: main
  • in suites: wheezy-backports
  • size: 2,628 kB
  • sloc: cpp: 12,005; ansic: 558; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 2,751 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* -*- c++ -*- */
/*
 * Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
 *           http://gqrx.dk/
 *
 * Copyright 2012 Alexandru Csete OZ9AEC.
 *
 * Gqrx is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * Gqrx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gqrx; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */
#include <cmath>
#include <gnuradio/io_signature.h>
#include <gnuradio/filter/firdes.h>
#include "dsp/lpf.h"

static const int MIN_IN  = 1; /* Mininum number of input streams. */
static const int MAX_IN  = 1; /* Maximum number of input streams. */
static const int MIN_OUT = 1; /* Minimum number of output streams. */
static const int MAX_OUT = 1; /* Maximum number of output streams. */


/*
 * Create a new instance of lpf and return
 * a boost shared_ptr. This is effectively the public constructor.
 */
lpf_ff_sptr make_lpf_ff(double sample_rate, double cutoff_freq,
                        double trans_width, double gain)
{
    return gnuradio::get_initial_sptr(new lpf_ff(sample_rate, cutoff_freq,
                                                 trans_width, gain));
}


lpf_ff::lpf_ff(double sample_rate, double cutoff_freq,
               double trans_width, double gain)
    : gr::hier_block2("lpf_ff",
                     gr::io_signature::make(MIN_IN,  MAX_IN,  sizeof (float)),
                     gr::io_signature::make(MIN_OUT, MAX_OUT, sizeof (float))),
    d_sample_rate(sample_rate),
    d_cutoff_freq(cutoff_freq),
    d_trans_width(trans_width),
    d_gain(gain)
{
    /* generate taps */
    d_taps = gr::filter::firdes::low_pass(d_gain, d_sample_rate,
                                 d_cutoff_freq, d_trans_width);

    /* create low-pass filter (decimation=1) */
    lpf = gr::filter::fir_filter_fff::make(1, d_taps);

    /* connect filter */
    connect(self(), 0, lpf, 0);
    connect(lpf, 0, self(), 0);
}


lpf_ff::~lpf_ff()
{

}


void lpf_ff::set_param(double cutoff_freq, double trans_width)
{
    d_cutoff_freq = cutoff_freq;
    d_trans_width = trans_width;

    /* generate new taps */
    d_taps = gr::filter::firdes::low_pass(d_gain, d_sample_rate,
                                 d_cutoff_freq, d_trans_width);

    lpf->set_taps(d_taps);
}