Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / python / gnuradio / blks2impl / pfb_decimator.py @ 3d3d3c05

History | View | Annotate | Download (2.6 kB)

1
#!/usr/bin/env python
2
#
3
# Copyright 2009 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
from gnuradio import gr, optfir
24
25
class pfb_decimator_ccf(gr.hier_block2):
26
    '''
27
    Make a Polyphase Filter decimator (complex in, complex out, floating-point taps)
28
29
    This simplifies the interface by allowing a single input stream to connect to this block.
30
    It will then output a stream that is the decimated output stream.
31
    '''
32
    def __init__(self, decim, taps=None, channel=0, atten=100):
33
        gr.hier_block2.__init__(self, "pfb_decimator_ccf",
34
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
35
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
36
37
        self._decim = decim
38
        self._channel = channel
39
40
        if taps is not None:
41
            self._taps = taps
42
        else:
43
            # Create a filter that covers the full bandwidth of the input signal
44
            bw = 0.4
45
            tb = 0.2
46
            ripple = 0.1
47
            made = False
48
            while not made:
49
                try:
50
                    self._taps = optfir.low_pass(1, self._decim, bw, bw+tb, ripple, atten)
51
                    made = True
52
                except RuntimeError:
53
                    ripple += 0.01
54
                    made = False
55
                    print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple))
56
57
                    # Build in an exit strategy; if we've come this far, it ain't working.
58
                    if(ripple >= 1.0):
59
                        raise RuntimeError("optfir could not generate an appropriate filter.")
60
61
        self.s2ss = gr.stream_to_streams(gr.sizeof_gr_complex, self._decim)
62
        self.pfb = gr.pfb_decimator_ccf(self._decim, self._taps, self._channel)
63
64
        self.connect(self, self.s2ss)
65
66
        for i in xrange(self._decim):
67
            self.connect((self.s2ss,i), (self.pfb,i))
68
69
        self.connect(self.pfb, self)