MATLAB: Diff(x) is different to diff(fit)

diff()differentiationerrormagnitudeSignal Processing Toolboxsmoothsmoothing

Hi there. I have got some data from a wheel speed sensor on a motorcycle and i am trying to process it to get the driving force. This is simple as it just requires F=ma after deriving acceleration but the noise in the data makes it very difficult. The onboard computer is sampling every 100Hz and is varying only small amounts but when i differentiate it it gives a correct but useless graph of the acceleration against time after plotting it.
I have tried smoothing the data using smooth(v,50) which gives a more general trend but when differentiating it, it gives accelerations of around 0.4m/s^2. however if i curve fit the time vs velocity data after smoothing and differentiate the cfit then it gives me acceleration values of around 2-10 m/s^2 which is what is expected and backed up by the accelerometers.
So why is differentiating the fit different to differentiating the data? is it because it is differentiating from data point to data point? What can i do to fix this?
Many Thanks

Best Answer

Differentiation has the effect of high-pass filtering your data. This amplifies the noise, because the step-by-step differences produced by the diff function include the differences of the noise. Doing the fit first essentially low-pass filters your data, eliminating much of the noise and the noise effects), so the numerical derivative is of the ‘de-noised’ signal.
To determine if your noise is largely band-limited, use the fft (link) function. If it is, you might be able to get the same result by first using a lowpass filter (instead of doing the fit), and then taking the derivative of the filtered data. A Savitzky-Golay filter (the sgolayfilt (link) function) is another option.