5.0

5.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 51.15 KB File ID: #6121

Adaptive-Degree Polynomial Filter (Savitzky-Golay Filter)

by Jianwen Luo

 

26 Oct 2004 (Updated 05 Nov 2004)

Obtain the polynomial degree selected in the adaptive-degree polynomial filter.

| Watch this File

File Information
Description

function polynomial_degree=adpf(data_frame)

Adaptive-Degree Polynomial Filter (Savitzky-Golay Filter)

Commonly, the degree of the fitting polynomial for the Savitzky-Golay filter is fixed. However, the polynomial degree can vary according to the sum of squares of fitting residuals and the statistical testing to obtain the adaptive-degree polynomial filter.

This function can be used to obtain the polynomial degree (output: polynomial_degree) selected in the adaptive-degree polynomial filter (Savitzky-Golay filter) for the data subset of length 2M+1 (intput: data_frame).

Usage:
Run Pkmi_Calculate first to obtain the numerical table of gram polynomials so as to accelerate the calculation.

Examples:
%Examples:
adpf_demo %A demo of data smoothing with the adaptive-degree polynomial filter
Fig_1 %Obtain figure 1 of Ref. [1]
Fig_2 %Obtain figure 2 of Ref. [1]

Author:
      Jianwen Luo <luojw@bme.tsinghua.edu.cn, luojw@ieee.org> 2004-10-26
      Department of Biomedical Engineering, Department of Electrical Engineering
      Tsinghua University, Beijing 100084, P. R. China

References:
[1] P. Barak,
"Smoothing and differentiation by an adaptive-degree polynomial filter," Analytical Chemistry, vol. 67, pp. 2758-2762, 1995.
[2] M. Jakubowska and W. W. Kubiak,
"Adaptive-degree polynomial filter for voltammetric signals," Analytica Chimica Acta, vol. 512, pp. 241-250, 2004.
[3] A. Savitzky and M. J. E. Golay,
"Smoothing and Differentiation of Data by Simplified Least Squares Procedures," Analytical Chemistry, vol. 36, pp. 1627-1639, 1964.
[4]P. A. Gorry,
"General Least-Squares Smoothing and Differentiation by the Convolution (Savitzky-Golay) Method," Analytical Chemistry, vol. 62, pp. 570-573, 1990.
[5] J. W. Luo, K. Ying, P. He and J. Bai,
¡°Properties of Savitzky-Golay digital differentiators,¡±
Digital Signal Processing, in press
[6] http://www.mathworks.com/matlabcentral/fileexchange/loadFileList.do?objectType=search&criteria=savitzky+or+sgolayfilt&Search=Go
[7] http://uk.cambridge.org/chemistry/resources/delevie/

Acknowledgements
This submission has inspired the following:
z-transform of 1D & 2D Savitzky-Golay Smoothing and Differentiation Filter
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
29 Oct 2004 Jianwen Luo

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Revision:

if N==3
    polynomial_degree=1;%%%%%%%%%%%%revised from 2
else
    k_start=1;% 0/1 for smoothing
    k_end=N-2;%%%%%%%%%%%revised from N-1-2
    k=k_start;
    p_fit=polyfit(x,y,k);%polynomial degree = k_start
    res_odd=sum((y-polyval(p_fit,x)).^2);
    
    Fxs=[];
    F_alphas=[];
    while k<k_end%%%%%%%%%%%%%revised from k<=k_end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Demo:
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

A=1;
x0s=[20 40 60 90];
ws=[1 2 4 8]*2;
dx=min(ws)/5;

x=0:dx:120;
y=0;
for k=1:length(x0s)
    x0=x0s(k);
    w=ws(k);
    y1=A*exp(-4*log(2)*(x-x0).^2/w^2);
    y=y+y1;
end

yn=y+randn(size(y))*0.2;

figure
plot(x,y,'r');
hold on
plot(x,yn,'m')
title('data');

m=10;
hs=zeros(2*m,2*m+1);
for deg=1:2*m
    hs(deg,1:2*m+1)=sgsdf_smooth_closed_form(deg,m);
end

degs=[];
y_adpf=[];
for k=m+1:length(yn)-m
    k
    y1=yn(k-m:k+m);
    deg=adpf(y1);
    degs=[degs deg];
    h=hs(deg,:);
    
    y_adpf=[y_adpf block_oper(y1,h)];
end

figure
plot(x,y,'r')
hold on
plot(x(m+1:end-m),y_adpf);
title('adaptive degree')

figure
stem(x(m+1:end-m),degs);
title('polynomial degree');

for deg=1:2:7
    h=hs(deg,:);
    y_smoothed=block_oper(yn,h);
    figure
    plot(x,y,'r');
    hold on
    plot(x(m+1:end-m),y_smoothed);
    title(sprintf('polynomial degree = %d',deg));
end

29 Oct 2004 Jianwen Luo

See all the contributions about the Savitzky-Goaly filter in MATLAB Central File Exchange at http://www.mathworks.com/matlabcentral/fileexchange/loadFileList.do?objectType=search&criteria=savitzky+or+sgolayfilt&Search=Go

06 Jan 2005 nabhan-1 A. HAMDON  
Please login to add a comment or rating.
Updates
29 Oct 2004

Minor revision for the maximum polynomial degree and some others. In addition, a demo is added.

05 Nov 2004

A .zip file instead of a .rar file. for file consistency in File Exchange.

Tag Activity for this File
Tag Applied By Date/Time
filter design Jianwen Luo 22 Oct 2008 07:34:11
filter analysis Jianwen Luo 22 Oct 2008 07:34:11
savitzkygolay filter Jianwen Luo 22 Oct 2008 07:34:11
polynomial filter Jianwen Luo 22 Oct 2008 07:34:11
adaptive Jianwen Luo 22 Oct 2008 07:34:11
smoothing Jianwen Luo 22 Oct 2008 07:34:11

Contact us at files@mathworks.com