This post looks into the actual output of the accelerometer and investigates several filters that can be used to smooth the data.
I am slowly working towards the second phase of my microcontroller project. I hope to have a new proposal ready soon, but for now I have been working on my signal processing. I am very new to this, and I am trying to teach myself as much as possible with this project. I currently have the accelerometer from the servo arm project running on an arduino kit. Since the arduino has an easy to use serial library I set it up to work as a data logger for the accelerometer. I sampled the accelerometer at 50Hz, which is the same as in the previous project. I have not decided if this will be the sample frequency I use in the next project or not, but the results were informative.
The graph below shows the actual sampled data and the results of three different filters. The first filter, labeled Box, is the filter I used on the last project; an 8 sample rectangular rolling average. The Triangle filter is a 5 sample triangular weighted rolling average. The Butterworth filter is 2nd order with a cutoff of 2Hz.
Between the Box and Triangle filters, both lag the signal by similar amounts, but the triangular is much smoother. The butterworth is my first attempt at a real filter, it is much smoother but at the expense of a little more lag. The lag on these filters ranges from 100ms for the triangle and box, to about 140ms for the butterworth. I am not sure if this is a deal breaker, but it seems like a lot of lag.
My original thought with the very low sample frequency was that there was no point in sampling the accelerometer faster than I could update the servo (once every 20ms). Now, I am thinking I will investigate faster sampling times to see if I will be able to create a smooth signal with less lag than the filters presented here.
Looks like a fun project. Have you thought about using a Kalman filter?
I have looked at the Kalman filter and it does look like the tool for the job. I am very new to this though, and implementing the Kalman looks significantly more difficult than the others I have been investigating. Do you know where I might find an example implementation in C?