dsplib 1.1.0
C++ DSP library for MATLAB-like coding
Loading...
Searching...
No Matches
fir.h
1#pragma once
2
3#include <dsplib/array.h>
4#include <dsplib/keywords.h>
5#include <dsplib/math.h>
6#include <dsplib/fft.h>
7#include <dsplib/ifft.h>
8
9namespace dsplib {
10
15template<typename T>
17{
18public:
19 explicit FirFilter(span_t<T> h)
20 : _h(h)
21 , _d(h.size() - 1) {
22 }
23
24 base_array<T> process(span_t<T> x) {
25 base_array<T> r(x);
26 this->process(inplace(r));
27 return r;
28 }
29
30 void process(inplace_span_t<T> si) {
31 auto s = si.get();
32 auto x = concatenate(_d, s);
33 FirFilter::conv(x, _h);
34 s.assign(x.slice(0, s.size()));
35 const int nd = _d.size();
36 const int nx = x.size();
37 _d.slice(0, nd) = x.slice((nx - nd), nx);
38 }
39
40 //current impulse response
41 [[nodiscard]] span_t<T> coeffs() const {
42 return make_span(_h);
43 }
44
45 mut_span_t<T> coeffs() {
46 return make_span(_h);
47 }
48
49 base_array<T> operator()(span_t<T> x) {
50 return this->process(x);
51 }
52
53private:
54 static void conv(mut_span_t<T> x, span_t<T> h);
55
56 base_array<T> _h;
57 base_array<T> _d;
58};
59
62
63template<typename U>
65
66template<typename T>
68
73template<typename T>
75{
76public:
77 explicit FftFilter(span_t<T> h);
78
79 base_array<T> process(span_t<T> x);
80
81 base_array<T> operator()(span_t<T> x) {
82 return this->process(x);
83 }
84
85 [[nodiscard]] int block_size() const;
86
87private:
88 std::shared_ptr<FftFilterImpl<T>> d_;
89};
90
93
94template<typename U>
96
97//Type of linear phase FIR filter
98FirType firtype(span_real h);
99
100//Window-based FIR filter design (low or high)
101//n - filter order
102//wn - frequency constraints (0, 1)
103//ftype - fir type
104//win - custom window (must be n+1 or n+1+rem(n,2) for high/stop)
105arr_real fir1(int n, real_t wn, FilterType ftype = FilterType::Low);
106arr_real fir1(int n, real_t wn, FilterType ftype, const arr_real& win);
107
108//Window-based FIR filter design (bandpass or stop)
109arr_real fir1(int n, real_t wn1, real_t wn2, FilterType ftype = FilterType::Bandpass);
110arr_real fir1(int n, real_t wn1, real_t wn2, FilterType ftype, const arr_real& win);
111
112} // namespace dsplib
Definition fir.h:67
FFT-based FIR filtering using overlap-add method.
Definition fir.h:75
FIR filter class.
Definition fir.h:17
base dsplib array type
Definition array.h:25
Definition span.h:465
Definition span.h:27
Definition span.h:295