GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
fir_filter_with_buffer.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010,2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H
12 #define INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H
13 
14 #include <gnuradio/filter/api.h>
15 #include <gnuradio/gr_complex.h>
16 #include <volk/volk_alloc.hh>
17 #include <vector>
18 
19 namespace gr {
20 namespace filter {
21 namespace kernel {
22 
23 /*!
24  * \brief FIR with internal buffer for float input, float output and float taps.
25  * \ingroup filter
26  */
28 {
29 private:
30  mutable volk::vector<float> d_output; // Temporary storage for one element.
31  int d_align;
32  int d_naligned;
33  std::vector<float> d_taps;
34  unsigned int d_ntaps;
35  volk::vector<float> d_buffer_ptr;
36  float* d_buffer; // Current position pointer into d_buffer_ptr.
37  unsigned int d_idx;
38  std::vector<volk::vector<float>> d_aligned_taps;
39 
40 public:
41  // CONSTRUCTORS
42 
43  /*!
44  * \brief construct new FIR with given taps.
45  *
46  * Note that taps must be in forward order, e.g., coefficient 0 is
47  * stored in new_taps[0], coefficient 1 is stored in
48  * new_taps[1], etc.
49  */
50  fir_filter_with_buffer_fff(const std::vector<float>& taps);
51 
52  // Disable copy because of the raw pointer member d_buffer.
57 
58  // MANIPULATORS
59 
60  /*!
61  * \brief compute a single output value.
62  *
63  * \p input is a single input value of the filter type
64  *
65  * \returns the filtered input value.
66  */
67  float filter(float input);
68 
69  /*!
70  * \brief compute a single output value; designed for decimating filters.
71  *
72  * \p input is a single input value of the filter type. The value of dec is the
73  * decimating value of the filter, so input[] must have dec valid values.
74  * The filter pushes dec number of items onto the circ. buffer before computing
75  * a single output.
76  *
77  * \returns the filtered input value.
78  */
79  float filter(const float input[], unsigned long dec);
80 
81  /*!
82  * \brief compute an array of N output values.
83  *
84  * \p input must have (n - 1 + ntaps()) valid entries.
85  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
86  */
87  void filterN(float output[], const float input[], unsigned long n);
88 
89  /*!
90  * \brief compute an array of N output values, decimating the input
91  *
92  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
93  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
94  * compute the output values.
95  */
96  void filterNdec(float output[],
97  const float input[],
98  unsigned long n,
99  unsigned long decimate);
100 
101  // ACCESSORS
102 
103  /*!
104  * \return number of taps in filter.
105  */
106  unsigned int ntaps() const { return d_ntaps; }
107 
108  /*!
109  * \brief install \p new_taps as the current taps.
110  */
111  void set_taps(const std::vector<float>& taps);
112 
113  /*!
114  * \return current taps
115  */
116  std::vector<float> taps() const;
117 };
118 
119 
120 /**************************************************************/
121 
122 
123 /*!
124  * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex
125  * taps. \ingroup filter
126  */
128 {
129 private:
130  mutable volk::vector<gr_complex> d_output; // Temporary storage for one element.
131  int d_align;
132  int d_naligned;
133  std::vector<gr_complex> d_taps;
134  unsigned int d_ntaps;
135  volk::vector<gr_complex> d_buffer_ptr;
136  gr_complex* d_buffer; // Current position pointer into d_buffer_ptr.
137  unsigned int d_idx;
138  std::vector<volk::vector<gr_complex>> d_aligned_taps;
139 
140 public:
141  // CONSTRUCTORS
142 
143  /*!
144  * \brief construct new FIR with given taps.
145  *
146  * Note that taps must be in forward order, e.g., coefficient 0 is
147  * stored in new_taps[0], coefficient 1 is stored in
148  * new_taps[1], etc.
149  */
150  fir_filter_with_buffer_ccc(const std::vector<gr_complex>& taps);
151 
152  // Disable copy because of the raw pointer member d_buffer.
157 
158  // MANIPULATORS
159 
160  /*!
161  * \brief compute a single output value.
162  *
163  * \p input is a single input value of the filter type
164  *
165  * \returns the filtered input value.
166  */
168 
169  /*!
170  * \brief compute a single output value; designed for decimating filters.
171  *
172  * \p input is a single input value of the filter type. The value of dec is the
173  * decimating value of the filter, so input[] must have dec valid values.
174  * The filter pushes dec number of items onto the circ. buffer before computing
175  * a single output.
176  *
177  * \returns the filtered input value.
178  */
179  gr_complex filter(const gr_complex input[], unsigned long dec);
180 
181  /*!
182  * \brief compute an array of N output values.
183  *
184  * \p input must have (n - 1 + ntaps()) valid entries.
185  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
186  */
187  void filterN(gr_complex output[], const gr_complex input[], unsigned long n);
188 
189  /*!
190  * \brief compute an array of N output values, decimating the input
191  *
192  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
193  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
194  * compute the output values.
195  */
196  void filterNdec(gr_complex output[],
197  const gr_complex input[],
198  unsigned long n,
199  unsigned long decimate);
200 
201  // ACCESSORS
202 
203  /*!
204  * \return number of taps in filter.
205  */
206  unsigned int ntaps() const { return d_ntaps; }
207 
208  /*!
209  * \brief install \p new_taps as the current taps.
210  */
211  void set_taps(const std::vector<gr_complex>& taps);
212 
213  /*!
214  * \return current taps
215  */
216  std::vector<gr_complex> taps() const;
217 };
218 
219 
220 /**************************************************************/
221 
222 
223 /*!
224  * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex
225  * taps. \ingroup filter
226  */
228 {
229 private:
230  mutable volk::vector<gr_complex> d_output; // Temporary storage for one element.
231  int d_align;
232  int d_naligned;
233  std::vector<float> d_taps;
234  unsigned int d_ntaps;
235  volk::vector<gr_complex> d_buffer_ptr;
236  gr_complex* d_buffer; // Current position pointer into d_buffer_ptr.
237  unsigned int d_idx;
238  std::vector<volk::vector<float>> d_aligned_taps;
239 
240 public:
241  // CONSTRUCTORS
242 
243  /*!
244  * \brief construct new FIR with given taps.
245  *
246  * Note that taps must be in forward order, e.g., coefficient 0 is
247  * stored in new_taps[0], coefficient 1 is stored in
248  * new_taps[1], etc.
249  */
250  fir_filter_with_buffer_ccf(const std::vector<float>& taps);
251 
252  // Disable copy because of the raw pointer member d_buffer.
257 
258  // MANIPULATORS
259 
260  /*!
261  * \brief compute a single output value.
262  *
263  * \p input is a single input value of the filter type
264  *
265  * \returns the filtered input value.
266  */
268 
269  /*!
270  * \brief compute a single output value; designed for decimating filters.
271  *
272  * \p input is a single input value of the filter type. The value of dec is the
273  * decimating value of the filter, so input[] must have dec valid values.
274  * The filter pushes dec number of items onto the circ. buffer before computing
275  * a single output.
276  *
277  * \returns the filtered input value.
278  */
279  gr_complex filter(const gr_complex input[], unsigned long dec);
280 
281  /*!
282  * \brief compute an array of N output values.
283  *
284  * \p input must have (n - 1 + ntaps()) valid entries.
285  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
286  */
287  void filterN(gr_complex output[], const gr_complex input[], unsigned long n);
288 
289  /*!
290  * \brief compute an array of N output values, decimating the input
291  *
292  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
293  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
294  * compute the output values.
295  */
296  void filterNdec(gr_complex output[],
297  const gr_complex input[],
298  unsigned long n,
299  unsigned long decimate);
300 
301  // ACCESSORS
302 
303  /*!
304  * \return number of taps in filter.
305  */
306  unsigned int ntaps() const { return d_ntaps; }
307 
308  /*!
309  * \brief install \p new_taps as the current taps.
310  */
311  void set_taps(const std::vector<float>& taps);
312 
313  /*!
314  * \return current taps
315  */
316  std::vector<float> taps() const;
317 };
318 
319 
320 } /* namespace kernel */
321 } /* namespace filter */
322 } /* namespace gr */
323 
324 #endif /* INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H */
FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
Definition: fir_filter_with_buffer.h:128
fir_filter_with_buffer_ccc & operator=(fir_filter_with_buffer_ccc &&)=default
fir_filter_with_buffer_ccc(const std::vector< gr_complex > &taps)
construct new FIR with given taps.
fir_filter_with_buffer_ccc & operator=(const fir_filter_with_buffer_ccc &)=delete
gr_complex filter(const gr_complex input[], unsigned long dec)
compute a single output value; designed for decimating filters.
std::vector< gr_complex > taps() const
fir_filter_with_buffer_ccc(fir_filter_with_buffer_ccc &&)=default
void filterN(gr_complex output[], const gr_complex input[], unsigned long n)
compute an array of N output values.
void filterNdec(gr_complex output[], const gr_complex input[], unsigned long n, unsigned long decimate)
compute an array of N output values, decimating the input
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:206
gr_complex filter(gr_complex input)
compute a single output value.
void set_taps(const std::vector< gr_complex > &taps)
install new_taps as the current taps.
fir_filter_with_buffer_ccc(const fir_filter_with_buffer_ccc &)=delete
FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
Definition: fir_filter_with_buffer.h:228
fir_filter_with_buffer_ccf & operator=(fir_filter_with_buffer_ccf &&)=default
gr_complex filter(const gr_complex input[], unsigned long dec)
compute a single output value; designed for decimating filters.
void filterNdec(gr_complex output[], const gr_complex input[], unsigned long n, unsigned long decimate)
compute an array of N output values, decimating the input
fir_filter_with_buffer_ccf(const fir_filter_with_buffer_ccf &)=delete
void set_taps(const std::vector< float > &taps)
install new_taps as the current taps.
fir_filter_with_buffer_ccf(const std::vector< float > &taps)
construct new FIR with given taps.
fir_filter_with_buffer_ccf & operator=(const fir_filter_with_buffer_ccf &)=delete
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:306
void filterN(gr_complex output[], const gr_complex input[], unsigned long n)
compute an array of N output values.
gr_complex filter(gr_complex input)
compute a single output value.
fir_filter_with_buffer_ccf(fir_filter_with_buffer_ccf &&)=default
FIR with internal buffer for float input, float output and float taps.
Definition: fir_filter_with_buffer.h:28
void filterN(float output[], const float input[], unsigned long n)
compute an array of N output values.
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:106
void filterNdec(float output[], const float input[], unsigned long n, unsigned long decimate)
compute an array of N output values, decimating the input
fir_filter_with_buffer_fff(const std::vector< float > &taps)
construct new FIR with given taps.
void set_taps(const std::vector< float > &taps)
install new_taps as the current taps.
fir_filter_with_buffer_fff(fir_filter_with_buffer_fff &&)=default
float filter(float input)
compute a single output value.
fir_filter_with_buffer_fff & operator=(const fir_filter_with_buffer_fff &)=delete
fir_filter_with_buffer_fff(const fir_filter_with_buffer_fff &)=delete
fir_filter_with_buffer_fff & operator=(fir_filter_with_buffer_fff &&)=default
float filter(const float input[], unsigned long dec)
compute a single output value; designed for decimating filters.
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:18
std::complex< float > gr_complex
Definition: gr_complex.h:15
static constexpr float taps[NSTEPS+1][NTAPS]
Definition: interpolator_taps.h:9
GNU Radio logging wrapper.
Definition: basic_block.h:29