nurhidayat86 / ERTS

1 stars 0 forks source link

Butterworth Filter (fixed point) #11

Closed anggairawan closed 7 years ago

anggairawan commented 7 years ago

Noise suppression (low pass filtering) to filter out the noise from the motor.

anggairawan commented 7 years ago

@rviset @nurhidayat86 http://www.st.ewi.tudelft.nl/~koen/in4073/Resources/index.html

Download: Arjan's [Kalman] filter examples (Matlab)

See myfilter1.m and nyfilter2.m. There are butterworth filter Examples.

The last lecture mentioned approximately we have to filter out the frequency around 77.9 Hz (?).

nurhidayat86 commented 7 years ago

I did not notice about the number, but yes he said something about filtering DMP data due to the micro vibration caused by the motors. Otherwise our control input will also oscillate.

nurhidayat86 commented 7 years ago

@rviset, you can use this program: http://www.winfilter.20m.com/

It looks like this after conversion: /** WinFilter version 0.8 http://www.winfilter.20m.com akundert@hotmail.com

Filter type: Low Pass Filter model: Butterworth Filter order: 2 Sampling Frequency: 100 Hz Cut Frequency: 10.000000 Hz Coefficents Quantization: 16-bit

Z domain Zeros z = -1.000000 + j 0.000000 z = -1.000000 + j 0.000000

Z domain Poles z = 0.571472 + j -0.293599 z = 0.571472 + j 0.293599 ***/

int16_t iir(int16_t NewSample) {

//NCoef 2
//DCgain 8

uint8_t n;
int16_t ACoef[3], BCoef[3];
int32_t y[3], int32_t x[3];

ACoef[0] = 8841;
ACoef[1] = 17682;
ACoef[2] = 8841;

BCoef[0] = 16384;
BCoef[1] = -18726;
BCoef[2] = 6763;

//shift the old samples
for(n=2; n>0; n--) {
   x[n] = x[n-1];
   y[n] = y[n-1];
}

//Calculate the new output
x[0] = NewSample;
y[0] = ACoef[0] * x[0];

for(n=1; n<=2; n++)
    y[0] += ACoef[n] * x[n] - BCoef[n] * y[n];

y[0] /= BCoef[0];

return y[0] / 8;

}

nurhidayat86 commented 7 years ago

8 bit butterworth filter works no better than averaging filter. 16 bit butt filter gives overflow