summaryrefslogtreecommitdiff
path: root/gr-channels/lib/channel_model_impl.cc
blob: a9ed06eb5330e428a90897e91430c5bd1e5510dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* -*- c++ -*- */
/*
 * Copyright 2009,2012 Free Software Foundation, Inc.
 *
 * This file is part of GNU Radio
 *
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#include "channel_model_impl.h"
#include <gr_io_signature.h>
#include <iostream>

namespace gr {
  namespace channels {
    
    channel_model::sptr
    channel_model::make(double noise_voltage,
			double frequency_offset,
			double epsilon,
			const std::vector<gr_complex> &taps,
			double noise_seed)
    {
      return gnuradio::get_initial_sptr
	(new channel_model_impl(noise_voltage,
				frequency_offset,
				epsilon,
				taps,
				noise_seed));
    }

    // Hierarchical block constructor
    channel_model_impl::channel_model_impl(double noise_voltage,
					   double frequency_offset,
					   double epsilon,
					   const std::vector<gr_complex> &taps,
					   double noise_seed)
      : gr_hier_block2("channel_model",
		       gr_make_io_signature(1, 1, sizeof(gr_complex)),
		       gr_make_io_signature(1, 1, sizeof(gr_complex)))
    {
      d_taps = taps;
      while(d_taps.size() < 2) {
	d_taps.push_back(0);
      }

      d_timing_offset = filter::fractional_interpolator_cc::make(0, epsilon);

      d_multipath = filter::fir_filter_ccc::make(1, d_taps);

      d_noise_adder = blocks::add_cc::make();
      d_noise = analog::noise_source_c::make(analog::GR_GAUSSIAN,
					     noise_voltage, noise_seed);
      d_freq_offset = analog::sig_source_c::make(1, analog::GR_SIN_WAVE,
						 frequency_offset, 1.0, 0.0);
      d_mixer_offset = blocks::multiply_cc::make();

      connect(self(), 0, d_timing_offset, 0);
      connect(d_timing_offset, 0, d_multipath, 0);
      connect(d_multipath, 0, d_mixer_offset, 0);
      connect(d_freq_offset, 0, d_mixer_offset, 1);
      connect(d_mixer_offset, 0, d_noise_adder, 1);
      connect(d_noise, 0, d_noise_adder, 0);
      connect(d_noise_adder, 0, self(), 0);
    }

    channel_model_impl::~channel_model_impl()
    {
    }

    void
    channel_model_impl::set_noise_voltage(double noise_voltage)
    {
      d_noise->set_amplitude(noise_voltage);
    }

    void
    channel_model_impl::set_frequency_offset(double frequency_offset)
    {
      d_freq_offset->set_frequency(frequency_offset);
    }

    void
    channel_model_impl::set_taps(const std::vector<gr_complex> &taps)
    {
      d_taps = taps;
      while(d_taps.size() < 2) {
	d_taps.push_back(0);
      }
      d_multipath->set_taps(d_taps);
    }

    void
    channel_model_impl::set_timing_offset(double epsilon)
    {
      d_timing_offset->set_interp_ratio(epsilon);
    }

    double
    channel_model_impl::noise_voltage() const
    {
      return d_noise->amplitude();
    }

    double
    channel_model_impl::frequency_offset() const
    {
      return d_freq_offset->frequency();
    }

    std::vector<gr_complex>
    channel_model_impl::taps() const
    {
      return d_multipath->taps();
    }

    double
    channel_model_impl::timing_offset() const
    {
      return d_timing_offset->interp_ratio();
    }

  } /* namespace channels */
} /* namespace gr */