View Full Version : Discussion digital filtering of accelerometer data...?
flygplan123
Mar 16, 2009, 05:01 AM
Hi.
I am trying to filter out noise in my accelerometer data by using a low pass filter but have problems with the implementation.
In matlab I have tried to filter with a butterworth filter and found a good filter for my data but when I try to digitally implement it I do not get the same results by far. I have tried this website (http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html) to generate c-code for my AVR-microprocessor but don't get any good results.
Have also tried a digital FIR filter but I am not getting the noise reduction that I want.
How should I proceed? What kind of filter is the best for LP-filtering accelerometer data digitally? How do I implement it?
flyg :)
rbeall
Mar 16, 2009, 03:03 PM
Show me some of your code and I can help. I have writen alot of LP's in matlab here lately!
Basic idea is
i=1;
B1 = 0.9;
A0 = 1-B1;
data_lp = 0;
while(i<(length(data)))
data_lp(i+1) = (data_lp(i)*B1) + (data(i+1)*A0);
i=i+1;
end
-Ryan
flygplan123
Mar 17, 2009, 04:10 AM
Show me some of your code and I can help. I have writen alot of LP's in matlab here lately!
-Ryan
function [signalOut] = LPfilter(signalIn)
NZEROS = 9;
NPOLES = 9;
GAIN = 4.013407380e+13;
xv = zeros(1,NZEROS+1);
yv = zeros(1,NPOLES+1);
for i=1:length(signalIn)
xv(1) = xv(2); xv(2) = xv(3); xv(3) = xv(4); xv(4) = xv(5); xv(5) = xv(6); xv(6) = xv(7); xv(7) = xv(8); xv(8) = xv(9); xv(9) = xv(9);
xv(9) = signalIn(i) / GAIN;
yv(1) = yv(2); yv(2) = yv(3); yv(3) = yv(4); yv(4) = yv(5); yv(5) = yv(6); yv(6) = yv(7); yv(7) = yv(8); yv(8) = yv(9); yv(9) = yv(9);
yv(10) = (xv(1) + xv(9)) + 9 * (xv(2) + xv(9)) + 36 * (xv(3) + xv(8))
+ 84 * (xv(4) + xv(7)) + 126 * (xv(5) + xv(6))
+ ( 0.6963436851 * yv(1)) + ( -6.5190506719 * yv(2))
+ ( 27.1297881830 * yv(3)) + (-65.8734134040 * yv(4))
+ (102.8429285400 * yv(5)) + (-107.0618151300 * yv(6))
+ ( 74.3176263530 * yv(7)) + (-33.1705783120 * yv(8))
+ ( 8.6381707611 * yv(9));
signalOut(i) = yv(10);
end
end
This is a butterworth filter generated on the link I previously mentioned.
Maybe there is no need to make it this complicated.
flyg :)
rbeall
Mar 17, 2009, 11:47 AM
yeah I like to keep things simple and a sigle pole low pass is about as simple as they come. Try mine and see if you like it. My guess is it will work just fine.
What exactly are you trying to accomplish. There is a lot to consider when it comes to hardware as well. Low passing the hardware with an RC can drop your noise a couple of standard devs.
-Ryan
eddymoore
Mar 17, 2009, 05:41 PM
How fast are you running it? Remember all that floating point on an AVR is going to be hard, lengthy work for such a diddy micro.
9th order is perhaps a bit long too, though the 2nd order advocated above might be a *bit simple*. Give it a go.
Also, check you can deal with overflows.
Infact, this might be useful: http://www.atmel.com/dyn/resources/prod_documents/doc2527.pdf
flygplan123
Mar 19, 2009, 05:45 AM
How fast are you running it? Remember all that floating point on an AVR is going to be hard, lengthy work for such a diddy micro.
9th order is perhaps a bit long too, though the 2nd order advocated above might be a *bit simple*. Give it a go.
Also, check you can deal with overflows.
Infact, this might be useful: http://www.atmel.com/dyn/resources/prod_documents/doc2527.pdf
You might be right, I'll try to keep it simple. Didn't really take the processors limitations into account. The pdf was really helpful. Thanks.
/flyg :)
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.