2014-06-27 12:36:13 -04:00
|
|
|
/*
|
2017-03-15 21:45:51 -04:00
|
|
|
* Filters from Fldigi.
|
2014-06-27 12:36:13 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FFTFILT_H
|
|
|
|
#define _FFTFILT_H
|
|
|
|
|
2015-05-15 05:29:41 -04:00
|
|
|
#include <complex>
|
2020-11-03 07:52:12 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
2014-06-27 12:36:13 -04:00
|
|
|
#include "gfft.h"
|
2018-03-20 08:49:21 -04:00
|
|
|
#include "export.h"
|
2014-06-27 12:36:13 -04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2018-03-03 14:23:38 -05:00
|
|
|
class SDRBASE_API fftfilt {
|
2014-06-27 12:36:13 -04:00
|
|
|
enum {NONE, BLACKMAN, HAMMING, HANNING};
|
|
|
|
|
2015-05-15 05:29:41 -04:00
|
|
|
public:
|
|
|
|
typedef std::complex<float> cmplx;
|
|
|
|
|
|
|
|
fftfilt(float f1, float f2, int len);
|
2015-06-21 06:46:47 -04:00
|
|
|
fftfilt(float f2, int len);
|
2015-05-15 05:29:41 -04:00
|
|
|
~fftfilt();
|
|
|
|
// f1 < f2 ==> bandpass
|
|
|
|
// f1 > f2 ==> band reject
|
|
|
|
void create_filter(float f1, float f2);
|
2015-06-21 06:46:47 -04:00
|
|
|
void create_dsb_filter(float f2);
|
2017-03-16 05:11:03 -04:00
|
|
|
void create_asym_filter(float fopp, float fin); //!< two different filters for in band and opposite band
|
2018-05-21 18:10:56 -04:00
|
|
|
void create_rrc_filter(float fb, float a); //!< root raised cosine. fb is half the band pass
|
2015-05-15 05:29:41 -04:00
|
|
|
|
2015-06-21 06:46:47 -04:00
|
|
|
int noFilt(const cmplx& in, cmplx **out);
|
2015-05-15 05:29:41 -04:00
|
|
|
int runFilt(const cmplx& in, cmplx **out);
|
2017-03-15 10:37:51 -04:00
|
|
|
int runSSB(const cmplx& in, cmplx **out, bool usb, bool getDC = true);
|
2018-05-13 11:27:24 -04:00
|
|
|
int runDSB(const cmplx& in, cmplx **out, bool getDC = true);
|
2017-03-16 05:11:03 -04:00
|
|
|
int runAsym(const cmplx & in, cmplx **out, bool usb); //!< Asymmetrical fitering can be used for vestigial sideband
|
2015-05-15 05:29:41 -04:00
|
|
|
|
2014-06-27 12:36:13 -04:00
|
|
|
protected:
|
|
|
|
int flen;
|
|
|
|
int flen2;
|
|
|
|
g_fft<float> *fft;
|
|
|
|
cmplx *filter;
|
2017-03-16 05:11:03 -04:00
|
|
|
cmplx *filterOpp;
|
2014-12-25 16:24:03 -05:00
|
|
|
cmplx *data;
|
2014-06-27 12:36:13 -04:00
|
|
|
cmplx *ovlbuf;
|
|
|
|
cmplx *output;
|
|
|
|
int inptr;
|
|
|
|
int pass;
|
|
|
|
int window;
|
|
|
|
|
2018-05-21 18:10:56 -04:00
|
|
|
inline float fsinc(float fc, int i, int len)
|
|
|
|
{
|
2018-02-24 04:29:27 -05:00
|
|
|
int len2 = len/2;
|
|
|
|
return (i == len2) ? 2.0 * fc:
|
|
|
|
sin(2 * M_PI * fc * (i - len2)) / (M_PI * (i - len2));
|
2014-06-27 12:36:13 -04:00
|
|
|
}
|
2015-06-21 06:46:47 -04:00
|
|
|
|
2018-05-21 18:10:56 -04:00
|
|
|
inline float _blackman(int i, int len)
|
|
|
|
{
|
2017-03-15 21:45:51 -04:00
|
|
|
return (0.42 -
|
|
|
|
0.50 * cos(2.0 * M_PI * i / len) +
|
2014-06-27 12:36:13 -04:00
|
|
|
0.08 * cos(4.0 * M_PI * i / len));
|
|
|
|
}
|
2015-06-21 06:46:47 -04:00
|
|
|
|
2018-05-21 18:10:56 -04:00
|
|
|
/** RRC function in the frequency domain. Zero frequency is on the sides with first half in positive frequencies
|
|
|
|
* and second half in negative frequencies */
|
|
|
|
inline cmplx frrc(float fb, float a, int i, int len)
|
|
|
|
{
|
|
|
|
float x = i/(float)len; // normalize to [0..1]
|
|
|
|
x = 0.5-fabs(x-0.5); // apply symmetry: now both halves overlap near 0
|
2018-05-21 20:20:36 -04:00
|
|
|
float tr = fb*a; // half the transition zone
|
2018-05-21 18:10:56 -04:00
|
|
|
|
|
|
|
if (x < fb-tr)
|
|
|
|
{
|
|
|
|
return 1.0; // in band
|
|
|
|
}
|
|
|
|
else if (x < fb+tr) // transition
|
|
|
|
{
|
|
|
|
float y = ((x-(fb-tr)) / (2.0*tr))*M_PI;
|
|
|
|
return (cos(y) + 1.0f)/2.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0.0; // out of band
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 12:36:13 -04:00
|
|
|
void init_filter();
|
2015-06-21 06:46:47 -04:00
|
|
|
void init_dsb_filter();
|
2014-06-27 12:36:13 -04:00
|
|
|
};
|
|
|
|
|
2015-01-11 14:30:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* Sliding FFT filter from Fldigi */
|
2018-03-03 14:23:38 -05:00
|
|
|
class SDRBASE_API sfft {
|
2015-01-11 14:30:48 -05:00
|
|
|
#define K1 0.99999
|
2015-05-15 05:29:41 -04:00
|
|
|
public:
|
|
|
|
typedef std::complex<float> cmplx;
|
|
|
|
sfft(int len);
|
|
|
|
~sfft();
|
|
|
|
void run(const cmplx& input);
|
|
|
|
void fetch(float *result);
|
2015-01-11 14:30:48 -05:00
|
|
|
private:
|
|
|
|
int fftlen;
|
|
|
|
int first;
|
|
|
|
int last;
|
|
|
|
int ptr;
|
|
|
|
struct vrot_bins_pair;
|
|
|
|
vrot_bins_pair *vrot_bins;
|
|
|
|
cmplx *delay;
|
|
|
|
float k2;
|
|
|
|
};
|
|
|
|
|
2014-06-27 12:36:13 -04:00
|
|
|
#endif
|