1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Filters for Real World Accelerations

  1. Feb 12, 2013 #1

    I'm having trouble with the application of filtering to real acceleration data. I have looked at a lot of recommendations, filtering through fft, butterworth high and low pass filters, and I'm not finding something thats working for my data and I'm looking for recommendations.

    I think my problem is that I am looking at very slow accelerations, so the "drift" in the accelerometer is eliminated-but so is the trend in the data itself. I will be looking at the cases of relatively slow acceleration and velocity, and slow acceleration with pauses in between sequences. A low pass filter does okay-but does not provide an accurate map of displacement in the end. Using an fft seems to also eliminate the slower trend in the data.

    I have also added in elimination of values less than the abolsute mean found for a static case. This seems to help a little bit, but I may be losing some data.

    I have attached a couple of examples of what the problem is. I made a rectangle with the accelerometer pretty much and these are the results with no filters and a low pass filter.
    First 2 are no filter. 2nd 1 is the LP filtered accel. (I can send velocity if interested-looks the same pretty much)

    Are there any other filters I should be trying? Different methods of integration? (I am currently using a trapazoidal integrator). I'm pretty much looking for recommendations processing this type of data.

    Thanks! (I also hope this is the correct thread for this).

    Attached Files:

  2. jcsd
  3. Feb 12, 2013 #2


    User Avatar
    Science Advisor
    Homework Helper

    Integrating the accelerations twice to get displacements is equivalent to a high pass filter, without doing anything to the raw data. It multipliies a component with frequuency ##\omega## by ##-1/\omega^2##.

    Filtering the data in the time domain can be problematic if the filter introduces phase shifts in the different frequency components of the measured data. You can design finite impulse response (FIR) digital filters that don't introduce phase shifts, but unless there is a specific noise problem (e.g. vibration or electrical noise at a particular frequency that you want to remove) you probably don't need to do it at all.

    A common problem with this sort of measurement is low frequency "drift" because the accelerometer readings are not exactly correct for zero acceleration. One way to fix that is do it empirically. If you know the start and end positions independent of the accelerometer data, add a constant acceleration that makes the end point of the graph correct, i.e. use the formulas ##v = at##, ##x = at^2/2## to estimate the "zero error acceleration" ##a##.

    Trapeziod integration is probably as good as anything. It uses all the data without "inventing" anything extra, or throwing any information away.

    Another practical tip is use the highest data sampling rate than you can, to capture rapid changes of acceleration as accurately as possible. Unfortunately there is usually a trade off between capturing the peak acceleration values without clipping, and getting accurate data when the accleration is low.

    If you can do your experiment so the start and end positions are the same, you can enforce that by taking an FFT of all the data, and setting just the "zero frequency" Fourier coefficient to 0. You can then integrate the data in the frequency domain by dividing the fourer coefficients by ##i\omega## or ##-\omega^2## before doing the inverse FFT, rather than doing the integration in the time domain with the trapezoidal rule.
  4. Feb 13, 2013 #3
    Okay, that helps a little. Maybe you can help me with the underlying understanding of the FFT as that seems to be one of my issues. I can guarantee for this particular experiment that the start and end point are always the same (to a relatively high degree of accuracy).

    So-I'm trying to map my accelerations into the frequency domain. That means those acceleration points now become termed fourier coefficients after the fft? Does this also mean that I randomly set the first one in the array to zero?

    To get the Ω associated with each Fourier coeffcient, I am a little confused. I can get the sampling frequency by looking at 1/T. (Lets say for experiments' sake that I do this calculation for a sampling period of 0.005s and get 200 Hz for my sampling frequency.)

    Does that mean I just divide my new fourier coefficients by that same Ω? (200 Hz or whatever it is-although this looks like Ω needs to be in rad/sample?) The previous comes out very wrong so I assume I'm making at least some incorrect assertions.

    Or does each coefficient have a specific Ω value that can be found somehow? Is this what you mean by "zero frequency" fourier coefficients in that there will be values throughout my coefficient array that are specifically associated with Ω =0? (not necesarily the first coefficient).

    I had a question also about finding a characteristic acceleration that can be used to cancel out the offset. I understand I want my acceleration integral and velocity integral to be zero in the end to achieve start/stop in the same place. But how can this be applied to an array of data where the equation is unknown and, in all likelihood, to get accurate results, a changing acceleration is needed to not only allow the displacement to end at 0, but to also allow the inbetween values to be accurate? How do I go about looking for that equation where I have
    [itex]v_{n} = v_{n-1} + a_{n-1}(t_n - t_{n-1})[/itex]

    [itex]x_{n} = x_{n-1} + v_{n-1}(t_n - t_{n-1}) + \frac{1}{2} a_{n-1} (t_n - t_{n-1})^2[/itex]

    and I probably need a unique acceleration between each time step? especially where all I know are the endpoints and not the exact location after each time step?

    Sorry for the multitude of questions. Thanks.
  5. Feb 13, 2013 #4


    User Avatar
    Science Advisor
    Homework Helper

    If you have a N data points and sample interval of T, you get N Fourier components which represent frequencies of ##0##, ##1/(2NT)##, ##2/(2NT)## ... ##(N-1)/(2NT)## Hz.

    To get the corresponding ##\omega##'s in radians/sec you multiply by ##2\pi## of course.

    Each fourier component represents a "sine" and a "cosine" wave of that particular frequency. Each component is a complex number (even if your original measured data was real numbers) and the real and imaginary part of each coefficient represent the amplitudes of the cos and sin waves.

    So you need to divide each coefficient by the corresponding ##i\omega## or ##-\omega^2##.

    (If you look at websites or testbooks about this, you might discover I've left out some issues about what the "zero frequency" coefficient means when you do an FFT of complex data - but your measured data is real numbers, not complex, so you don't need to bother about that)

    You can't get everything accurate. The best you can do is "spread out" the errors evenly do at least the final position is correct.

    If you start and end with the same displacement (if doesn't matter if you measure it as 0, or something else) that means the average velocity in the experiment was zero. Similarly if you start and end with the same velocity, the average acceleration is zero.

    So you can calculate the average acceleration that you measured, and subtract that from every acceleration measurement.
    Then do the integration to find the velocities, as you did before.
    Then calculate the average velocity, and subtract that from your calculated values.
    Then do the integration to find the displacements.

    Actually these two methods are really the same, because the fourier coefficient for the zero frequency is just the average of the data points.
  6. Feb 13, 2013 #5
    okay-that at least makes sense theoretically, thank you.

    getting it to work in real life-looks like I have a bit more work to do. Neither of the 2 methods quite makes the true rectangle out of the data yet (as shown below, first averaging, then FFT) but the values are in the right range, which is good.

    Code (Text):

    function disp_time_data = acc2disp(acc_time_data,dt)

    N = length(acc_time_data);

    acc_freq_data = fft(acc_time_data);

    disp_freq_data = zeros(size(acc_freq_data));
    disp_freq_data(1) = 0;

    for i = 2 : N
          disp_freq_data(i) = acc_freq_data(i)/( sqrt(-1)*(2*pi*((i-1)/(2*N*dt))) );
    disp_time_data = ifft(disp_freq_data);    

    Although, I actually had to square the bottom term (ωi) to get the graphs to be the same shape (picture 3 is the fft with the bottom term squared), which I was a little curious about, as well as why the FFT graph was offset compared to the averaging techniques. I'm hoping that I don't see a rectangle yet because on this one test, I did not end up in exactly the same place I started?

    Attached Files:

  7. Feb 14, 2013 #6


    User Avatar
    Science Advisor
    Homework Helper

    If the accelerations for one Fourier component are ##Ae^{i\omega t}## (where ##A## is the Fourier coefficient), integrating once to get the velocities gives ##Ae^{i\omega t}/(i\omega)## and integrating again to get the displacements gives ##-Ae^{i\omega t}/\omega^2##

    If you integrate the FFT data, the origin will be at the mean of all the data points in X and Y. The zero fourier coefficient represents the mean value of the data points, and you set it to 0. (Try setting it to some other value and see what difference it makes).

    On the other hand, when you do the integration in the time domain, you are arbitrarily setting the first data point to be at (0,0). Again, you could use a different value if you want.

    Just a thought on doing the experiment: remember the accelerometers measure accelerations in the direction they are pointing, not in the global X and Y directions. Maybe you are accidentally rotating the object as you move it around the path.
  8. Feb 14, 2013 #7
    Cool! Thats kind of interesting to see.

    I had been thinking about local reference frame actually in trying to solve my real problem, but I actually don't have a fixed global reference frame that I "know" about, at least not yet, that's a part of what this is about.

    I suppose I could set, for this purpose, the first position as the "fixed" frame for subsequent measurements. But even then, especially as I have no idea what the path is, I wouldn't have a method of determining the transformation matrix to get from one frame to the next. (okay, I will know its an arc of undetermined radius-maybe there's an optimization or something I could do with that... although initial position of the accelerometer frame relative to the frame at the base of the arc is unknown in both rotation and translation)

    I just did a decently precise circle with the accelerometer (where the accelerometer is fixed to the edge of a rotating disc), where the frame is changing all the time, to see what the result would be. I wonder if that local frame integration, without a static frame, is what causes the units and the shape to be so off in a position graph.

    Attached Files:

  9. Feb 14, 2013 #8


    User Avatar
    Science Advisor
    Homework Helper

    Was that a circle at constant RPM? Was it rotating in a horizontal plane or a vertical plane (where gravity would affect what you measure?)

    If you fix the accelerometers to a rotating dosk at constant speed in the horizontal plane, you should measure a constant acceleration towards the center (= ##r\omega^2##). If not, I think you need to figure out exactly what you ARE measuring here.
  10. Feb 14, 2013 #9
    horizontal plane with variable acceleration and variable velocity (I actually stopped and restarted the motion about 200 degrees around or there about before completing the circle).
    I had wanted to do a case with uncertian accelerations, but a constant accel case might be easier to calculate for functionality.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook