3.6.3. filters.hpp#

3.6.3.1. Source code#

 1// University of Florida EEL6528
 2// Tan F. Wong
 3// Feb 2, 2021
 4
 5#pragma once
 6
 7#include "fft.hpp"
 8
 9// Overlap-save filter class
10class FilterOverlapSave {
11  public:
12    FilterOverlapSave(int x_len, int h_len, std::complex<float>* h, int nt=1); // single-rate constructor
13    FilterOverlapSave(int up, int down, int x_len, int h_len, std::complex<float>* h, int nt=1); // multi-rate constructor
14    ~FilterOverlapSave(void); // destructor
15    int filter(std::complex<float>* in, std::complex<float>* out);  //do filtering
16    void set_head(bool reset=false); // Set head of input array for continuously filtering
17    int out_len(void); //calculate output length
18
19  private:
20    void setup(int x_len, int h_len, std::complex<float>* h, int nt); // utility method to set up FFTs
21    int fftsize;
22    fft* fwdfft; // forward FFT 
23    fft* invfft; // inverse FFT
24    int U; // upsampling factor
25    int D; // downsampling factor
26    int L; // length of filter impulse response
27    int M; // length of valid sample block
28    int nblocks; // number of blocks to calculate
29    int nthreads; // number of threads to use in FFT calculation
30    int nx; // length of input sequence
31    int Unx; // length of input sequence after interpolation
32    std::complex<float>* H; // FFT of impulse response
33};
34
35// Polyphase filter class
36class FilterPolyphase {
37  public:
38    FilterPolyphase(int up, int down, int x_len, int h_len, std::complex<float>* h, int nt); // constructor
39    ~FilterPolyphase(void); // destructor
40    int filter(std::complex<float>* in, std::complex<float>* out);  // do filtering
41    void set_head(bool reset=false); // Set head of input array for continuously filtering
42    int out_len(void); //calculate output length
43
44  private:
45    int fftsize;
46    fft* fwdfft; // forward FFT 
47    fft* invfft; // inverse FFT
48    int U; // upsampling factor
49    int D; // downsampling factor
50    int L; // length of filter impulse response
51    int Lp; // length of polyphase filter impulse responses
52    int M; // length of valid sample block
53    int nblocks; // number of blocks to calculate on each down-sampled input signal (row)
54    int nthreads; // number of threads to use in FFT calculation
55    int nx; // length of input sequence
56    int nxD; // length of down-sampled signals
57    std::complex<float>* F; // FFTs of impulse responses of polyphase filters
58};