1 /**
2 * KFR (http://kfrlib.com)
3 * Copyright (C) 2016 D Levin
4 * See LICENSE.txt for details
5 */
6
7 #include <kfr/base.hpp>
8 #include <kfr/dsp.hpp>
9 #include <kfr/io.hpp>
10
11 using namespace kfr;
12
main()13 int main()
14 {
15 println(library_version());
16
17 constexpr size_t maxorder = 32;
18
19 const std::string options = "phaseresp=True, log_freq=True, freq_dB_lim=(-160, 10), padwidth=8192";
20
21 univector<fbase, 1024> output;
22 {
23 zpk<fbase> filt = iir_lowpass(bessel<fbase>(24), 1000, 48000);
24 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
25 output = biquad<maxorder>(bqs, unitimpulse());
26 }
27 plot_save("bessel_lowpass24", output, options + ", title='24th-order Bessel filter, lowpass 1khz'");
28
29 {
30 zpk<fbase> filt = iir_lowpass(bessel<fbase>(12), 1000, 48000);
31 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
32 output = biquad<maxorder>(bqs, unitimpulse());
33 }
34 plot_save("bessel_lowpass12", output, options + ", title='12th-order Bessel filter, lowpass 1khz'");
35
36 {
37 zpk<fbase> filt = iir_lowpass(bessel<fbase>(6), 1000, 48000);
38 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
39 output = biquad<maxorder>(bqs, unitimpulse());
40 }
41 plot_save("bessel_lowpass6", output, options + ", title='6th-order Bessel filter, lowpass 1khz'");
42
43 {
44 zpk<fbase> filt = iir_lowpass(butterworth<fbase>(24), 1000, 48000);
45 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
46 output = biquad<maxorder>(bqs, unitimpulse());
47 }
48 plot_save("butterworth_lowpass24", output,
49 options + ", title='24th-order Butterworth filter, lowpass 1khz'");
50
51 {
52 zpk<fbase> filt = iir_lowpass(butterworth<fbase>(12), 1000, 48000);
53 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
54 output = biquad<maxorder>(bqs, unitimpulse());
55 }
56 plot_save("butterworth_lowpass12", output,
57 options + ", title='12th-order Butterworth filter, lowpass 1khz'");
58
59 {
60 zpk<fbase> filt = iir_highpass(butterworth<fbase>(12), 1000, 48000);
61 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
62 output = biquad<maxorder>(bqs, unitimpulse());
63 }
64 plot_save("butterworth_highpass12", output,
65 options + ", title='12th-order Butterworth filter, highpass 1khz'");
66
67 {
68 zpk<fbase> filt = iir_bandpass(butterworth<fbase>(12), 0.1, 0.2);
69 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
70 output = biquad<maxorder>(bqs, unitimpulse());
71 }
72 plot_save("butterworth_bandpass12", output,
73 options + ", title='12th-order Butterworth filter, bandpass'");
74
75 {
76 zpk<fbase> filt = iir_bandstop(butterworth<fbase>(12), 0.1, 0.2);
77 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
78 output = biquad<maxorder>(bqs, unitimpulse());
79 }
80 plot_save("butterworth_bandstop12", output,
81 options + ", title='12th-order Butterworth filter, bandstop'");
82
83 {
84 zpk<fbase> filt = iir_bandpass(butterworth<fbase>(4), 0.005, 0.9);
85 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
86 output = biquad<maxorder>(bqs, unitimpulse());
87 }
88 plot_save("butterworth_bandpass4", output, options + ", title='4th-order Butterworth filter, bandpass'");
89
90 {
91 zpk<fbase> filt = iir_lowpass(chebyshev1<fbase>(8, 2), 0.09);
92 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
93 output = biquad<maxorder>(bqs, unitimpulse());
94 }
95 plot_save("chebyshev1_lowpass8", output,
96 options + ", title='8th-order Chebyshev type I filter, lowpass'");
97
98 {
99 zpk<fbase> filt = iir_lowpass(chebyshev2<fbase>(8, 80), 0.09);
100 std::vector<biquad_params<fbase>> bqs = to_sos(filt);
101 output = biquad<maxorder>(bqs, unitimpulse());
102 }
103 plot_save("chebyshev2_lowpass8", output,
104 options + ", title='8th-order Chebyshev type II filter, lowpass'");
105
106 println("SVG plots have been saved to svg directory");
107
108 return 0;
109 }
110