from Adaptive-Degree Polynomial Filter (Savitzky-Golay Filter) by Jianwen Luo
Obtain the polynomial degree selected in the adaptive-degree polynomial filter.

Fig_2.m
clear
global Pkmi_array
if exist('Pkmi_array.mat','file')
    load Pkmi_array
else
    error('Please run Pkmi_Calculate first to obtain the numerical table of gram polynomials!')
end


u=0;
sigma=15;
x=-55:55;
y=exp(-(x-u).^2/(2*sigma^2));

figure
for p=0:9
    height=[];
    for m=ceil(p/2):ceil((3*2.35*sigma-1)/2)
        h=sgsdf_smooth_closed_form(p,m);
        result=max(block_oper(y,h));
        height=[height result(1)];
    end
    
    plot(((ceil(p/2):ceil((3*2.35*sigma-1)/2))*2+1)/(2.35*sigma),height,'m-o');
    hold on
end
xlim([0,3.0]);
ylim([0.65,1.05]);

height=[];
for m=2:53
    
    m
    hs=zeros(2*m,2*m+1);
    for p=1:min([2*m 100])
        hs(p,1:2*m+1)=sgsdf_smooth_closed_form(p,m);
    end
    
    result=[];
    for y1_index=m+1:length(y)-m
        y1=y(y1_index-m:y1_index+m);
        p=adpf(y1);         
        h=hs(p,1:2*m+1);
        result=[result y1*h'];
    end        
    result=max(result);
    height=[height result(1)];
end
plot(((2:m)*2+1)/(2.35*sigma),height,'r-s');

Contact us at files@mathworks.com