Merge commit 'v3.3.0' into upstream
[debian/gnuradio] / gr-atsc / src / python / fpll.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2004,2005 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., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
21
22
23 from gnuradio import gr, atsc
24 import math, os
25
26 def main():
27
28         print os.getpid()
29
30         tb = gr.top_block()
31
32         u = gr.file_source(gr.sizeof_float,"/tmp/atsc_pipe_2")
33
34         input_rate = 19.2e6
35         IF_freq = 5.75e6
36
37
38         # 1/2 as wide because we're designing lp filter
39         symbol_rate = atsc.ATSC_SYMBOL_RATE/2. 
40         NTAPS = 279
41         tt = gr.firdes.root_raised_cosine (1.0, input_rate, symbol_rate, .115, NTAPS)
42   # heterodyne the low pass coefficients up to the specified bandpass
43   # center frequency.  Note that when we do this, the filter bandwidth
44   # is effectively twice the low pass (2.69 * 2 = 5.38) and hence
45   # matches the diagram in the ATSC spec.
46         arg = 2. * math.pi * IF_freq / input_rate
47         t=[]
48         for i in range(len(tt)):
49           t += [tt[i] * 2. * math.cos(arg * i)]
50         rrc = gr.fir_filter_fff(1, t)
51
52         fpll = atsc.fpll()
53
54         pilot_freq = IF_freq - 3e6 + 0.31e6
55         lower_edge = 6e6 - 0.31e6
56         upper_edge = IF_freq - 3e6 + pilot_freq
57         transition_width = upper_edge - lower_edge
58         lp_coeffs = gr.firdes.low_pass (1.0,
59                            input_rate,
60                            (lower_edge + upper_edge) * 0.5,
61                            transition_width,
62                            gr.firdes.WIN_HAMMING);
63
64         lp_filter = gr.fir_filter_fff (1,lp_coeffs)
65
66         alpha = 1e-5
67         iir = gr.single_pole_iir_filter_ff(alpha)
68         remove_dc = gr.sub_ff()
69
70         out = gr.file_sink(gr.sizeof_float,"/tmp/atsc_pipe_3")
71         # out = gr.file_sink(gr.sizeof_float,"/mnt/sata/atsc_data_float")
72
73         tb.connect(u, fpll, lp_filter)
74         tb.connect(lp_filter, iir)
75         tb.connect(lp_filter, (remove_dc,0))
76         tb.connect(iir, (remove_dc,1))
77         tb.connect(remove_dc, out)
78
79         tb.run()
80
81
82 if __name__ == '__main__':
83     main ()
84
85
86