Luke O. Cartwright 201225242
Embed:
(wiki syntax)
Show/hide line numbers
Filter.cpp
00001 #include "mbed.h" 00002 #include "Filter.h" 00003 00004 //constructor/destructor 00005 Filter::Filter() 00006 { 00007 } 00008 Filter::~Filter() 00009 { 00010 } 00011 00012 00013 int Filter::filter_run(int input, int filter_type, bool init) 00014 { 00015 if (filter_type==0){ //none 00016 y=input; 00017 } 00018 if (filter_type==1){ //LPF 00019 y=LPF(input,init); 00020 } 00021 if (filter_type==2){ //HPF 00022 y=HPF(input,init); 00023 } 00024 if (filter_type==3){ //BPF 00025 y=BPF(input,init); 00026 } 00027 return(y); //Output 00028 } 00029 00030 int Filter::LPF(int input,bool init) 00031 { 00032 if (init==true) { //initial Value set 00033 x=0; 00034 y_1=0; 00035 y=0; 00036 } 00037 else { 00038 x = input; 00039 y = y_1 + 0.05*(x-y_1); //LPF algorithm 00040 y_1=y; 00041 } 00042 return(y); 00043 } 00044 00045 int Filter::HPF(int input,bool init) 00046 { 00047 if (init==true) { //initial Value Set 00048 x=0; 00049 y_1=0; 00050 y=0; 00051 } 00052 else { 00053 x = input; 00054 y = (y_1 - 0.95*(x - y_1))/2.9; //HPF Algorithm 00055 y_1=y; 00056 } 00057 return(y); 00058 } 00059 00060 int Filter::BPF(int input,bool init) 00061 { 00062 if (init==true) { //initialise 00063 y=0; 00064 } 00065 else { 00066 y=HPF(input,false); //HPF 00067 y=LPF(y,false); //LPF 00068 } 00069 return(y); 00070 }
Generated on Tue Jul 12 2022 19:25:35 by
1.7.2