openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
Filter.cc
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 "Filter.h"
21 
32 Butterworth::Butterworth( int order, double low, double upper)
33 {
34  if( !low && !upper ) {
35  fprintf( stderr, "Must specify at least one frequency\n" );
36  return;
37  }
38 
39  if( !low ) {
40  _n = order+1;
41  _c = ccof_bwlp( order );
42  _d = dcof_bwlp( order, upper );
43  _sf = sf_bwlp( order, upper );
44  } else if( !upper ) {
45  _n = order+1;
46  _c = ccof_bwhp( order );
47  _d = dcof_bwhp( order, low );
48  _sf = sf_bwhp( order, low );
49  } else {
50  _n = 2*order+1;
51  _c = ccof_bwbp( order );
52  _d = dcof_bwbp( order, low, upper );
53  _sf = sf_bwbp( order, low, upper );
54  }
55 }
56 
57 void zero_avg( double *x, int n )
58 {
59  double avg=0;
60  for( int i=0;i<n;i++ )
61  avg += x[i];
62  avg /= (double)n;
63  for( int i=0;i<n;i++ )
64  x[i] -= avg;
65 }
66 
67 
76 void filter_all( double **in, int nr, IIR_Filt *filt, double *out, int t )
77 {
78  for( int i=0; i<nr; i++ ) {
79  filt->apply( in[i], out, t );
80  memcpy( in[i], out, t*sizeof(double) );
81  }
82 }
83 
84 
long double sf_bwhp(int n, long double fcf)
Definition: iir.c:493
Butterworth(int, double, double h=0)
Definition: Filter.cc:32
void apply(T *, U *, int)
Definition: Filter.h:39
long double * dcof_bwbp(int n, long double f1f, long double f2f)
Definition: iir.c:236
int * ccof_bwbp(int n)
Definition: iir.c:397
void zero_avg(double *x, int n)
Definition: Filter.cc:57
int _n
Definition: Filter.h:34
long double * _d
Definition: Filter.h:33
void filter_all(double **in, int nr, IIR_Filt *filt, double *out, int t)
Definition: Filter.cc:76
int * ccof_bwhp(int n)
Definition: iir.c:377
long double _sf
Definition: Filter.h:35
long double sf_bwbp(int n, long double f1f, long double f2f)
Definition: iir.c:525
int * _c
Definition: Filter.h:32
int * ccof_bwlp(int n)
Definition: iir.c:348
long double * dcof_bwlp(int n, long double fcf)
Definition: iir.c:178
long double sf_bwlp(int n, long double fcf)
Definition: iir.c:461
long double * dcof_bwhp(int n, long double fcf)
Definition: iir.c:224