1 // ---------------------------------------------------------------------------- 2 // Copyright (C) 2014 3 // David Freese, W1HKJ 4 // 5 // This file is part of fldigi 6 // 7 // fldigi 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 of the License, or 10 // (at your option) any later version. 11 // 12 // fldigi 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 this program. If not, see <http://www.gnu.org/licenses/>. 19 // ---------------------------------------------------------------------------- 20 21 #ifndef _FFTFILT_H 22 #define _FFTFILT_H 23 24 #include "complex.h" 25 #include "gfft.h" 26 27 //---------------------------------------------------------------------- 28 29 class fftfilt { 30 enum {NONE, BLACKMAN, HAMMING, HANNING}; 31 32 protected: 33 int flen; 34 int flen2; 35 g_fft<double> *fft; 36 g_fft<double> *ift; 37 cmplx *ht; 38 cmplx *filter; 39 cmplx *timedata; 40 cmplx *freqdata; 41 cmplx *ovlbuf; 42 cmplx *output; 43 int inptr; 44 int pass; 45 int window; 46 fsinc(double fc,int i,int len)47 inline double fsinc(double fc, int i, int len) { 48 return (i == len/2) ? 2.0 * fc: 49 sin(2 * M_PI * fc * (i - len/2)) / (M_PI * (i - len/2)); 50 } _blackman(int i,int len)51 inline double _blackman(int i, int len) { 52 return (0.42 - 53 0.50 * cos(2.0 * M_PI * i / len) + 54 0.08 * cos(4.0 * M_PI * i / len)); 55 } 56 void init_filter(); 57 void clear_filter(); 58 59 public: 60 fftfilt(double f1, double f2, int len); 61 fftfilt(double f, int len); 62 ~fftfilt(); 63 // f1 < f2 ==> bandpass 64 // f1 > f2 ==> band reject 65 void create_filter(double f1, double f2); create_lpf(double f)66 void create_lpf(double f) { 67 create_filter(0, f); 68 } create_hpf(double f)69 void create_hpf(double f) { 70 create_filter(f, 0); 71 } 72 void rtty_filter(double); 73 74 int run(const cmplx& in, cmplx **out); 75 int flush_size(); 76 }; 77 78 #endif 79