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