|
2 | 2 |
|
3 | 3 | #include <dsplib/array.h> |
4 | 4 | #include <dsplib/keywords.h> |
| 5 | +#include <dsplib/math.h> |
| 6 | +#include <dsplib/fft.h> |
| 7 | +#include <dsplib/ifft.h> |
5 | 8 |
|
6 | 9 | namespace dsplib { |
7 | 10 |
|
@@ -60,45 +63,37 @@ using FirFilterC = FirFilter<cmplx_t>; |
60 | 63 | template<typename U> |
61 | 64 | FirFilter(const base_array<U>&) -> FirFilter<U>; |
62 | 65 |
|
| 66 | +template<typename T> |
| 67 | +class FftFilterImpl; |
| 68 | + |
63 | 69 | /*! |
64 | 70 | * \brief FFT-based FIR filtering using overlap-add method |
65 | | - * \details Fast fir implementation for IR len > 200 |
66 | | - * \todo make template (real version is faster) |
| 71 | + * \details Fast fir implementation for large IR length (usually > 200) |
67 | 72 | */ |
| 73 | +template<typename T> |
68 | 74 | class FftFilter |
69 | 75 | { |
70 | 76 | public: |
71 | | - FftFilter() = default; |
72 | | - explicit FftFilter(span_real h); |
| 77 | + explicit FftFilter(span_t<T> h); |
73 | 78 |
|
74 | | - explicit FftFilter(span_cmplx h); |
75 | | - |
76 | | - //usually in.size() != out.size() |
77 | | - arr_real process(span_real x); |
78 | | - arr_cmplx process(span_cmplx x); |
79 | | - |
80 | | - //optimal input size for y[nx] = process(x[nx]) |
81 | | - [[nodiscard]] int block_size() const { |
82 | | - return _n; |
83 | | - } |
| 79 | + base_array<T> process(span_t<T> x); |
84 | 80 |
|
85 | | - arr_real operator()(span_real x) { |
| 81 | + base_array<T> operator()(span_t<T> x) { |
86 | 82 | return this->process(x); |
87 | 83 | } |
88 | 84 |
|
89 | | - arr_cmplx operator()(span_cmplx x) { |
90 | | - return this->process(x); |
91 | | - } |
| 85 | + [[nodiscard]] int block_size() const; |
92 | 86 |
|
93 | 87 | private: |
94 | | - arr_cmplx _x; |
95 | | - arr_cmplx _h; |
96 | | - arr_cmplx _olap; |
97 | | - int _nx{0}; |
98 | | - int _m{0}; |
99 | | - int _n{0}; |
| 88 | + std::shared_ptr<FftFilterImpl<T>> d_; |
100 | 89 | }; |
101 | 90 |
|
| 91 | +using FftFilterR = FftFilter<real_t>; |
| 92 | +using FftFilterC = FftFilter<cmplx_t>; |
| 93 | + |
| 94 | +template<typename U> |
| 95 | +FftFilter(const base_array<U>&) -> FftFilter<U>; |
| 96 | + |
102 | 97 | //Type of linear phase FIR filter |
103 | 98 | FirType firtype(span_real h); |
104 | 99 |
|
|
0 commit comments