e2f5932836886bcd4f31adc8e682a0bcb426a43d
[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 import ofdm_sync
26
27 class ofdm_receiver(gr.hier_block):
28     def __init__(self, fg, fft_length, cp_length, occupied_tones, snr, ks1, ks2):
29         self.fg = fg
30
31         bw = (float(occupied_tones) / float(fft_length)) / 2.0
32         tb = bw*0.08
33         chan_coeffs = gr.firdes.low_pass (1.0,                     # gain
34                                           1.0,                     # sampling rate
35                                           bw+tb,                   # midpoint of trans. band
36                                           tb,                      # width of trans. band
37                                           gr.firdes.WIN_HAMMING)   # filter type
38         self.chan_filt = gr.fft_filter_ccc(1, chan_coeffs)
39         
40         win = [1 for i in range(fft_length)]
41
42         self.ofdm_sync = ofdm_sync(fg, fft_length, cp_length, snr)
43         self.fft_demod = gr.fft_vcc(fft_length, True, win, True)
44         self.ofdm_corr  = gr.ofdm_correlator(occupied_tones, fft_length,
45                                              cp_length, ks1, ks2)
46
47         self.fg.connect(self.chan_filt, self.ofdm_sync, self.fft_demod, self.ofdm_corr)
48         
49         if 1:
50             self.fg.connect(self.chan_filt, gr.file_sink(gr.sizeof_gr_complex, "chan_filt_c.dat"))
51             self.fg.connect(self.fft_demod, gr.file_sink(gr.sizeof_gr_complex*fft_length, "fft_out_c.dat"))
52             self.fg.connect(self.ofdm_corr, gr.file_sink(gr.sizeof_gr_complex*occupied_tones, "ofdm_corr_out_c.dat"))
53             self.fg.connect((self.ofdm_corr,1), gr.file_sink(1, "found_corr_b.dat"))
54
55         gr.hier_block.__init__(self, fg, self.chan_filt, self.ofdm_corr)