Imported Upstream version 3.2.2
[debian/gnuradio] / gr-pager / src / flex_demod.py
1 #
2 # Copyright 2006,2007 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
20
21
22 from gnuradio import gr, gru, optfir, blks2
23 from math import pi
24 import pager_swig
25
26 class flex_demod(gr.hier_block2):
27     """
28     FLEX pager protocol demodulation block.
29
30     This block demodulates a band-limited, complex down-converted baseband 
31     channel into FLEX protocol frames.
32
33     """
34
35     def __init__(self, queue, freq=0.0, verbose=False, log=False):
36         gr.hier_block2.__init__(self, "flex_demod",
37                                 gr.io_signature(1, 1, gr.sizeof_gr_complex),
38                                 gr.io_signature(0,0,0))
39
40         k = 25000/(2*pi*1600)        # 4800 Hz max deviation
41         quad = gr.quadrature_demod_cf(k)
42         self.connect(self, quad)
43         
44         rsamp = blks2.rational_resampler_fff(16, 25)
45         self.slicer = pager_swig.slicer_fb(5e-6) # DC removal averaging filter constant
46         self.sync = pager_swig.flex_sync()
47
48         self.connect(quad, rsamp, self.slicer, self.sync)
49
50         for i in range(4):
51             self.connect((self.sync, i), pager_swig.flex_deinterleave(), pager_swig.flex_parse(queue, freq))
52
53         if log:
54             suffix = '_'+ "%3.3f" % (freq/1e6,) + '.dat'
55             quad_sink = gr.file_sink(gr.sizeof_float, 'quad'+suffix)
56             rsamp_sink = gr.file_sink(gr.sizeof_float, 'rsamp'+suffix)
57             slicer_sink = gr.file_sink(gr.sizeof_char, 'slicer'+suffix)
58             self.connect(rsamp, rsamp_sink)
59             self.connect(quad, quad_sink)
60             self.connect(self.slicer, slicer_sink)
61
62     def dc_offset(self):
63         return self.slicer.dc_offset()
64