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