USRP Hardware Driver and USRP Manual  Version: 004.000.000.HEAD-0-g8773fb2c
UHD and USRP Manual
filters.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2015 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_TYPES_FILTERS_HPP
19 #define INCLUDED_UHD_TYPES_FILTERS_HPP
20 
21 #include <uhd/config.hpp>
22 #include <uhd/utils/log.hpp>
23 #include <uhd/utils/msg.hpp>
24 #include <boost/cstdint.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/scoped_array.hpp>
27 #include <string>
28 #include <vector>
29 #include <iostream>
30 #include <ostream>
31 #include <sstream>
32 
33 namespace uhd{
34 
36  {
37  public:
38  typedef boost::shared_ptr<filter_info_base> sptr;
40  {
44  DIGITAL_FIR_I16
45  };
46 
48  filter_type type,
49  bool bypass,
50  size_t position_index
51  ):
52  _type(type), _bypass(bypass),
53  _position_index(position_index)
54  {
55  //NOP
56  }
57 
58  UHD_INLINE virtual bool is_bypassed()
59  {
60  return _bypass;
61  }
62 
64  {
65  return _type;
66  }
67 
69  {
70  //NOP
71  }
72 
73  virtual std::string to_pp_string();
74 
75  protected:
77  bool _bypass;
79 
80  };
81 
82  UHD_API std::ostream& operator<<(std::ostream& os, filter_info_base& f);
83 
85  {
86  std::string _analog_type;
87  public:
88  typedef boost::shared_ptr<analog_filter_base> sptr;
90  filter_type type,
91  bool bypass,
92  size_t position_index,
93  const std::string& analog_type
94  ):
95  filter_info_base(type, bypass, position_index),
96  _analog_type(analog_type)
97  {
98  //NOP
99  }
100 
101  UHD_INLINE const std::string& get_analog_type()
102  {
103  return _analog_type;
104  }
105 
106  virtual std::string to_pp_string();
107  };
108 
110  {
111  double _cutoff;
112  double _rolloff;
113 
114  public:
115  typedef boost::shared_ptr<analog_filter_lp> sptr;
117  filter_type type,
118  bool bypass,
119  size_t position_index,
120  const std::string& analog_type,
121  double cutoff,
122  double rolloff
123  ):
124  analog_filter_base(type, bypass, position_index, analog_type),
125  _cutoff(cutoff),
126  _rolloff(rolloff)
127  {
128  //NOP
129  }
130 
132  {
133  return _cutoff;
134  }
135 
137  {
138  return _cutoff;
139  }
140 
141  UHD_INLINE void set_cutoff(const double cutoff)
142  {
143  _cutoff = cutoff;
144  }
145 
146  virtual std::string to_pp_string();
147  };
148 
149  template<typename tap_t>
151  {
152  protected:
153  double _rate;
154  boost::uint32_t _interpolation;
155  boost::uint32_t _decimation;
157  boost::uint32_t _max_num_taps;
158  std::vector<tap_t> _taps;
159 
160  public:
161  typedef boost::shared_ptr<digital_filter_base> sptr;
163  filter_type type,
164  bool bypass,
165  size_t position_index,
166  double rate,
167  size_t interpolation,
168  size_t decimation,
169  double tap_full_scale,
170  size_t max_num_taps,
171  const std::vector<tap_t>& taps
172  ):
173  filter_info_base(type, bypass, position_index),
174  _rate(rate),
175  _interpolation(interpolation),
176  _decimation(decimation),
177  _tap_full_scale(tap_full_scale),
178  _max_num_taps(max_num_taps),
179  _taps(taps)
180  {
181  //NOP
182  }
183 
185  {
186  return (_bypass ? _rate : (_rate / _decimation * _interpolation));
187  }
188 
190  {
191  return _rate;
192  }
193 
195  {
196  return _interpolation;
197  }
198 
200  {
201  return _decimation;
202  }
203 
205  {
206  return _tap_full_scale;
207  }
208 
209  UHD_INLINE std::vector<tap_t>& get_taps()
210  {
211  return _taps;
212  }
213 
214  virtual std::string to_pp_string()
215  {
216  std::ostringstream os;
218  "\t[digital_filter_base]"<<std::endl<<
219  "\tinput rate: "<<_rate<<std::endl<<
220  "\tinterpolation: "<<_interpolation<<std::endl<<
221  "\tdecimation: "<<_decimation<<std::endl<<
222  "\tfull-scale: "<<_tap_full_scale<<std::endl<<
223  "\tmax num taps: "<<_max_num_taps<<std::endl<<
224  "\ttaps: "<<std::endl;
225 
226  os<<"\t\t";
227  for(size_t i = 0; i < _taps.size(); i++)
228  {
229  os<<"(tap "<<i<<": "<<_taps[i]<<")";
230  if( ((i%10) == 0) && (i != 0))
231  {
232  os<<std::endl<<"\t\t";
233  }
234  }
235  os<<std::endl;
236  return std::string(os.str());
237  }
238 
239  };
240 
241  template<typename tap_t>
243  {
244  public:
245  typedef boost::shared_ptr<digital_filter_fir<tap_t> > sptr;
246 
249  bool bypass, size_t position_index,
250  double rate,
251  size_t interpolation,
252  size_t decimation,
253  size_t tap_bit_width,
254  size_t max_num_taps,
255  const std::vector<tap_t>& taps
256  ):
257  digital_filter_base<tap_t>(type, bypass, position_index, rate, interpolation, decimation, tap_bit_width, max_num_taps, taps)
258  {
259  //NOP
260  }
261 
262  void set_taps(const std::vector<tap_t>& taps)
263  {
264  std::size_t num_taps = taps.size();
265  if(num_taps < this->_max_num_taps){
266  UHD_MSG(warning) << "digital_filter_fir::set_taps not enough coefficients. Appending zeros";
267  std::vector<tap_t> coeffs;
268  for (size_t i = 0; i < this->_max_num_taps; i++)
269  {
270  if(i < num_taps)
271  {
272  coeffs.push_back(taps[i]);
273  } else {
274  coeffs.push_back(0);
275  }
276  }
277  this->_taps = coeffs;
278  } else {
279  this->_taps = taps;
280  }
281  }
282  };
283 
284 } //namespace uhd
285 
286 #endif /* INCLUDED_UHD_TYPES_FILTERS_HPP */
virtual std::string to_pp_string()
boost::shared_ptr< digital_filter_fir< tap_t > > sptr
Definition: filters.hpp:245
filter_type _type
Definition: filters.hpp:76
Definition: filters.hpp:242
Definition: msg.hpp:51
UHD_INLINE std::vector< tap_t > & get_taps()
Definition: filters.hpp:209
std::vector< tap_t > _taps
Definition: filters.hpp:158
boost::shared_ptr< analog_filter_base > sptr
Definition: filters.hpp:88
virtual std::string to_pp_string()
Definition: filters.hpp:214
UHD_INLINE const std::string & get_analog_type()
Definition: filters.hpp:101
UHD_INLINE double get_decimation()
Definition: filters.hpp:199
UHD_INLINE double get_interpolation()
Definition: filters.hpp:194
virtual UHD_INLINE bool is_bypassed()
Definition: filters.hpp:58
tap_t _tap_full_scale
Definition: filters.hpp:156
Definition: filters.hpp:150
bool _bypass
Definition: filters.hpp:77
Definition: filters.hpp:84
UHD_INLINE void set_cutoff(const double cutoff)
Definition: filters.hpp:141
Definition: build_info.hpp:25
void set_taps(const std::vector< tap_t > &taps)
Definition: filters.hpp:262
digital_filter_base(filter_type type, bool bypass, size_t position_index, double rate, size_t interpolation, size_t decimation, double tap_full_scale, size_t max_num_taps, const std::vector< tap_t > &taps)
Definition: filters.hpp:162
Definition: filters.hpp:35
UHD_INLINE double get_rolloff()
Definition: filters.hpp:136
boost::shared_ptr< filter_info_base > sptr
Definition: filters.hpp:38
#define UHD_MSG(type)
Definition: msg.hpp:31
UHD_INLINE double get_input_rate()
Definition: filters.hpp:189
Definition: filters.hpp:109
UHD_INLINE double get_tap_full_scale()
Definition: filters.hpp:204
analog_filter_base(filter_type type, bool bypass, size_t position_index, const std::string &analog_type)
Definition: filters.hpp:89
virtual ~filter_info_base()
Definition: filters.hpp:68
Definition: filters.hpp:41
#define UHD_INLINE
Definition: config.h:63
digital_filter_fir(filter_info_base::filter_type type, bool bypass, size_t position_index, double rate, size_t interpolation, size_t decimation, size_t tap_bit_width, size_t max_num_taps, const std::vector< tap_t > &taps)
Definition: filters.hpp:247
analog_filter_lp(filter_type type, bool bypass, size_t position_index, const std::string &analog_type, double cutoff, double rolloff)
Definition: filters.hpp:116
size_t _position_index
Definition: filters.hpp:78
#define UHD_API
Definition: config.h:73
filter_type
Definition: filters.hpp:39
filter_info_base(filter_type type, bool bypass, size_t position_index)
Definition: filters.hpp:47
boost::shared_ptr< analog_filter_lp > sptr
Definition: filters.hpp:115
UHD_API std::ostream & operator<<(std::ostream &os, filter_info_base &f)
UHD_INLINE double get_cutoff()
Definition: filters.hpp:131
boost::shared_ptr< digital_filter_base > sptr
Definition: filters.hpp:161
UHD_INLINE double get_output_rate()
Definition: filters.hpp:184
Definition: filters.hpp:42
double _rate
Definition: filters.hpp:153
boost::uint32_t _decimation
Definition: filters.hpp:155
UHD_INLINE filter_type get_type()
Definition: filters.hpp:63
boost::uint32_t _interpolation
Definition: filters.hpp:154
Definition: filters.hpp:43
boost::uint32_t _max_num_taps
Definition: filters.hpp:157