d77c15abac65ea08fa4be97711b563a7e8ade5fa
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_firdes.i
1 /* -*- C++ -*- */
2 /*
3  * Copyright 2002,2008 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 /*!
24  * \brief Finite Impulse Response (FIR) filter design functions.
25  */
26
27 %rename(firdes) gr_firdes;
28
29 class gr_firdes {
30  public:
31
32   enum win_type {
33     WIN_HAMMING = 0,    // max attenuation 53 dB
34     WIN_HANN = 1,       // max attenuation 44 dB
35     WIN_BLACKMAN = 2,   // max attenuation 74 dB
36     WIN_RECTANGULAR = 3,
37     WIN_KAISER = 4      // max attenuation variable with beta, google it
38   };
39
40   // ... class methods ...
41
42   /*!
43    * \brief use "window method" to design a low-pass FIR filter
44    *
45    * \p gain:                   overall gain of filter (typically 1.0)
46    * \p sampling_freq:          sampling freq (Hz)
47    * \p cutoff_freq:            center of transition band (Hz)
48    * \p transition_width:       width of transition band (Hz).
49    *                            The normalized width of the transition
50    *                            band is what sets the number of taps
51    *                            required.  Narrow --> more taps
52    * \p window_type:            What kind of window to use. Determines
53    *                            maximum attenuation and passband ripple.
54    * \p beta:                   parameter for Kaiser window
55    */
56   static std::vector<float>
57   low_pass (double gain,
58             double sampling_freq,
59             double cutoff_freq,         // Hz center of transition band
60             double transition_width,    // Hz width of transition band
61             win_type window = WIN_HAMMING,
62             double beta = 6.76          // used only with Kaiser
63             ) throw(std::out_of_range);
64
65   /*!
66    * \brief use "window method" to design a low-pass FIR filter
67    *  using alternative design criteria
68    * \p gain:                   overall gain of filter (typically 1.0)
69    * \p sampling_freq:          sampling freq (Hz)
70    * \p cutoff_freq:            center of transition band (Hz)
71    * \p transition_width:       width of transition band (Hz).
72    * \p attenuation_dB          out of band attenuation
73    *                            The normalized width of the transition
74    *                            band and the required stop band
75    *                            attenuation is what sets the number of taps
76    *                            required.  Narrow --> more taps
77    *                            More attenuation --> more taps
78    * \p window_type:            What kind of window to use. Determines
79    *                            maximum attenuation and passband ripple.
80    * \p beta:                   parameter for Kaiser window
81    */
82   static std::vector<float>
83   low_pass_2 (double gain,
84             double sampling_freq,
85             double cutoff_freq,         // Hz center of transition band
86             double transition_width,    // Hz width of transition band
87             double attenuation_dB,       // out of band attenuation
88             win_type window = WIN_HAMMING,
89             double beta = 6.76          // used only with Kaiser
90             ) throw(std::out_of_range);
91
92   /*!
93    * \brief use "window method" to design a high-pass FIR filter
94    *
95    * \p gain:                   overall gain of filter (typically 1.0)
96    * \p sampling_freq:          sampling freq (Hz)
97    * \p cutoff_freq:            center of transition band (Hz)
98    * \p transition_width:       width of transition band (Hz).
99    *                            The normalized width of the transition
100    *                            band is what sets the number of taps
101    *                            required.  Narrow --> more taps
102    * \p window_type:            What kind of window to use. Determines
103    *                            maximum attenuation and passband ripple.
104    * \p beta:                   parameter for Kaiser window
105    */
106
107   static std::vector<float>
108   high_pass (double gain,
109              double sampling_freq,
110              double cutoff_freq,                // Hz center of transition band
111              double transition_width,           // Hz width of transition band
112              win_type window = WIN_HAMMING,
113              double beta = 6.76                 // used only with Kaiser
114              ) throw(std::out_of_range); 
115
116   /*!
117    * \brief use "window method" to design a high-pass FIR filter
118    *
119    * \p gain:                   overall gain of filter (typically 1.0)
120    * \p sampling_freq:          sampling freq (Hz)
121    * \p cutoff_freq:            center of transition band (Hz)
122    * \p transition_width:       width of transition band (Hz).
123    * \p attenuation_dB          out of band attenuation
124    *                            The normalized width of the transition
125    *                            band and the required stop band
126    *                            attenuation is what sets the number of taps
127    *                            required.  Narrow --> more taps
128    *                            More attenuation --> more taps
129    * \p window_type:            What kind of window to use. Determines
130    *                            maximum attenuation and passband ripple.
131    * \p beta:                   parameter for Kaiser window
132    */
133
134   static std::vector<float>
135   high_pass_2 (double gain,
136              double sampling_freq,
137              double cutoff_freq,                // Hz center of transition band
138              double transition_width,           // Hz width of transition band
139              double attenuation_dB,             // out of band attenuation dB
140              win_type window = WIN_HAMMING,
141              double beta = 6.76);               // used only with Kaiser
142
143
144   /*!
145    * \brief use "window method" to design a band-pass FIR filter
146    *
147    * \p gain:                   overall gain of filter (typically 1.0)
148    * \p sampling_freq:          sampling freq (Hz)
149    * \p low_cutoff_freq:        center of transition band (Hz)
150    * \p high_cutoff_freq:       center of transition band (Hz)
151    * \p transition_width:       width of transition band (Hz).
152    *                            The normalized width of the transition
153    *                            band is what sets the number of taps
154    *                            required.  Narrow --> more taps
155    * \p window_type:            What kind of window to use. Determines
156    *                            maximum attenuation and passband ripple.
157    * \p beta:                   parameter for Kaiser window
158    */
159
160   static std::vector<float>
161   band_pass (double gain,
162              double sampling_freq,
163              double low_cutoff_freq,            // Hz center of transition band
164              double high_cutoff_freq,           // Hz center of transition band
165              double transition_width,           // Hz width of transition band
166              win_type window = WIN_HAMMING,
167              double beta = 6.76                 // used only with Kaiser
168              ) throw(std::out_of_range); 
169
170
171   /*!
172    * \brief use "window method" to design a band-pass FIR filter
173    *
174    * \p gain:                   overall gain of filter (typically 1.0)
175    * \p sampling_freq:          sampling freq (Hz)
176    * \p low_cutoff_freq:        center of transition band (Hz)
177    * \p high_cutoff_freq:       center of transition band (Hz)
178    * \p transition_width:       width of transition band (Hz).
179    * \p attenuation_dB          out of band attenuation
180    *                            The normalized width of the transition
181    *                            band and the required stop band
182    *                            attenuation is what sets the number of taps
183    *                            required.  Narrow --> more taps
184    *                            More attenuation --> more taps
185    * \p window_type:            What kind of window to use. Determines
186    *                            maximum attenuation and passband ripple.
187    * \p beta:                   parameter for Kaiser window
188    */
189
190   static std::vector<float>
191   band_pass_2 (double gain,
192              double sampling_freq,
193              double low_cutoff_freq,            // Hz beginning transition band
194              double high_cutoff_freq,           // Hz beginning transition band
195              double transition_width,           // Hz width of transition band
196              double attenuation_dB,             // out of band attenuation dB
197              win_type window = WIN_HAMMING,
198              double beta = 6.76);               // used only with Kaiser
199
200   /*!
201    * \brief use "window method" to design a band-reject FIR filter
202    *
203    * \p gain:                   overall gain of filter (typically 1.0)
204    * \p sampling_freq:          sampling freq (Hz)
205    * \p low_cutoff_freq:        center of transition band (Hz)
206    * \p high_cutoff_freq:       center of transition band (Hz)
207    * \p transition_width:       width of transition band (Hz).
208    *                            The normalized width of the transition
209    *                            band is what sets the number of taps
210    *                            required.  Narrow --> more taps
211    * \p window_type:            What kind of window to use. Determines
212    *                            maximum attenuation and passband ripple.
213    * \p beta:                   parameter for Kaiser window
214    */
215
216   static std::vector<gr_complex>
217   complex_band_pass (double gain,
218              double sampling_freq,
219              double low_cutoff_freq,            // Hz center of transition band
220              double high_cutoff_freq,           // Hz center of transition band
221              double transition_width,           // Hz width of transition band
222              win_type window = WIN_HAMMING,     // used only with Kaiser
223              double beta = 6.76
224              ) throw(std::out_of_range); 
225
226
227   /*!
228    * \brief use "window method" to design a complex band-pass FIR filter
229    *
230    * \p gain:                   overall gain of filter (typically 1.0)
231    * \p sampling_freq:          sampling freq (Hz)
232    * \p low_cutoff_freq:        center of transition band (Hz)
233    * \p high_cutoff_freq:       center of transition band (Hz)
234    * \p transition_width:       width of transition band (Hz).
235    * \p attenuation_dB          out of band attenuation
236    *                            The normalized width of the transition
237    *                            band and the required stop band
238    *                            attenuation is what sets the number of taps
239    *                            required.  Narrow --> more taps
240    *                            More attenuation --> more taps
241    * \p window_type:            What kind of window to use. Determines
242    *                            maximum attenuation and passband ripple.
243    * \p beta:                   parameter for Kaiser window
244    */
245
246   static std::vector<gr_complex>
247   complex_band_pass_2 (double gain,
248              double sampling_freq,
249              double low_cutoff_freq,            // Hz beginning transition band
250              double high_cutoff_freq,           // Hz beginning transition band
251              double transition_width,           // Hz width of transition band
252              double attenuation_dB,             // out of band attenuation dB
253              win_type window = WIN_HAMMING,
254              double beta = 6.76);               // used only with Kaiser
255
256   /*!
257    * \brief use "window method" to design a band-reject FIR filter
258    *
259    * \p gain:                   overall gain of filter (typically 1.0)
260    * \p sampling_freq:          sampling freq (Hz)
261    * \p low_cutoff_freq:        center of transition band (Hz)
262    * \p high_cutoff_freq:       center of transition band (Hz)
263    * \p transition_width:       width of transition band (Hz).
264    *                            The normalized width of the transition
265    *                            band is what sets the number of taps
266    *                            required.  Narrow --> more taps
267    * \p window_type:            What kind of window to use. Determines
268    *                            maximum attenuation and passband ripple.
269    * \p beta:                   parameter for Kaiser window
270    */
271
272   static std::vector<float>
273   band_reject (double gain,
274                double sampling_freq,
275                double low_cutoff_freq,          // Hz center of transition band
276                double high_cutoff_freq,         // Hz center of transition band
277                double transition_width,         // Hz width of transition band
278                win_type window = WIN_HAMMING,   // used only with Kaiser
279                double beta = 6.76
280                ) throw(std::out_of_range);
281
282
283   /*!
284    * \brief use "window method" to design a band-reject FIR filter
285    *
286    * \p gain:                   overall gain of filter (typically 1.0)
287    * \p sampling_freq:          sampling freq (Hz)
288    * \p low_cutoff_freq:        center of transition band (Hz)
289    * \p high_cutoff_freq:       center of transition band (Hz)
290    * \p transition_width:       width of transition band (Hz).
291    * \p attenuation_dB          out of band attenuation
292    *                            The normalized width of the transition
293    *                            band and the required stop band
294    *                            attenuation is what sets the number of taps
295    *                            required.  Narrow --> more taps
296    *                            More attenuation --> more taps
297    * \p window_type:            What kind of window to use. Determines
298    *                            maximum attenuation and passband ripple.
299    * \p beta:                   parameter for Kaiser window
300    */
301
302   static std::vector<float>
303   band_reject_2 (double gain,
304                double sampling_freq,
305                double low_cutoff_freq,          // Hz beginning transition band
306                double high_cutoff_freq,         // Hz beginning transition band
307                double transition_width,         // Hz width of transition band
308                double attenuation_dB,           // out of band attenuation dB
309                win_type window = WIN_HAMMING,
310                double beta = 6.76);             // used only with Kaiser
311
312   /*!\brief design a Hilbert Transform Filter
313    *
314    * \p ntaps:                  Number of taps, must be odd
315    * \p window_type:            What kind of window to use
316    * \p beta:                   Only used for Kaiser
317    */
318   static std::vector<float>
319   hilbert (unsigned int ntaps = 19,
320            win_type windowtype = WIN_RECTANGULAR,
321            double beta = 6.76
322            ) throw(std::out_of_range);
323    
324   /*!
325    * \brief design a Root Cosine FIR Filter (do we need a window?)
326    *
327    * \p gain:                   overall gain of filter (typically 1.0)
328    * \p sampling_freq:          sampling freq (Hz)
329    * \p symbol rate:            symbol rate, must be a factor of sample rate
330    * \p alpha:                  excess bandwidth factor
331    * \p ntaps:                  number of taps
332    */
333   static std::vector<float>
334   root_raised_cosine (double gain,
335                       double sampling_freq,
336                       double symbol_rate,       // Symbol rate, NOT bitrate (unless BPSK)
337                       double alpha,             // Excess Bandwidth Factor
338                       int ntaps) throw(std::out_of_range);
339
340   /*!
341    * \brief design a Gaussian filter
342    *
343    * \p gain:                   overall gain of filter (typically 1.0)
344    * \p symbols per bit:        symbol rate, must be a factor of sample rate
345    * \p bt:                     BT bandwidth time product
346    * \p ntaps:                  number of taps
347    */
348   static std::vector<float>
349   gaussian (double gain,
350             double spb,       
351             double bt,              // Bandwidth to bitrate ratio
352             int ntaps) throw(std::out_of_range);
353
354   /*!
355    * Return window given type, ntaps and optional beta.
356    */
357   static std::vector<float> gr_firdes::window (win_type type, int ntaps, double beta) 
358     throw(std::runtime_error);
359 };