| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00:00
										 |  |  |  * Filters from Fldigi.  | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef	_FFTFILT_H
 | 
					
						
							|  |  |  | #define	_FFTFILT_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | #include <complex>
 | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | #include "gfft.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class fftfilt { | 
					
						
							|  |  |  | enum {NONE, BLACKMAN, HAMMING, HANNING}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | public: | 
					
						
							|  |  |  | 	typedef std::complex<float> cmplx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fftfilt(float f1, float f2, int len); | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 	fftfilt(float f2, int len); | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | 	~fftfilt(); | 
					
						
							|  |  |  | // f1 < f2 ==> bandpass
 | 
					
						
							|  |  |  | // f1 > f2 ==> band reject
 | 
					
						
							|  |  |  | 	void create_filter(float f1, float f2); | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 	void create_dsb_filter(float f2); | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 	int noFilt(const cmplx& in, cmplx **out); | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | 	int runFilt(const cmplx& in, cmplx **out); | 
					
						
							|  |  |  | 	int runSSB(const cmplx& in, cmplx **out, bool usb); | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 	int runDSB(const cmplx& in, cmplx **out); | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	int flen; | 
					
						
							|  |  |  | 	int flen2; | 
					
						
							|  |  |  | 	g_fft<float> *fft; | 
					
						
							|  |  |  | 	g_fft<float> *ift; | 
					
						
							|  |  |  | 	cmplx *filter; | 
					
						
							| 
									
										
										
										
											2014-12-25 21:24:03 +00:00
										 |  |  | 	cmplx *data; | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | 	cmplx *ovlbuf; | 
					
						
							|  |  |  | 	cmplx *output; | 
					
						
							|  |  |  | 	int inptr; | 
					
						
							|  |  |  | 	int pass; | 
					
						
							|  |  |  | 	int window; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	inline float fsinc(float fc, int i, int len) { | 
					
						
							|  |  |  | 		return (i == len/2) ? 2.0 * fc:  | 
					
						
							|  |  |  | 				sin(2 * M_PI * fc * (i - len/2)) / (M_PI * (i - len/2)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | 	inline float _blackman(int i, int len) { | 
					
						
							|  |  |  | 		return (0.42 -  | 
					
						
							|  |  |  | 				 0.50 * cos(2.0 * M_PI * i / len) +  | 
					
						
							|  |  |  | 				 0.08 * cos(4.0 * M_PI * i / len)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | 	void init_filter(); | 
					
						
							| 
									
										
										
										
											2015-06-21 12:46:47 +02:00
										 |  |  | 	void init_dsb_filter(); | 
					
						
							| 
									
										
										
										
											2014-06-27 17:36:13 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Sliding FFT filter from Fldigi */ | 
					
						
							|  |  |  | class sfft { | 
					
						
							|  |  |  | #define K1 0.99999
 | 
					
						
							| 
									
										
										
										
											2015-05-15 11:29:41 +02:00
										 |  |  | public: | 
					
						
							|  |  |  | 	typedef std::complex<float> cmplx; | 
					
						
							|  |  |  | 	sfft(int len); | 
					
						
							|  |  |  | 	~sfft(); | 
					
						
							|  |  |  | 	void run(const cmplx& input); | 
					
						
							|  |  |  | 	void fetch(float *result); | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00: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 17:36:13 +01:00
										 |  |  | #endif
 |