GNU Radio 3.4.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2002,2008 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef _GR_FIRDES_H_ 00024 #define _GR_FIRDES_H_ 00025 00026 #include <vector> 00027 #include <cmath> 00028 #include <gr_complex.h> 00029 00030 /*! 00031 * \brief Finite Impulse Response (FIR) filter design functions. 00032 * \ingroup filter_design 00033 */ 00034 00035 class gr_firdes { 00036 public: 00037 00038 enum win_type { 00039 WIN_HAMMING = 0, // max attenuation 53 dB 00040 WIN_HANN = 1, // max attenuation 44 dB 00041 WIN_BLACKMAN = 2, // max attenuation 74 dB 00042 WIN_RECTANGULAR = 3, 00043 WIN_KAISER = 4, // max attenuation a function of beta, google it 00044 WIN_BLACKMAN_hARRIS = 5, 00045 }; 00046 00047 00048 // ... class methods ... 00049 00050 /*! 00051 * \brief use "window method" to design a low-pass FIR filter 00052 * 00053 * \p gain: overall gain of filter (typically 1.0) 00054 * \p sampling_freq: sampling freq (Hz) 00055 * \p cutoff_freq: center of transition band (Hz) 00056 * \p transition_width: width of transition band (Hz). 00057 * The normalized width of the transition 00058 * band is what sets the number of taps 00059 * required. Narrow --> more taps 00060 * \p window_type: What kind of window to use. Determines 00061 * maximum attenuation and passband ripple. 00062 * \p beta: parameter for Kaiser window 00063 */ 00064 static std::vector<float> 00065 low_pass (double gain, 00066 double sampling_freq, 00067 double cutoff_freq, // Hz center of transition band 00068 double transition_width, // Hz width of transition band 00069 win_type window = WIN_HAMMING, 00070 double beta = 6.76); // used only with Kaiser 00071 00072 /*! 00073 * \brief use "window method" to design a low-pass FIR filter 00074 * 00075 * \p gain: overall gain of filter (typically 1.0) 00076 * \p sampling_freq: sampling freq (Hz) 00077 * \p cutoff_freq: center of transition band (Hz) 00078 * \p transition_width: width of transition band (Hz). 00079 * \p attenuation_dB required stopband attenuation 00080 * The normalized width of the transition 00081 * band and the required stop band 00082 * attenuation is what sets the number of taps 00083 * required. Narrow --> more taps 00084 * More attenuatin --> more taps 00085 * \p window_type: What kind of window to use. Determines 00086 * maximum attenuation and passband ripple. 00087 * \p beta: parameter for Kaiser window 00088 */ 00089 00090 static std::vector<float> 00091 low_pass_2 (double gain, 00092 double sampling_freq, 00093 double cutoff_freq, // Hz beginning transition band 00094 double transition_width, // Hz width of transition band 00095 double attenuation_dB, // out of band attenuation dB 00096 win_type window = WIN_HAMMING, 00097 double beta = 6.76); // used only with Kaiser 00098 00099 /*! 00100 * \brief use "window method" to design a high-pass FIR filter 00101 * 00102 * \p gain: overall gain of filter (typically 1.0) 00103 * \p sampling_freq: sampling freq (Hz) 00104 * \p cutoff_freq: center of transition band (Hz) 00105 * \p transition_width: width of transition band (Hz). 00106 * The normalized width of the transition 00107 * band is what sets the number of taps 00108 * required. Narrow --> more taps 00109 * \p window_type: What kind of window to use. Determines 00110 * maximum attenuation and passband ripple. 00111 * \p beta: parameter for Kaiser window 00112 */ 00113 00114 static std::vector<float> 00115 high_pass (double gain, 00116 double sampling_freq, 00117 double cutoff_freq, // Hz center of transition band 00118 double transition_width, // Hz width of transition band 00119 win_type window = WIN_HAMMING, 00120 double beta = 6.76); // used only with Kaiser 00121 00122 /*! 00123 * \brief use "window method" to design a high-pass FIR filter 00124 * 00125 * \p gain: overall gain of filter (typically 1.0) 00126 * \p sampling_freq: sampling freq (Hz) 00127 * \p cutoff_freq: center of transition band (Hz) 00128 * \p transition_width: width of transition band (Hz). 00129 * \p attenuation_dB out of band attenuation 00130 * The normalized width of the transition 00131 * band and the required stop band 00132 * attenuation is what sets the number of taps 00133 * required. Narrow --> more taps 00134 * More attenuation --> more taps 00135 * \p window_type: What kind of window to use. Determines 00136 * maximum attenuation and passband ripple. 00137 * \p beta: parameter for Kaiser window 00138 */ 00139 00140 static std::vector<float> 00141 high_pass_2 (double gain, 00142 double sampling_freq, 00143 double cutoff_freq, // Hz center of transition band 00144 double transition_width, // Hz width of transition band 00145 double attenuation_dB, // out of band attenuation dB 00146 win_type window = WIN_HAMMING, 00147 double beta = 6.76); // used only with Kaiser 00148 00149 /*! 00150 * \brief use "window method" to design a band-pass FIR filter 00151 * 00152 * \p gain: overall gain of filter (typically 1.0) 00153 * \p sampling_freq: sampling freq (Hz) 00154 * \p low_cutoff_freq: center of transition band (Hz) 00155 * \p high_cutoff_freq: center of transition band (Hz) 00156 * \p transition_width: width of transition band (Hz). 00157 * The normalized width of the transition 00158 * band is what sets the number of taps 00159 * required. Narrow --> more taps 00160 * \p window_type: What kind of window to use. Determines 00161 * maximum attenuation and passband ripple. 00162 * \p beta: parameter for Kaiser window 00163 */ 00164 static std::vector<float> 00165 band_pass (double gain, 00166 double sampling_freq, 00167 double low_cutoff_freq, // Hz center of transition band 00168 double high_cutoff_freq, // Hz center of transition band 00169 double transition_width, // Hz width of transition band 00170 win_type window = WIN_HAMMING, 00171 double beta = 6.76); // used only with Kaiser 00172 00173 /*! 00174 * \brief use "window method" to design a band-pass FIR filter 00175 * 00176 * \p gain: overall gain of filter (typically 1.0) 00177 * \p sampling_freq: sampling freq (Hz) 00178 * \p low_cutoff_freq: center of transition band (Hz) 00179 * \p high_cutoff_freq: center of transition band (Hz) 00180 * \p transition_width: width of transition band (Hz). 00181 * \p attenuation_dB out of band attenuation 00182 * The normalized width of the transition 00183 * band and the required stop band 00184 * attenuation is what sets the number of taps 00185 * required. Narrow --> more taps 00186 * More attenuation --> more taps 00187 * \p window_type: What kind of window to use. Determines 00188 * maximum attenuation and passband ripple. 00189 * \p beta: parameter for Kaiser window 00190 */ 00191 00192 static std::vector<float> 00193 band_pass_2 (double gain, 00194 double sampling_freq, 00195 double low_cutoff_freq, // Hz beginning transition band 00196 double high_cutoff_freq, // Hz beginning transition band 00197 double transition_width, // Hz width of transition band 00198 double attenuation_dB, // out of band attenuation dB 00199 win_type window = WIN_HAMMING, 00200 double beta = 6.76); // used only with Kaiser 00201 00202 /*! 00203 * \brief use "window method" to design a complex band-pass FIR filter 00204 * 00205 * \p gain: overall gain of filter (typically 1.0) 00206 * \p sampling_freq: sampling freq (Hz) 00207 * \p low_cutoff_freq: center of transition band (Hz) 00208 * \p high_cutoff_freq: center of transition band (Hz) 00209 * \p transition_width: width of transition band (Hz). 00210 * The normalized width of the transition 00211 * band is what sets the number of taps 00212 * required. Narrow --> more taps 00213 * \p window_type: What kind of window to use. Determines 00214 * maximum attenuation and passband ripple. 00215 * \p beta: parameter for Kaiser window 00216 */ 00217 00218 static std::vector<gr_complex> 00219 complex_band_pass (double gain, 00220 double sampling_freq, 00221 double low_cutoff_freq, // Hz center of transition band 00222 double high_cutoff_freq, // Hz center of transition band 00223 double transition_width, // Hz width of transition band 00224 win_type window = WIN_HAMMING, 00225 double beta = 6.76); // used only with Kaiser 00226 00227 /*! 00228 * \brief use "window method" to design a complex band-pass FIR filter 00229 * 00230 * \p gain: overall gain of filter (typically 1.0) 00231 * \p sampling_freq: sampling freq (Hz) 00232 * \p low_cutoff_freq: center of transition band (Hz) 00233 * \p high_cutoff_freq: center of transition band (Hz) 00234 * \p transition_width: width of transition band (Hz). 00235 * \p attenuation_dB out of band attenuation 00236 * The normalized width of the transition 00237 * band and the required stop band 00238 * attenuation is what sets the number of taps 00239 * required. Narrow --> more taps 00240 * More attenuation --> more taps 00241 * \p window_type: What kind of window to use. Determines 00242 * maximum attenuation and passband ripple. 00243 * \p beta: parameter for Kaiser window 00244 */ 00245 00246 static std::vector<gr_complex> 00247 complex_band_pass_2 (double gain, 00248 double sampling_freq, 00249 double low_cutoff_freq, // Hz beginning transition band 00250 double high_cutoff_freq, // Hz beginning transition band 00251 double transition_width, // Hz width of transition band 00252 double attenuation_dB, // out of band attenuation dB 00253 win_type window = WIN_HAMMING, 00254 double beta = 6.76); // used only with Kaiser 00255 00256 /*! 00257 * \brief use "window method" to design a band-reject FIR filter 00258 * 00259 * \p gain: overall gain of filter (typically 1.0) 00260 * \p sampling_freq: sampling freq (Hz) 00261 * \p low_cutoff_freq: center of transition band (Hz) 00262 * \p high_cutoff_freq: center of transition band (Hz) 00263 * \p transition_width: width of transition band (Hz). 00264 * The normalized width of the transition 00265 * band is what sets the number of taps 00266 * required. Narrow --> more taps 00267 * \p window_type: What kind of window to use. Determines 00268 * maximum attenuation and passband ripple. 00269 * \p beta: parameter for Kaiser window 00270 */ 00271 00272 static std::vector<float> 00273 band_reject (double gain, 00274 double sampling_freq, 00275 double low_cutoff_freq, // Hz center of transition band 00276 double high_cutoff_freq, // Hz center of transition band 00277 double transition_width, // Hz width of transition band 00278 win_type window = WIN_HAMMING, 00279 double beta = 6.76); // used only with Kaiser 00280 00281 /*! 00282 * \brief use "window method" to design a band-reject FIR filter 00283 * 00284 * \p gain: overall gain of filter (typically 1.0) 00285 * \p sampling_freq: sampling freq (Hz) 00286 * \p low_cutoff_freq: center of transition band (Hz) 00287 * \p high_cutoff_freq: center of transition band (Hz) 00288 * \p transition_width: width of transition band (Hz). 00289 * \p attenuation_dB out of band attenuation 00290 * The normalized width of the transition 00291 * band and the required stop band 00292 * attenuation is what sets the number of taps 00293 * required. Narrow --> more taps 00294 * More attenuation --> more taps 00295 * \p window_type: What kind of window to use. Determines 00296 * maximum attenuation and passband ripple. 00297 * \p beta: parameter for Kaiser window 00298 */ 00299 00300 static std::vector<float> 00301 band_reject_2 (double gain, 00302 double sampling_freq, 00303 double low_cutoff_freq, // Hz beginning transition band 00304 double high_cutoff_freq, // Hz beginning transition band 00305 double transition_width, // Hz width of transition band 00306 double attenuation_dB, // out of band attenuation dB 00307 win_type window = WIN_HAMMING, 00308 double beta = 6.76); // used only with Kaiser 00309 00310 /*!\brief design a Hilbert Transform Filter 00311 * 00312 * \p ntaps: Number of taps, must be odd 00313 * \p window_type: What kind of window to use 00314 * \p beta: Only used for Kaiser 00315 */ 00316 static std::vector<float> 00317 hilbert (unsigned int ntaps = 19, 00318 win_type windowtype = WIN_RECTANGULAR, 00319 double beta = 6.76); 00320 00321 /*! 00322 * \brief design a Root Cosine FIR Filter (do we need a window?) 00323 * 00324 * \p gain: overall gain of filter (typically 1.0) 00325 * \p sampling_freq: sampling freq (Hz) 00326 * \p symbol rate: symbol rate, must be a factor of sample rate 00327 * \p alpha: excess bandwidth factor 00328 * \p ntaps: number of taps 00329 */ 00330 static std::vector<float> 00331 root_raised_cosine (double gain, 00332 double sampling_freq, 00333 double symbol_rate, // Symbol rate, NOT bitrate (unless BPSK) 00334 double alpha, // Excess Bandwidth Factor 00335 int ntaps); 00336 00337 /*! 00338 * \brief design a Gaussian filter 00339 * 00340 * \p gain: overall gain of filter (typically 1.0) 00341 * \p symbols per bit: symbol rate, must be a factor of sample rate 00342 * \p ntaps: number of taps 00343 */ 00344 static std::vector<float> 00345 gaussian (double gain, 00346 double spb, 00347 double bt, // Bandwidth to bitrate ratio 00348 int ntaps); 00349 00350 // window functions ... 00351 static std::vector<float> window (win_type type, int ntaps, double beta); 00352 00353 private: 00354 static double bessi0(double x); 00355 static void sanity_check_1f (double sampling_freq, double f1, 00356 double transition_width); 00357 static void sanity_check_2f (double sampling_freq, double f1, double f2, 00358 double transition_width); 00359 static void sanity_check_2f_c (double sampling_freq, double f1, double f2, 00360 double transition_width); 00361 00362 static int compute_ntaps (double sampling_freq, 00363 double transition_width, 00364 win_type window_type, double beta); 00365 00366 static int compute_ntaps_windes (double sampling_freq, 00367 double transition_width, 00368 double attenuation_dB); 00369 }; 00370 00371 #endif