Merging OFDM features branch r5661:5759 into trunk. OFDM works over the air with...
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blksimpl / ofdm_receiver.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006, 2007 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., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 import math
24 from gnuradio import gr
25 from gnuradio.blksimpl.ofdm_sync_ml import ofdm_sync_ml
26 from gnuradio.blksimpl.ofdm_sync_pn import ofdm_sync_pn
27 from gnuradio.blksimpl.ofdm_sync_pnac import ofdm_sync_pnac
28
29 class ofdm_receiver(gr.hier_block):
30     def __init__(self, fg, fft_length, cp_length, occupied_tones, snr, ks, logging=False):
31         self.fg = fg
32
33         bw = (float(occupied_tones) / float(fft_length)) / 2.0
34         tb = bw*0.08
35         chan_coeffs = gr.firdes.low_pass (1.0,                     # gain
36                                           1.0,                     # sampling rate
37                                           bw+tb,                   # midpoint of trans. band
38                                           tb,                      # width of trans. band
39                                           gr.firdes.WIN_HAMMING)   # filter type
40         self.chan_filt = gr.fft_filter_ccc(1, chan_coeffs)
41         
42         win = [1 for i in range(fft_length)]
43
44         SYNC = "pn"
45         if SYNC == "ml":
46             self.ofdm_sync = ofdm_sync_ml(fg, fft_length, cp_length, snr, logging)
47         elif SYNC == "pn":
48             self.ofdm_sync = ofdm_sync_pn(fg, fft_length, cp_length, logging)
49         elif SYNC == "pnac":
50             self.ofdm_sync = ofdm_sync_pnac(fg, fft_length, cp_length, ks[0])
51
52         self.fft_demod = gr.fft_vcc(fft_length, True, win, True)
53         self.ofdm_corr  = gr.ofdm_correlator(occupied_tones, fft_length,
54                                              cp_length, ks[1], ks[2])
55
56         self.fg.connect(self.chan_filt, self.ofdm_sync, self.fft_demod, self.ofdm_corr)
57         
58         if logging:
59             self.fg.connect(self.chan_filt, gr.file_sink(gr.sizeof_gr_complex, "chan_filt_c.dat"))
60             self.fg.connect(self.fft_demod, gr.file_sink(gr.sizeof_gr_complex*fft_length, "fft_out_c.dat"))
61             self.fg.connect(self.ofdm_corr, gr.file_sink(gr.sizeof_gr_complex*occupied_tones, "ofdm_corr_out_c.dat"))
62             self.fg.connect((self.ofdm_corr,1), gr.file_sink(1, "found_corr_b.dat"))
63
64         gr.hier_block.__init__(self, fg, self.chan_filt, self.ofdm_corr)