next up previous contents
Next: Time domain integration Up: Time domain analysis Previous: Time domain analysis   Contents

Time domain differentiation (e.g. convert velocity to acceleration)

If we want to convert from velocity to acceleration (or displacement to velocity), what we want is time domain differentiation. In matlab, given a signal x, your first inclicination might be plot(t, diff(x)*Fs). You will immediately get an error here, because matlab's diff routine computes a vector of first order differences x(2)-(1), x(3)-x(2), x(4)-x(3), etc. and there are only n-1 output values for n inputs values. I remember being a little unsure what to do about this. Perhaps the most useful thing I learned from my class on computation fluid dynamics is that it is okay to treat the boundaries differently in numerical differentiation. So, for example, we can use first order forward differences for the main part of the vector, and first order backward difference at the end. In other words, v=[ diff(x), x(end)-x(end-1)]/Fs is perfectly okay.

Surprisingly, diff() is the only difference routine provided by matlab. I guess they assume that if you want something more accurate, you will write it yourself. Here is a second order centered difference (with first order differences at the boundaries).

function d = cdiff(x, dt)

if (nargin<2)

dt =1 ;

end

d(1) = (x(2) - x(1)) / dt;

d(length(x)) = ( x(end) - x(end-1) ) / dt;

ndx = 2:(length(x)-1);

d(ndx) = (x( ndx+1) - x(ndx-1)) / (2 * dt);

I rarely feel the need to go beyond a second order difference formula, but higher orders do exist. Consult any book on numerical methods.

Differentiation will amplify high frequency noise in your signal. Depending on what you are interested in, you may need to apply a low pass filter afterwards to remove this noise.


next up previous contents
Next: Time domain integration Up: Time domain analysis Previous: Time domain analysis   Contents " . $row['Name'] . " Posted on " . $row['DateTime']; echo "
"; echo $row['Comment']; echo "

"; } echo "
"; ?> Leave a comment on this page:

Name: (optional)
To prove you are not a robot, what is 2+3?

Creative Commons License
This work by Daniel Kiracofe (daniel dot kiracofe at gmail dot com) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License./' $I