openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
Filter.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 // ----------------------------------------------------------------------------
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include "iir.h"
24 
25 class IIR_Filt {
26  public:
27  IIR_Filt( ){};
28  virtual ~IIR_Filt(){free(_c);free(_d);}
29 template<class T, class U>
30  void apply(T*, U*, int);
31  protected:
32  int *_c;
33  long double *_d;
34  int _n;
35  long double _sf;
36 };
37 
38 template<class T,class U>
39 void IIR_Filt::apply( T *x, U *y, int sz )
40 {
41  for( int i=0; i<_n; i++ )
42  y[i] = 0;
43 
44  for( int i=_n; i<sz; i++ ) {
45  long double sum = _sf*_c[0]*x[i];
46  for( int j=1; j<_n; j++ ) {
47  sum += x[i-j]*_sf*_c[j] - _d[j]*y[i-j];
48  }
49  y[i] = sum;
50  }
51 }
52 
53 
54 class Butterworth : public IIR_Filt {
55  public :
56  Butterworth( int, double, double h=0 );
57 };
58 
59 void filter_all( double **in, int nr, IIR_Filt *filt, double *out, int t );
60 
61 void zero_avg( double *x, int n );
62 
void zero_avg(double *x, int n)
Definition: Filter.cc:57
void filter_all(double **in, int nr, IIR_Filt *filt, double *out, int t)
Definition: Filter.cc:76
void apply(T *, U *, int)
Definition: Filter.h:39
int _n
Definition: Filter.h:34
long double * _d
Definition: Filter.h:33
long double _sf
Definition: Filter.h:35
int * _c
Definition: Filter.h:32
T sum(const vector< T > &vec)
Compute sum of a vector&#39;s entries.
Definition: SF_vector.h:340
IIR_Filt()
Definition: Filter.h:27
virtual ~IIR_Filt()
Definition: Filter.h:28