Merge r6461:6464 from jcorgan/t162-staging into trunk.
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blks2impl / channel_model.py
1 #!/usr/bin/env python
2 #
3 # Copyright 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 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., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 from gnuradio import gr
24
25 class channel_model(gr.hier_block):
26     def __init__(self, fg, noise_voltage=0.0, frequency_offset=0.0, epsilon=1.0, taps=[1.0,0.0]):
27         ''' Creates a channel model that includes:
28           - AWGN noise power in terms of noise voltage
29           - A frequency offest in the channel in ratio
30           - A timing offset ratio to model clock difference (epsilon)
31           - Multipath taps
32           '''
33
34         print epsilon
35         self.timing_offset = gr.fractional_interpolator_cc(0, epsilon)
36         
37         self.multipath = gr.fir_filter_ccc(1, taps)
38         
39         self.noise_adder = gr.add_cc()
40         self.noise = gr.noise_source_c(gr.GR_GAUSSIAN,noise_voltage)
41         self.freq_offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, frequency_offset, 1.0, 0.0)
42         self.mixer_offset = gr.multiply_cc()
43
44         fg.connect(self.timing_offset, self.multipath)
45         fg.connect(self.multipath, (self.mixer_offset,0))
46         fg.connect(self.freq_offset,(self.mixer_offset,1))
47         fg.connect(self.mixer_offset, (self.noise_adder,1))
48         fg.connect(self.noise, (self.noise_adder,0))
49         
50         gr.hier_block.__init__(self, fg, self.timing_offset, self.noise_adder)
51         
52     def set_noise_voltage(noise_voltage):
53         self.noise.set_amplitude(noise_voltage)
54         
55     def set_frequency_offset(frequency_offset):
56         self.freq_offset.set_frequency(frequency_offset)
57      
58     def set_taps(taps):
59         self.multipath.set_taps(taps)