GNU Radio Manual and C++ API Reference  3.8.1.0
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  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H
24 #define INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H
25 
26 #include <gnuradio/filter/api.h>
27 #include <gnuradio/gr_complex.h>
28 #include <vector>
29 
30 namespace gr {
31 namespace filter {
32 namespace kernel {
33 
34 /*!
35  * \brief FIR with internal buffer for float input, float output and float taps.
36  * \ingroup filter
37  */
39 {
40 private:
41  std::vector<float> d_taps;
42  unsigned int d_ntaps;
43  float* d_buffer_ptr;
44  float* d_buffer;
45  unsigned int d_idx;
46  float** d_aligned_taps;
47  float* d_output;
48  int d_align;
49  int d_naligned;
50 
51 public:
52  // CONSTRUCTORS
53 
54  /*!
55  * \brief construct new FIR with given taps.
56  *
57  * Note that taps must be in forward order, e.g., coefficient 0 is
58  * stored in new_taps[0], coefficient 1 is stored in
59  * new_taps[1], etc.
60  */
61  fir_filter_with_buffer_fff(const std::vector<float>& taps);
62 
64 
65  // MANIPULATORS
66 
67  /*!
68  * \brief compute a single output value.
69  *
70  * \p input is a single input value of the filter type
71  *
72  * \returns the filtered input value.
73  */
74  float filter(float input);
75 
76  /*!
77  * \brief compute a single output value; designed for decimating filters.
78  *
79  * \p input is a single input value of the filter type. The value of dec is the
80  * decimating value of the filter, so input[] must have dec valid values.
81  * The filter pushes dec number of items onto the circ. buffer before computing
82  * a single output.
83  *
84  * \returns the filtered input value.
85  */
86  float filter(const float input[], unsigned long dec);
87 
88  /*!
89  * \brief compute an array of N output values.
90  *
91  * \p input must have (n - 1 + ntaps()) valid entries.
92  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
93  */
94  void filterN(float output[], const float input[], unsigned long n);
95 
96  /*!
97  * \brief compute an array of N output values, decimating the input
98  *
99  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
100  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
101  * compute the output values.
102  */
103  void filterNdec(float output[],
104  const float input[],
105  unsigned long n,
106  unsigned long decimate);
107 
108  // ACCESSORS
109 
110  /*!
111  * \return number of taps in filter.
112  */
113  unsigned int ntaps() const { return d_ntaps; }
114 
115  /*!
116  * \brief install \p new_taps as the current taps.
117  */
118  void set_taps(const std::vector<float>& taps);
119 
120  /*!
121  * \return current taps
122  */
123  std::vector<float> taps() const;
124 };
125 
126 
127 /**************************************************************/
128 
129 
130 /*!
131  * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex
132  * taps. \ingroup filter
133  */
135 {
136 private:
137  std::vector<gr_complex> d_taps;
138  unsigned int d_ntaps;
139  gr_complex* d_buffer_ptr;
140  gr_complex* d_buffer;
141  unsigned int d_idx;
142  gr_complex** d_aligned_taps;
143  gr_complex* d_output;
144  int d_align;
145  int d_naligned;
146 
147 public:
148  // CONSTRUCTORS
149 
150  /*!
151  * \brief construct new FIR with given taps.
152  *
153  * Note that taps must be in forward order, e.g., coefficient 0 is
154  * stored in new_taps[0], coefficient 1 is stored in
155  * new_taps[1], etc.
156  */
157  fir_filter_with_buffer_ccc(const std::vector<gr_complex>& taps);
158 
160 
161  // MANIPULATORS
162 
163  /*!
164  * \brief compute a single output value.
165  *
166  * \p input is a single input value of the filter type
167  *
168  * \returns the filtered input value.
169  */
170  gr_complex filter(gr_complex input);
171 
172  /*!
173  * \brief compute a single output value; designed for decimating filters.
174  *
175  * \p input is a single input value of the filter type. The value of dec is the
176  * decimating value of the filter, so input[] must have dec valid values.
177  * The filter pushes dec number of items onto the circ. buffer before computing
178  * a single output.
179  *
180  * \returns the filtered input value.
181  */
182  gr_complex filter(const gr_complex input[], unsigned long dec);
183 
184  /*!
185  * \brief compute an array of N output values.
186  *
187  * \p input must have (n - 1 + ntaps()) valid entries.
188  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
189  */
190  void filterN(gr_complex output[], const gr_complex input[], unsigned long n);
191 
192  /*!
193  * \brief compute an array of N output values, decimating the input
194  *
195  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
196  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
197  * compute the output values.
198  */
199  void filterNdec(gr_complex output[],
200  const gr_complex input[],
201  unsigned long n,
202  unsigned long decimate);
203 
204  // ACCESSORS
205 
206  /*!
207  * \return number of taps in filter.
208  */
209  unsigned int ntaps() const { return d_ntaps; }
210 
211  /*!
212  * \brief install \p new_taps as the current taps.
213  */
214  void set_taps(const std::vector<gr_complex>& taps);
215 
216  /*!
217  * \return current taps
218  */
219  std::vector<gr_complex> taps() const;
220 };
221 
222 
223 /**************************************************************/
224 
225 
226 /*!
227  * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex
228  * taps. \ingroup filter
229  */
231 {
232 private:
233  std::vector<float> d_taps;
234  unsigned int d_ntaps;
235  gr_complex* d_buffer_ptr;
236  gr_complex* d_buffer;
237  unsigned int d_idx;
238  float** d_aligned_taps;
239  gr_complex* d_output;
240  int d_align;
241  int d_naligned;
242 
243 public:
244  // CONSTRUCTORS
245 
246  /*!
247  * \brief construct new FIR with given taps.
248  *
249  * Note that taps must be in forward order, e.g., coefficient 0 is
250  * stored in new_taps[0], coefficient 1 is stored in
251  * new_taps[1], etc.
252  */
253  fir_filter_with_buffer_ccf(const std::vector<float>& taps);
254 
256 
257  // MANIPULATORS
258 
259  /*!
260  * \brief compute a single output value.
261  *
262  * \p input is a single input value of the filter type
263  *
264  * \returns the filtered input value.
265  */
266  gr_complex filter(gr_complex input);
267 
268  /*!
269  * \brief compute a single output value; designed for decimating filters.
270  *
271  * \p input is a single input value of the filter type. The value of dec is the
272  * decimating value of the filter, so input[] must have dec valid values.
273  * The filter pushes dec number of items onto the circ. buffer before computing
274  * a single output.
275  *
276  * \returns the filtered input value.
277  */
278  gr_complex filter(const gr_complex input[], unsigned long dec);
279 
280  /*!
281  * \brief compute an array of N output values.
282  *
283  * \p input must have (n - 1 + ntaps()) valid entries.
284  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
285  */
286  void filterN(gr_complex output[], const gr_complex input[], unsigned long n);
287 
288  /*!
289  * \brief compute an array of N output values, decimating the input
290  *
291  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
292  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
293  * compute the output values.
294  */
295  void filterNdec(gr_complex output[],
296  const gr_complex input[],
297  unsigned long n,
298  unsigned long decimate);
299 
300  // ACCESSORS
301 
302  /*!
303  * \return number of taps in filter.
304  */
305  unsigned int ntaps() const { return d_ntaps; }
306 
307  /*!
308  * \brief install \p new_taps as the current taps.
309  */
310  void set_taps(const std::vector<float>& taps);
311 
312  /*!
313  * \return current taps
314  */
315  std::vector<float> taps() const;
316 };
317 
318 
319 } /* namespace kernel */
320 } /* namespace filter */
321 } /* namespace gr */
322 
323 #endif /* INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H */
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:113
FIR with internal buffer for float input, float output and float taps.
Definition: fir_filter_with_buffer.h:38
FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
Definition: fir_filter_with_buffer.h:134
std::complex< float > gr_complex
Definition: gr_complex.h:27
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:209
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
static const float taps[NSTEPS+1][NTAPS]
Definition: interpolator_taps.h:9
FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
Definition: fir_filter_with_buffer.h:230
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:305
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:30