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