SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
fir_iir.cpp
Go to the documentation of this file.
1
25#include "sigpack.h"
26
27using namespace arma;
28using namespace sp;
29
30int main()
31{
32 // Filter coeffs.
33 vec b;
34 int N = 15;
35
36 // Create a FIR filter
38 b = fir1( 7, 0.35 );
39 fir_filt.set_coeffs( b );
40
41 vec X( N ); // Input sig
42 X.zeros();
43 X[0] = 1; // Impulse
44
45 vec Y( N ); // Output sig
46 Y.zeros();
47
48 // Filter - sample loop
49 for( int n = 0; n < N; n++ )
50 {
51 Y[n] = fir_filt( X[n] );
52 }
53
54 std::cout << "Filter coeffs: \n" << b.t() << std::endl;
55 std::cout << "Impulse response:\n" << Y.t() << std::endl;
56
57 // Create a IIR filter
59 vec a;
60 b = { 0.25, 0.5, 0.25 };
61 a = { 1, -0.9 };
62
63 iir_filt.set_coeffs( b, a );
64 Y = iir_filt.filter( X );
65 std::cout << "IIR theor. impulse response: \n 0.2500 0.7250 0.9025 0.8123 "
66 " 0.7310 0.6579 0.5921 0.5329 0.4796 0.4317 0.3885 ..."
67 << std::endl;
68 std::cout << "IIR output: \n" << Y.t() << std::endl;
69
70 Delay<double> del( 3 );
71 std::cout << "Delay three samples:\n" << del.delay( Y ).t() << std::endl;
72
73 return 0;
74}
A delay class.
Definition timing.h:20
arma::Col< T1 > delay(const arma::Col< T1 > &in)
A delay operator (vector version).
Definition timing.h:91
FIR/MA filter class.
Definition filter.h:22
void set_coeffs(const arma::Mat< T2 > &_b)
Sets coefficients in FIR filter. The internal state and pointers are cleared.
Definition filter.h:70
IIR/ARMA filter class.
Definition filter.h:504
void set_coeffs(const arma::Col< T2 > &_b, const arma::Col< T2 > &_a)
Sets coefficients in IIR filter. The internal state and pointers are cleared.
Definition filter.h:546
arma::Col< T3 > filter(const arma::Col< T1 > &in)
Filter function.
Definition filter.h:615
int main()
Definition fir_iir.cpp:30
arma_inline arma::vec fir1(const arma::uword M, const double f0)
FIR lowpass design function. FIR lowpassdesign using windows method (hamming window)....
Definition filter.h:637
Definition base.h:8