Borrar filtros
Borrar filtros

diff(x) is different to diff(fit)

8 visualizaciones (últimos 30 días)
Ross Hanna
Ross Hanna el 24 de Ag. de 2017
Comentada: Star Strider el 24 de Ag. de 2017
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

Respuesta aceptada

Star Strider
Star Strider el 24 de Ag. de 2017
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.

Más respuestas (2)

Image Analyst
Image Analyst el 24 de Ag. de 2017
Since the derivative is the slope, obviously the slopes from one data point to another can vary wildly from some huge positive number to some huge negative number if you have noise in the data and it bounces up and down. Smoothing gets rid of that and gives a consistent slope from point to point.

Ross Hanna
Ross Hanna el 24 de Ag. de 2017
Editada: Ross Hanna el 24 de Ag. de 2017
Thanks for the very quick answers! The sgolayfilt worked best as fft was giving complex answers. however, how do you decide what order and framelength to use and also the values of the acceleration are still extremely low?
  1 comentario
Star Strider
Star Strider el 24 de Ag. de 2017
As with most things in signal processing, you have to experiment. I’m not certain there is any analytical way to determine the sgolayfilt parameters.
The fft will produce complex output. See the code between the first (top) two plot figures in the documentation I linked to, in order to get the one-sided real result (using the abs function).
If you want to do lowpass filtering of your signal once you have the fft plot, prototype code for one is:
Fs = 44100; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 500/Fn; % Passband Frequency (Normalised)
Ws = 510/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 147; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(1)
freqz(sosbp, 2^16, Fs) % Filter Bode Plot
signal = randn(1,Fs); % Substitute Your Signal Here
filtered_signal = filtfilt(sosbp, gbp, signal); % Filter Signal
Make appropriate changes for your sampling frequency and cutoff frequency. The filter Bode plot verifies that the filter has the characteristics you want it to have.

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by