Updated license from GPL version 2 or later to GPL version 3 or later.
[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
25
26 def main():
27
28         fg = gr.flow_graph()
29
30         u = gr.file_source(gr.sizeof_float,"/tmp/atsc_pipe_2")
31
32         input_rate = 19.2e6
33         IF_freq = 5.75e6
34
35
36         # 1/2 as wide because we're designing lp filter
37         symbol_rate = atsc.ATSC_SYMBOL_RATE/2. 
38         NTAPS = 279
39         tt = gr.firdes.root_raised_cosine (1.0, input_rate, symbol_rate, .115, NTAPS)
40   # heterodyne the low pass coefficients up to the specified bandpass
41   # center frequency.  Note that when we do this, the filter bandwidth
42   # is effectively twice the low pass (2.69 * 2 = 5.38) and hence
43   # matches the diagram in the ATSC spec.
44         arg = 2. * math.pi * IF_freq / input_rate
45         t=[]
46         for i in range(len(tt)):
47           t += [tt[i] * 2. * math.cos(arg * i)]
48         rrc = gr.fir_filter_fff(1, t)
49
50         fpll = atsc.fpll()
51
52         pilot_freq = IF_freq - 3e6 + 0.31e6
53         lower_edge = 6e6 - 0.31e6
54         upper_edge = IF_freq - 3e6 + pilot_freq
55         transition_width = upper_edge - lower_edge
56         lp_coeffs = gr.firdes.low_pass (1.0,
57                            input_rate,
58                            (lower_edge + upper_edge) * 0.5,
59                            transition_width,
60                            gr.firdes.WIN_HAMMING);
61
62         lp_filter = gr.fir_filter_fff (1,lp_coeffs)
63
64         alpha = 1e-5
65         iir = gr.single_pole_iir_filter_ff(alpha)
66         remove_dc = gr.sub_ff()
67
68         out = gr.file_sink(gr.sizeof_float,"/tmp/atsc_pipe_3")
69         # out = gr.file_sink(gr.sizeof_float,"/mnt/sata/atsc_data_float")
70
71         fg.connect(u, fpll, lp_filter)
72         fg.connect(lp_filter, iir)
73         fg.connect(lp_filter, (remove_dc,0))
74         fg.connect(iir, (remove_dc,1))
75         fg.connect(remove_dc, out)
76
77         fg.run()
78
79
80 if __name__ == '__main__':
81     main ()
82
83
84