SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
fftfilt.h
Go to the documentation of this file.
1 /*
2  * Filters from Fldigi.
3 */
4 
5 #ifndef _FFTFILT_H
6 #define _FFTFILT_H
7 
8 #include <complex>
9 #include "gfft.h"
10 #include "export.h"
11 
12 #undef M_PI
13 #define M_PI 3.14159265358979323846
14 
15 //----------------------------------------------------------------------
16 
18 enum {NONE, BLACKMAN, HAMMING, HANNING};
19 
20 public:
21  typedef std::complex<float> cmplx;
22 
23  fftfilt(float f1, float f2, int len);
24  fftfilt(float f2, int len);
25  ~fftfilt();
26 // f1 < f2 ==> bandpass
27 // f1 > f2 ==> band reject
28  void create_filter(float f1, float f2);
29  void create_dsb_filter(float f2);
30  void create_asym_filter(float fopp, float fin);
31  void create_rrc_filter(float fb, float a);
32 
33  int noFilt(const cmplx& in, cmplx **out);
34  int runFilt(const cmplx& in, cmplx **out);
35  int runSSB(const cmplx& in, cmplx **out, bool usb, bool getDC = true);
36  int runDSB(const cmplx& in, cmplx **out, bool getDC = true);
37  int runAsym(const cmplx & in, cmplx **out, bool usb);
38 
39 protected:
40  int flen;
41  int flen2;
43  cmplx *filter;
44  cmplx *filterOpp;
45  cmplx *data;
46  cmplx *ovlbuf;
47  cmplx *output;
48  int inptr;
49  int pass;
50  int window;
51 
52  inline float fsinc(float fc, int i, int len)
53  {
54  int len2 = len/2;
55  return (i == len2) ? 2.0 * fc:
56  sin(2 * M_PI * fc * (i - len2)) / (M_PI * (i - len2));
57  }
58 
59  inline float _blackman(int i, int len)
60  {
61  return (0.42 -
62  0.50 * cos(2.0 * M_PI * i / len) +
63  0.08 * cos(4.0 * M_PI * i / len));
64  }
65 
68  inline cmplx frrc(float fb, float a, int i, int len)
69  {
70  float x = i/(float)len; // normalize to [0..1]
71  x = 0.5-fabs(x-0.5); // apply symmetry: now both halves overlap near 0
72  float tr = fb*a; // half the transition zone
73 
74  if (x < fb-tr)
75  {
76  return 1.0; // in band
77  }
78  else if (x < fb+tr) // transition
79  {
80  float y = ((x-(fb-tr)) / (2.0*tr))*M_PI;
81  return (cos(y) + 1.0f)/2.0f;
82  }
83  else
84  {
85  return 0.0; // out of band
86  }
87  }
88 
89  void init_filter();
90  void init_dsb_filter();
91 };
92 
93 
94 
95 /* Sliding FFT filter from Fldigi */
97 #define K1 0.99999
98 public:
99  typedef std::complex<float> cmplx;
100  sfft(int len);
101  ~sfft();
102  void run(const cmplx& input);
103  void fetch(float *result);
104 private:
105  int fftlen;
106  int first;
107  int last;
108  int ptr;
111  cmplx *delay;
112  float k2;
113 };
114 
115 #endif
int last
Definition: fftfilt.h:107
int pass
Definition: fftfilt.h:49
int first
Definition: fftfilt.h:106
int flen
Definition: fftfilt.h:40
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
vrot_bins_pair * vrot_bins
Definition: fftfilt.h:109
cmplx * ovlbuf
Definition: fftfilt.h:46
cmplx frrc(float fb, float a, int i, int len)
Definition: fftfilt.h:68
int fftlen
Definition: fftfilt.h:105
Definition: fftfilt.h:96
float _blackman(int i, int len)
Definition: fftfilt.h:59
float fsinc(float fc, int i, int len)
Definition: fftfilt.h:52
std::complex< float > cmplx
Definition: fftfilt.h:21
cmplx * delay
Definition: fftfilt.h:111
#define M_PI
Definition: fftfilt.h:13
int ptr
Definition: fftfilt.h:108
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2265
cmplx * filterOpp
Definition: fftfilt.h:44
int32_t i
Definition: decimators.h:244
cmplx * filter
Definition: fftfilt.h:43
int flen2
Definition: fftfilt.h:41
g_fft< float > * fft
Definition: fftfilt.h:42
float k2
Definition: fftfilt.h:112
cmplx * output
Definition: fftfilt.h:47
cmplx * data
Definition: fftfilt.h:45
std::complex< float > cmplx
Definition: fftfilt.h:99
int inptr
Definition: fftfilt.h:48
#define SDRBASE_API
Definition: export.h:40
int window
Definition: fftfilt.h:50