-
Notifications
You must be signed in to change notification settings - Fork 38
/
butterworth.cpp
59 lines (55 loc) · 1.61 KB
/
butterworth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "Butterworth.h"
Butterworth::Butterworth(){}
Butterworth::~Butterworth(){}
/*
filterDesign for the time being returns precalculated
values for Butterworth 2nd order highpass filter,
given the sample frequency of source signal
*/
std::vector<std::vector<double>> Butterworth::filterDesign(int order, double attenuation, double cutoffFreq, int sampleFreq, int type)
{
std::vector<std::vector<double>> baCoefficients(2, std::vector<double>(3,0));
switch(sampleFreq){
case 200:
baCoefficients[0][0] = 0.8949;
baCoefficients[0][1] = -1.7897;
baCoefficients[0][2] = 0.8949;
baCoefficients[1][0] = 1.0000;
baCoefficients[1][1] = -1.7786;
baCoefficients[1][2] = 0.8008;
break;
case 250:
baCoefficients[0][0] = 0.9150;
baCoefficients[0][1] = -1.8299;
baCoefficients[0][2] = 0.9150;
baCoefficients[1][0] = 1.0000;
baCoefficients[1][1] = -1.8227;
baCoefficients[1][2] = 0.8372;
break;
case 300:
baCoefficients[0][0] = 0.9286;
baCoefficients[0][1] = -1.8572;
baCoefficients[0][2] = 0.9286;
baCoefficients[1][0] = 1.0000;
baCoefficients[1][1] = -1.8521;
baCoefficients[1][2] = 0.8623;
break;
case 360:
baCoefficients[0][0] = 0.9402;
baCoefficients[0][1] = -1.8803;
baCoefficients[0][2] = 0.9402;
baCoefficients[1][0] = 1.0000;
baCoefficients[1][1] = -1.8767;
baCoefficients[1][2] = 0.8839;
break;
case 500:
baCoefficients[0][0] = 0.9565;
baCoefficients[0][1] = -1.9131;
baCoefficients[0][2] = 0.9565;
baCoefficients[1][0] = 1.0000;
baCoefficients[1][1] = -1.9112;
baCoefficients[1][2] = 0.9150;
break;
}
return baCoefficients;
}