Adaptive Savitzky-Golay filter
3 次查看(过去 30 天)
显示 更早的评论
Hi
uses adaptive SG filter on a generated data and noise .
I need to apply this method on some signals , what should be changed in order to use it for my case ?
global Pkmi_array
m=(length(data_frame)-1)/2;
N=length(data_frame);
x=-m:m;
y=data_frame;
x=x(:);
y=y(:);
k_start=2;% Savitzky-Golay differentiation filters with polynomial degrees 1 and 2 are the same.
k_end=N-1-2;
alpha=0.01;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if k_end<=k_start
polynomial_degree=k_start;
return;
else
k=k_start;
p_fit=polyfit(x,y,k);%polynomial degree = k_start
res_even=sum((y-polyval(p_fit,x)).^2);
while k<k_end %%%%%%%%%%%%%%%%k=2,4,...(even)
%k
n1=k;
%polynomial degree = k
k=k+1;
value1=0;
value2=0;
for i=-m:m
value1=value1+Pkmi_array(k+2,m,i+m+1)*y(i+m+1);
value2=value2+(Pkmi_array(k+2,m,i+m+1))^2;
end
res_tmp=res_even(end)-value1^2/value2;
%polynomial degree = k+1
k=k+1;
value1=0;
value2=0;
for i=-m:m
value1=value1+Pkmi_array(k+2,m,i+m+1)*y(i+m+1);
value2=value2+(Pkmi_array(k+2,m,i+m+1))^2;
end
res_even=[res_even res_tmp-value1^2/value2];
n2=k;
v1=n2-n1;
v2=N-n2-1;
Fx=(res_even(end-1)-res_even(end))/(n2-n1)/(res_even(end)+eps)*(N-n2-1);
F_alpha=finv(1-alpha,v1,v2);
% finv is a function in the Statistics Toolbox
% Inverse of the F cumulative distribution function
if Fx<F_alpha
break;
end
end
if Fx<F_alpha
polynomial_degree=k-2;
else
polynomial_degree=k_end;
end
end
1 个评论
Jan
2018-2-5
@sarmad m: Is this the unchanged code from FileExchange: adpf_diff? Then please delete it or append the license text. See Answers: republish code from FileExchange .
what should be changed in order to use it for my case
How could the readers know this? What is the difference between "your case" and the standard input for this function?
回答(1 个)
Image Analyst
2018-2-2
Put some code at the top of it to define, or read in, your x and y data.
3 个评论
Image Analyst
2018-2-4
Make it EASY for me to help you. csvread() did not work with your data and it's all in one column anyway so I don't know what's x and what's y. Please give me the code to read in your data file and create x and y. If you wait for me to do it, it might not be until tomorrow or later, if ever.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!