diff(x) is different to diff(fit)
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (2)
Image Analyst
il 24 Ago 2017
0 voti
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
il 24 Ago 2017
Modificato: Ross Hanna
il 24 Ago 2017
0 voti
1 Commento
Star Strider
il 24 Ago 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.
Categorie
Scopri di più su Spectral Analysis in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!