Infinite impulse response filter
Embed:
(wiki syntax)
Show/hide line numbers
IIR.h
00001 #ifndef IIR_H 00002 #define IIR_H 00003 00004 #include <vector> 00005 using std::vector; 00006 /*-----------------------------*/ 00007 // Order of the numerator: m 00008 // Orser of the denominator: n 00009 //--------------------------------// 00010 // 00011 // y gain*( sum(i from 0 to m) b[i]*x[k-i] ) 00012 // --- = -------------------------------------------- 00013 // u 1 + sum( i from 1 to n) a[i]*y[k-i] 00014 // 00015 // y[k] = gain*( sum(i from 0 to m) b[i]*x[k-i] ) - sum( i from 1 to n) a[i]*y[k-i] 00016 // 00017 // Compatible with the coefficient generated by Matlab fdatool 00018 // 00019 // by C.F. Huang from LDSC 00020 /*-----------------------------*/ 00021 00022 class Circular_buffer{ 00023 private: 00024 size_t n; 00025 vector<float> A; 00026 // vector<float>::iterator it; 00027 int ind; // The index of the newest element 00028 00029 public: 00030 Circular_buffer(); 00031 Circular_buffer(int n_in); 00032 // 00033 void Init(int n_in); 00034 // 00035 float Get(int i); // Get the value of the (t-i)th element, where t stands for the current sample 00036 void Insert(float x_new); // Pop the oldest element and push a new element 00037 void reset(float val); // Reset all elements to val 00038 }; 00039 00040 class IIR{ 00041 private: 00042 00043 int m; // the order of numerator 00044 int n; // the order of denominator 00045 Circular_buffer x,y; 00046 vector<float> b; // parameters of numerator, highest order --> lowest order (newest -> oldest) 00047 vector<float> a; // parameters of denominator, highest order --> lowest order (newest -> oldest) 00048 float gain; 00049 00050 public: 00051 // 00052 IIR(int m, int n); 00053 // 00054 void Assign_parameters(float b_in[], float a_in[], float gain_in); 00055 // 00056 float Iterate_once(float x_in); 00057 void Reset(float val); 00058 }; 00059 00060 #endif
Generated on Sun Jul 17 2022 23:44:54 by
1.7.2