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