Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / hier / gr_channel_model.cc
1 /*
2  * Copyright 2009 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 #include <gr_channel_model.h>
23 #include <gr_io_signature.h>
24 #include <gr_sig_source_f.h>
25 #include <iostream>
26
27 // Shared pointer constructor
28 gr_channel_model_sptr
29 gr_make_channel_model(double noise_voltage,
30                       double frequency_offset,
31                       double epsilon,
32                       const std::vector<gr_complex> &taps,
33                       double noise_seed)
34 {
35   return gnuradio::get_initial_sptr(new gr_channel_model(noise_voltage,
36                                                          frequency_offset,
37                                                          epsilon,
38                                                          taps,
39                                                          noise_seed));
40 }
41
42 // Hierarchical block constructor
43 gr_channel_model::gr_channel_model(double noise_voltage,
44                                    double frequency_offset,
45                                    double epsilon,
46                                    const std::vector<gr_complex> &taps,
47                                    double noise_seed)
48   : gr_hier_block2("gr_channel_model",
49                    gr_make_io_signature(1, 1, sizeof(gr_complex)), 
50                    gr_make_io_signature(1, 1, sizeof(gr_complex)))
51 {
52   d_taps = taps;
53   while(d_taps.size() < 2) {
54     d_taps.push_back(0);
55   }
56   
57   d_timing_offset = gr_make_fractional_interpolator_cc(0, epsilon);
58   
59   d_multipath = gr_make_fir_filter_ccc(1, d_taps);
60   
61   d_noise_adder = gr_make_add_cc();
62   d_noise = gr_make_noise_source_c(GR_GAUSSIAN, noise_voltage, noise_seed);
63   d_freq_offset = gr_make_sig_source_c(1, GR_SIN_WAVE, frequency_offset, 1.0, 0.0);
64   d_mixer_offset = gr_make_multiply_cc();
65   
66   connect(self(), 0, d_timing_offset, 0);
67   connect(d_timing_offset, 0, d_multipath, 0);
68   connect(d_multipath, 0, d_mixer_offset, 0);
69   connect(d_freq_offset, 0, d_mixer_offset, 1);
70   connect(d_mixer_offset, 0, d_noise_adder, 1);
71   connect(d_noise, 0, d_noise_adder, 0);
72   connect(d_noise_adder, 0, self(), 0);
73 }
74
75 void
76 gr_channel_model::set_noise_voltage(double noise_voltage)
77 {
78   d_noise->set_amplitude(noise_voltage);
79 }
80    
81 void
82 gr_channel_model::set_frequency_offset(double frequency_offset)
83 {
84   d_freq_offset->set_frequency(frequency_offset);
85 }
86      
87 void
88 gr_channel_model::set_taps(const std::vector<gr_complex> &taps)
89 {
90   d_taps = taps;
91   while(d_taps.size() < 2) {
92     d_taps.push_back(0);
93   }
94   d_multipath->set_taps(d_taps);
95 }
96
97 void
98 gr_channel_model::set_timing_offset(double epsilon)
99 {
100   d_timing_offset->set_interp_ratio(epsilon);
101 }