GNU Radio Manual and C++ API Reference  3.7.13.4
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 <vector>
28 #include <gnuradio/gr_complex.h>
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 
53  // CONSTRUCTORS
54 
55  /*!
56  * \brief construct new FIR with given taps.
57  *
58  * Note that taps must be in forward order, e.g., coefficient 0 is
59  * stored in new_taps[0], coefficient 1 is stored in
60  * new_taps[1], etc.
61  */
62  fir_filter_with_buffer_fff(const std::vector<float> &taps);
63 
65 
66  // MANIPULATORS
67 
68  /*!
69  * \brief compute a single output value.
70  *
71  * \p input is a single input value of the filter type
72  *
73  * \returns the filtered input value.
74  */
75  float filter(float input);
76 
77  /*!
78  * \brief compute a single output value; designed for decimating filters.
79  *
80  * \p input is a single input value of the filter type. The value of dec is the
81  * decimating value of the filter, so input[] must have dec valid values.
82  * The filter pushes dec number of items onto the circ. buffer before computing
83  * a single output.
84  *
85  * \returns the filtered input value.
86  */
87  float filter(const float input[], unsigned long dec);
88 
89  /*!
90  * \brief compute an array of N output values.
91  *
92  * \p input must have (n - 1 + ntaps()) valid entries.
93  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
94  */
95  void filterN(float output[],
96  const float input[],
97  unsigned long n);
98 
99  /*!
100  * \brief compute an array of N output values, decimating the input
101  *
102  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
103  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
104  * compute the output values.
105  */
106  void filterNdec(float output[], const float input[],
107  unsigned long n, unsigned long decimate);
108 
109  // ACCESSORS
110 
111  /*!
112  * \return number of taps in filter.
113  */
114  unsigned int ntaps() const { return d_ntaps; }
115 
116  /*!
117  * \brief install \p new_taps as the current taps.
118  */
119  void set_taps(const std::vector<float> &taps);
120 
121  /*!
122  * \return current taps
123  */
124  std::vector<float> taps() const;
125  };
126 
127 
128  /**************************************************************/
129 
130 
131  /*!
132  * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
133  * \ingroup filter
134  */
136  {
137  private:
138  std::vector<gr_complex> d_taps;
139  unsigned int d_ntaps;
140  gr_complex *d_buffer_ptr;
141  gr_complex *d_buffer;
142  unsigned int d_idx;
143  gr_complex **d_aligned_taps;
144  gr_complex *d_output;
145  int d_align;
146  int d_naligned;
147 
148  public:
149 
150  // CONSTRUCTORS
151 
152  /*!
153  * \brief construct new FIR with given taps.
154  *
155  * Note that taps must be in forward order, e.g., coefficient 0 is
156  * stored in new_taps[0], coefficient 1 is stored in
157  * new_taps[1], etc.
158  */
159  fir_filter_with_buffer_ccc(const std::vector<gr_complex> &taps);
160 
162 
163  // MANIPULATORS
164 
165  /*!
166  * \brief compute a single output value.
167  *
168  * \p input is a single input value of the filter type
169  *
170  * \returns the filtered input value.
171  */
172  gr_complex filter(gr_complex input);
173 
174  /*!
175  * \brief compute a single output value; designed for decimating filters.
176  *
177  * \p input is a single input value of the filter type. The value of dec is the
178  * decimating value of the filter, so input[] must have dec valid values.
179  * The filter pushes dec number of items onto the circ. buffer before computing
180  * a single output.
181  *
182  * \returns the filtered input value.
183  */
184  gr_complex filter(const gr_complex input[], unsigned long dec);
185 
186  /*!
187  * \brief compute an array of N output values.
188  *
189  * \p input must have (n - 1 + ntaps()) valid entries.
190  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
191  */
192  void filterN(gr_complex output[],
193  const gr_complex input[],
194  unsigned long n);
195 
196  /*!
197  * \brief compute an array of N output values, decimating the input
198  *
199  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
200  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
201  * compute the output values.
202  */
203  void filterNdec(gr_complex output[], const gr_complex input[],
204  unsigned long n, unsigned long decimate);
205 
206  // ACCESSORS
207 
208  /*!
209  * \return number of taps in filter.
210  */
211  unsigned int ntaps() const { return d_ntaps; }
212 
213  /*!
214  * \brief install \p new_taps as the current taps.
215  */
216  void set_taps(const std::vector<gr_complex> &taps);
217 
218  /*!
219  * \return current taps
220  */
221  std::vector<gr_complex> taps() const;
222  };
223 
224 
225  /**************************************************************/
226 
227 
228  /*!
229  * \brief FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
230  * \ingroup filter
231  */
233  {
234  private:
235  std::vector<float> d_taps;
236  unsigned int d_ntaps;
237  gr_complex *d_buffer_ptr;
238  gr_complex *d_buffer;
239  unsigned int d_idx;
240  float **d_aligned_taps;
241  gr_complex *d_output;
242  int d_align;
243  int d_naligned;
244 
245  public:
246 
247  // CONSTRUCTORS
248 
249  /*!
250  * \brief construct new FIR with given taps.
251  *
252  * Note that taps must be in forward order, e.g., coefficient 0 is
253  * stored in new_taps[0], coefficient 1 is stored in
254  * new_taps[1], etc.
255  */
256  fir_filter_with_buffer_ccf(const std::vector<float> &taps);
257 
259 
260  // MANIPULATORS
261 
262  /*!
263  * \brief compute a single output value.
264  *
265  * \p input is a single input value of the filter type
266  *
267  * \returns the filtered input value.
268  */
269  gr_complex filter(gr_complex input);
270 
271  /*!
272  * \brief compute a single output value; designed for decimating filters.
273  *
274  * \p input is a single input value of the filter type. The value of dec is the
275  * decimating value of the filter, so input[] must have dec valid values.
276  * The filter pushes dec number of items onto the circ. buffer before computing
277  * a single output.
278  *
279  * \returns the filtered input value.
280  */
281  gr_complex filter(const gr_complex input[], unsigned long dec);
282 
283  /*!
284  * \brief compute an array of N output values.
285  *
286  * \p input must have (n - 1 + ntaps()) valid entries.
287  * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
288  */
289  void filterN(gr_complex output[],
290  const gr_complex input[],
291  unsigned long n);
292 
293  /*!
294  * \brief compute an array of N output values, decimating the input
295  *
296  * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
297  * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to
298  * compute the output values.
299  */
300  void filterNdec(gr_complex output[], const gr_complex input[],
301  unsigned long n, unsigned long decimate);
302 
303  // ACCESSORS
304 
305  /*!
306  * \return number of taps in filter.
307  */
308  unsigned int ntaps() const { return d_ntaps; }
309 
310  /*!
311  * \brief install \p new_taps as the current taps.
312  */
313  void set_taps(const std::vector<float> &taps);
314 
315  /*!
316  * \return current taps
317  */
318  std::vector<float> taps() const;
319  };
320 
321 
322  } /* namespace kernel */
323  } /* namespace filter */
324 } /* namespace gr */
325 
326 #endif /* INCLUDED_FILTER_FIR_FILTER_WITH_BUFFER_H */
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:211
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:308
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:135
std::complex< float > gr_complex
Definition: gr_complex.h:27
Include this header to use the message passing features.
Definition: logger.h:695
static const float taps[NSTEPS+1][NTAPS]
Definition: interpolator_taps.h:9
unsigned int ntaps() const
Definition: fir_filter_with_buffer.h:114
FIR with internal buffer for gr_complex input, gr_complex output and gr_complex taps.
Definition: fir_filter_with_buffer.h:232
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:30