kalman filter with MPU6050

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Switten
Level 2
Level 2
25 sign-ins 10 likes given 10 sign-ins

Hi there,

 

In my project(program in attached file), I am using a MPU6050 for selfbalancing purposes. I got the raw MPU data, processed it, and obtained an angle. However, when I push the device, it returns a 'noise value' as shown below:

 

The angle of the MPU6050 is :0 deg
The angle of the MPU6050 is :0 deg
The angle of the MPU6050 is :0 deg
The angle of the MPU6050 is :-62 deg
The angle of the MPU6050 is :21 deg
The angle of the MPU6050 is :1 deg
The angle of the MPU6050 is :1 deg
The angle of the MPU6050 is :0 deg
The angle of the MPU6050 is :0 deg
The angle of the MPU6050 is :0 deg
The angle of the MPU6050 is :0 deg

 


Usually a kalman filter is used for this (I think), but I don't know how to do this/I don't understand it. Does anyone know how to do this?

Thank you and have a nice day.

0 Likes
1 Solution
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

A Kalman filter is used to predict the next output based on a series of inputs; it is usually based on knowledge of system performance, for example how fast a system can move or a sensor can realistically respond. For simple impulse noise rejection, look at a median filter. This is good for rejecting impulse noise. There are a few community threads on this topic.

I took your data and padded it with 0 for a few samples before and after.
The raw data is in red, a moving average looks back at the last  5 samples.
The IIR looks back with last_out*(1-1/8) + input/8.
The median filter looks at the middle of 5 samples, 2 previous, current, and2 future; this will of course
require a 3 sample delay. It does the best job of limiting the spike noise, assuming that  your system
doesn't really move fast enough to generate real jumps of 61 counts.

DennisS_46_0-1642485619498.png

---- Dennis

View solution in original post

0 Likes
4 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

I could not find any solution readily available for this. I could see some C code implementing the same on searching on the internet. Are you trying to do something similar ? 

Also check digital filter component available in creator https://www.infineon.com/cms/en/design-support/tools/sdk/psoc-software/psoc-3-5-components/filter/?u...

 

Best Regards,
Vasanth

0 Likes
lock attach
Attachments are accessible only for community members.

(Sorry for the late reply) I have maybe found a complementary filter, but it needs to be tested:

angle = 0.98 (angle+gyrodt) + 0.02*acc

However, I'm having trouble adjusting the gyro angle. It won't give me the angle, see the new project.

 

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

A Kalman filter is used to predict the next output based on a series of inputs; it is usually based on knowledge of system performance, for example how fast a system can move or a sensor can realistically respond. For simple impulse noise rejection, look at a median filter. This is good for rejecting impulse noise. There are a few community threads on this topic.

I took your data and padded it with 0 for a few samples before and after.
The raw data is in red, a moving average looks back at the last  5 samples.
The IIR looks back with last_out*(1-1/8) + input/8.
The median filter looks at the middle of 5 samples, 2 previous, current, and2 future; this will of course
require a 3 sample delay. It does the best job of limiting the spike noise, assuming that  your system
doesn't really move fast enough to generate real jumps of 61 counts.

DennisS_46_0-1642485619498.png

---- Dennis

0 Likes