PSoC™ 5, 3 & 1

Level 2
Level 2

# kalman filter with MPU6050

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.

1 Solution
Employee
Employee

# Re: kalman filter with MPU6050

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.

---- Dennis

4 Replies
Moderator
Moderator

# Re: kalman filter with MPU6050

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

Level 2
Level 2

# Re: kalman filter with MPU6050

(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.

Employee
Employee