Derivative of Irregularly Sampled Noisy Data with Savitzky-Golay Filter
5 views (last 30 days)
Show older comments
I'm trying to find the derivative of some data that is both irregularly sampled, and somewhat noisy. It should be monotonically decreasing in theory. I've attached a file with the data for reference. Is there a way, SG or otherwise, that it would be possible to get a derivative of the relatively smooth input data that is smoother than this? Especially near the begining and end.
Modifying the SG parameters only does so much, (2,41) seems okay, but I start to lose info at the start. Is there another way around this? Also possibly with better resampling method?
clc;clear all;close all
%Load data
data=load('data.mat');t=data.M(:,1);V=data.M(:,2);
%resample data
desired_Freq_samples = 1/5;
[V_r, t_r] = resample(V,t,desired_Freq_samples);
%SG smoothing and derivative
[b,g] = sgolay(5,25);
dt = t_r(2)-t_r(1);
dx = zeros(length(V_r),2);
for p = 0:1
dx(:,p+1) = conv(V_r, factorial(p)/(-dt)^p * g(:,p+1), 'same');
end
%plot
s1=subplot(2,1,1);plot(s1,t,V,'--.',t_r,V_r,'.-',t_r,dx(:,1))
legend(s1,'V','V (resampled)','V (smoothed)','location','best')
s1.XLim=[min(t)-10 max(t)+10];
s2=subplot(2,1,2);plot(s2,t_r,dx(:,2))
legend(s2,'V''','location','best')
s2.YLim=[-4e-3 0];
s2.XLim=[min(t)-10 max(t)+10];
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!