-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPolyPhaseFilterBank.hpp
87 lines (66 loc) · 2.47 KB
/
PolyPhaseFilterBank.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Author: David Mittiga [email protected]
* Published on Github by Alex Ranaldi [email protected]
* License: MIT
*/
#ifndef POLYPHASEFILTERBANK
# define POLYPHASEFILTERBANK
#include "FFT_R2.hpp"
#include <complex>
namespace pd {
// An efficient implementation of a poly-phase filter bank
// - Uses a power-of-two based sinc filters (many coeffs are 0).
// - Uses a sample buffer to aid in processing consecutive samples (can be
// cleared if consecutive calls contain data that is not contiguous).
// - The output samples are delayed by FiltOrd/(NumChan*2)-1 samples.
// - Note that the output sample rate is 1/NumChan of the input rate.
// - Filter bandwidth scaling can be used for filter overlap
class PolyPhaseFilterBank {
public:
// Constructor
PolyPhaseFilterBank(
size_t NumChan_log2,
size_t FiltOrd_log2,
double FiltScale = 1.0);
// Destructor
~PolyPhaseFilterBank(void);
// Consumes the next NumChan samples from the provided pointer and
// generates the NumChan outputs (delayed and unnormalized).
// In and out pointers can be identical (in-place operation).
void Iterate(
std::complex<double> *in,
std::complex<double> *out);
// Resets the internal buffers to zero, losing history
void ResetBuffer(void);
// Returns a scalar which should be multiplied by the output as:
// output/sqrt(GetNorm())
// It is not multiplied internally for computational savings
inline double GetNorm(void) const {return norm;}
// Returns the fractional bandwidth (1/gain) of the filters
inline double GetBandwidth(void) const {return Scale/NumChan;}
// Returns the output delay of this filter (at the output rate)
inline size_t GetDelay(void) const {return FiltOrd/NumChan/2-1;}
// Returns the number of channels
inline size_t GetNumChan(void) const {return NumChan;}
private:
// The number of channels
const size_t NumChan;
// The low-pass filter order
const size_t FiltOrd;
// Scalar for filter bandwidth
const double Scale;
// The normalization scalar
double norm;
// The weighted low-pass filter
double *filter;
// Buffer for samples
std::complex<double> *samples;
// Index to place next sample
size_t next;
// The FFT object
FFT_R2 fft;
// FFT workspace
std::complex<double> *workspace;
}; // class PolyPhaseFilterBank
} // namespace pd
#endif // POLYPHASEFILTERBANK