1#!/usr/bin/env /usr/bin/python
2#
3# Copyright 2014 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 2, 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., 59 Temple Place - Suite 330,
20# Boston, MA 02111-1307, USA.
21
22from __future__ import division
23from __future__ import unicode_literals
24from gnuradio import gr, filter
25from . import dtv_swig as dtv
26
27# FIXME move these into separate constants module
28ATSC_CHANNEL_BW   = 6.0e6
29ATSC_SYMBOL_RATE  = 4.5e6/286*684 # ~10.76 Mbaud
30ATSC_RRC_SYMS     = 8             # filter kernel extends over 2N+1 symbols
31
32class atsc_rx_filter(gr.hier_block2):
33    def __init__(self, input_rate, sps):
34        gr.hier_block2.__init__(self, "atsc_rx_filter",
35                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
36                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
37
38        # Create matched RX filter with RRC response for fractional
39        # interpolator.
40        nfilts = 16
41        output_rate = ATSC_SYMBOL_RATE*sps # Desired oversampled sample rate
42        filter_rate = input_rate*nfilts
43        symbol_rate = ATSC_SYMBOL_RATE / 2.0 # One-sided bandwidth of sideband
44        excess_bw = 0.1152 #1.0-(0.5*ATSC_SYMBOL_RATE/ATSC_CHANNEL_BW) # ~10.3%
45        ntaps = int((2*ATSC_RRC_SYMS+1)*sps*nfilts)
46        interp = output_rate / input_rate
47        gain = nfilts*symbol_rate/filter_rate
48        rrc_taps = filter.firdes.root_raised_cosine(gain,             # Filter gain
49                                                    filter_rate,      # PFB filter prototype rate
50                                                    symbol_rate,      # ATSC symbol rate
51                                                    excess_bw,        # ATSC RRC excess bandwidth
52                                                    ntaps)            # Length of filter
53
54        pfb = filter.pfb_arb_resampler_ccf(interp, rrc_taps, nfilts)
55
56        # Connect pipeline
57        self.connect(self, pfb, self)
58