ya kno it

Committer:
Thijs12va
Date:
Wed Oct 25 12:35:24 2017 +0000
Revision:
0:09ae59836ddc
Child:
1:db5970567c4d
a;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thijs12va 0:09ae59836ddc 1 #include "filter.h"
Thijs12va 0:09ae59836ddc 2
Thijs12va 0:09ae59836ddc 3 float LowPass::filter(float x) // same as function lowpass
Thijs12va 0:09ae59836ddc 4 {
Thijs12va 0:09ae59836ddc 5 float y = a * yprev + (1 - a) * x;
Thijs12va 0:09ae59836ddc 6 yprev = y;
Thijs12va 0:09ae59836ddc 7 return y;
Thijs12va 0:09ae59836ddc 8 }
Thijs12va 0:09ae59836ddc 9
Thijs12va 0:09ae59836ddc 10 float HighPass::filter(float x){
Thijs12va 0:09ae59836ddc 11 xprev[0] = xprev[1]; // renew the 'previous value'
Thijs12va 0:09ae59836ddc 12 xprev[1] = x; // 2nd value is the current input value
Thijs12va 0:09ae59836ddc 13
Thijs12va 0:09ae59836ddc 14 float y = a * yprev + a * (xprev[1] - xprev[0]); // according to: https://en.wikipedia.org/wiki/High-pass_filter
Thijs12va 0:09ae59836ddc 15 yprev = y; // renew yprev for the next time
Thijs12va 0:09ae59836ddc 16 return y;
Thijs12va 0:09ae59836ddc 17 }
Thijs12va 0:09ae59836ddc 18
Thijs12va 0:09ae59836ddc 19 float Notch::filter(float x){
Thijs12va 0:09ae59836ddc 20 xprev[0] = xprev[1];
Thijs12va 0:09ae59836ddc 21 xprev[1] = xprev[2];
Thijs12va 0:09ae59836ddc 22 xprev[2] = x;
Thijs12va 0:09ae59836ddc 23
Thijs12va 0:09ae59836ddc 24 float y = (
Thijs12va 0:09ae59836ddc 25 (1.0+pow(lambda,2))*x
Thijs12va 0:09ae59836ddc 26 - 2.0*(1.0-pow(lambda,2))*xprev[1]
Thijs12va 0:09ae59836ddc 27 +(1.0+pow(lambda,2))*xprev[0]
Thijs12va 0:09ae59836ddc 28 + 2.0*(1.0-pow(lambda,2))*yprev[1]
Thijs12va 0:09ae59836ddc 29 -(1.0+pow(lambda,2)-b)*yprev[0]
Thijs12va 0:09ae59836ddc 30 )
Thijs12va 0:09ae59836ddc 31 /(1.0+pow(lambda,2)+b);
Thijs12va 0:09ae59836ddc 32
Thijs12va 0:09ae59836ddc 33 yprev[0] = yprev[1];
Thijs12va 0:09ae59836ddc 34 yprev[1] = y;
Thijs12va 0:09ae59836ddc 35 return y;
Thijs12va 0:09ae59836ddc 36 }
Thijs12va 0:09ae59836ddc 37
Thijs12va 0:09ae59836ddc 38 float ButterLow::filter(float x){
Thijs12va 0:09ae59836ddc 39 xprev[0] = xprev[1];
Thijs12va 0:09ae59836ddc 40 xprev[1] = xprev[2];
Thijs12va 0:09ae59836ddc 41 xprev[2] = x;
Thijs12va 0:09ae59836ddc 42
Thijs12va 0:09ae59836ddc 43 float y = (pow(w,2)*x
Thijs12va 0:09ae59836ddc 44 + 2*w*xprev[1]
Thijs12va 0:09ae59836ddc 45 + pow(w,2)*xprev[0]
Thijs12va 0:09ae59836ddc 46 + (2+sqrt(2.0f)*w-2*pow(w,2))*yprev[1]
Thijs12va 0:09ae59836ddc 47 - (1+pow(w,2))*yprev[0]
Thijs12va 0:09ae59836ddc 48 )
Thijs12va 0:09ae59836ddc 49 /(1+sqrt(2.0f)*w+pow(w,2));
Thijs12va 0:09ae59836ddc 50
Thijs12va 0:09ae59836ddc 51 yprev[0] = yprev[1];
Thijs12va 0:09ae59836ddc 52 yprev[1] = y;
Thijs12va 0:09ae59836ddc 53 return y;
Thijs12va 0:09ae59836ddc 54 }