3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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 2, or (at your option)
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.
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.
28 #include <gr_complex.h>
31 * \brief Finite Impulse Response (FIR) filter design functions.
38 WIN_HAMMING = 0, // max attenuation 53 dB
39 WIN_HANN = 1, // max attenuation 44 dB
40 WIN_BLACKMAN = 2, // max attenuation 74 dB
42 WIN_KAISER = 4 // max attenuation a function of beta, google it
46 // ... class methods ...
49 * \brief use "window method" to design a low-pass FIR filter
51 * \p gain: overall gain of filter (typically 1.0)
52 * \p sampling_freq: sampling freq (Hz)
53 * \p cutoff_freq: center of transition band (Hz)
54 * \p transition_width: width of transition band (Hz).
55 * The normalized width of the transition
56 * band is what sets the number of taps
57 * required. Narrow --> more taps
58 * \p window_type: What kind of window to use. Determines
59 * maximum attenuation and passband ripple.
60 * \p beta: parameter for Kaiser window
62 static std::vector<float>
63 low_pass (double gain,
65 double cutoff_freq, // Hz center of transition band
66 double transition_width, // Hz width of transition band
67 win_type window = WIN_HAMMING,
68 double beta = 6.76); // used only with Kaiser
71 * \brief use "window method" to design a high-pass FIR filter
73 * \p gain: overall gain of filter (typically 1.0)
74 * \p sampling_freq: sampling freq (Hz)
75 * \p cutoff_freq: center of transition band (Hz)
76 * \p transition_width: width of transition band (Hz).
77 * The normalized width of the transition
78 * band is what sets the number of taps
79 * required. Narrow --> more taps
80 * \p window_type: What kind of window to use. Determines
81 * maximum attenuation and passband ripple.
82 * \p beta: parameter for Kaiser window
84 static std::vector<float>
85 high_pass (double gain,
87 double cutoff_freq, // Hz center of transition band
88 double transition_width, // Hz width of transition band
89 win_type window = WIN_HAMMING,
90 double beta = 6.76); // used only with Kaiser
93 * \brief use "window method" to design a band-pass FIR filter
95 * \p gain: overall gain of filter (typically 1.0)
96 * \p sampling_freq: sampling freq (Hz)
97 * \p low_cutoff_freq: center of transition band (Hz)
98 * \p high_cutoff_freq: center of transition band (Hz)
99 * \p transition_width: width of transition band (Hz).
100 * The normalized width of the transition
101 * band is what sets the number of taps
102 * required. Narrow --> more taps
103 * \p window_type: What kind of window to use. Determines
104 * maximum attenuation and passband ripple.
105 * \p beta: parameter for Kaiser window
107 static std::vector<float>
108 band_pass (double gain,
109 double sampling_freq,
110 double low_cutoff_freq, // Hz center of transition band
111 double high_cutoff_freq, // Hz center of transition band
112 double transition_width, // Hz width of transition band
113 win_type window = WIN_HAMMING,
114 double beta = 6.76); // used only with Kaiser
118 * \brief use "window method" to design a complex band-pass FIR filter
120 * \p gain: overall gain of filter (typically 1.0)
121 * \p sampling_freq: sampling freq (Hz)
122 * \p low_cutoff_freq: center of transition band (Hz)
123 * \p high_cutoff_freq: center of transition band (Hz)
124 * \p transition_width: width of transition band (Hz).
125 * The normalized width of the transition
126 * band is what sets the number of taps
127 * required. Narrow --> more taps
128 * \p window_type: What kind of window to use. Determines
129 * maximum attenuation and passband ripple.
130 * \p beta: parameter for Kaiser window
133 static std::vector<gr_complex>
134 complex_band_pass (double gain,
135 double sampling_freq,
136 double low_cutoff_freq, // Hz center of transition band
137 double high_cutoff_freq, // Hz center of transition band
138 double transition_width, // Hz width of transition band
139 win_type window = WIN_HAMMING,
140 double beta = 6.76); // used only with Kaiser
144 * \brief use "window method" to design a band-reject FIR filter
146 * \p gain: overall gain of filter (typically 1.0)
147 * \p sampling_freq: sampling freq (Hz)
148 * \p low_cutoff_freq: center of transition band (Hz)
149 * \p high_cutoff_freq: center of transition band (Hz)
150 * \p transition_width: width of transition band (Hz).
151 * The normalized width of the transition
152 * band is what sets the number of taps
153 * required. Narrow --> more taps
154 * \p window_type: What kind of window to use. Determines
155 * maximum attenuation and passband ripple.
156 * \p beta: parameter for Kaiser window
159 static std::vector<float>
160 band_reject (double gain,
161 double sampling_freq,
162 double low_cutoff_freq, // Hz center of transition band
163 double high_cutoff_freq, // Hz center of transition band
164 double transition_width, // Hz width of transition band
165 win_type window = WIN_HAMMING,
166 double beta = 6.76); // used only with Kaiser
168 /*!\brief design a Hilbert Transform Filter
170 * \p ntaps: Number of taps, must be odd
171 * \p window_type: What kind of window to use
172 * \p beta: Only used for Kaiser
174 static std::vector<float>
175 hilbert (unsigned int ntaps,
176 win_type windowtype = WIN_RECTANGULAR,
180 * \brief design a Root Cosine FIR Filter (do we need a window?)
182 * \p gain: overall gain of filter (typically 1.0)
183 * \p sampling_freq: sampling freq (Hz)
184 * \p symbol rate: symbol rate, must be a factor of sample rate
185 * \p alpha: excess bandwidth factor
186 * \p ntaps: number of taps
188 static std::vector<float>
189 root_raised_cosine (double gain,
190 double sampling_freq,
191 double symbol_rate, // Symbol rate, NOT bitrate (unless BPSK)
192 double alpha, // Excess Bandwidth Factor
196 * \brief design a Gaussian filter
198 * \p gain: overall gain of filter (typically 1.0)
199 * \p symbols per bit: symbol rate, must be a factor of sample rate
200 * \p ntaps: number of taps
202 static std::vector<float>
203 gaussian (double gain,
205 double bt, // Bandwidth to bitrate ratio
208 // window functions ...
209 static std::vector<float> window (win_type type, int ntaps, double beta);
212 static double bessi0(double x);
213 static void sanity_check_1f (double sampling_freq, double f1,
214 double transition_width);
215 static void sanity_check_2f (double sampling_freq, double f1, double f2,
216 double transition_width);
217 static void sanity_check_2f_c (double sampling_freq, double f1, double f2,
218 double transition_width);
220 static int compute_ntaps (double sampling_freq,
221 double transition_width,
222 win_type window_type, double beta);