
function [output,new]=smoth_filter(input,k,L)
%%%%%平滑滤波器（可用于去大趋势）
%%%%%output为去趋势后的信号，new为趋势
%%%%%input为输入信号，k为滤波器阶数，L为单边长度，拟合点数为2*L+1

b=sgolay(k,2*L+1);%sgolay(k,f),k为阶数，f是拟合的双边点数，必须是奇数
new=zeros(1,length(input));
bstart=b(1:L,:);
temp=input(1:2*L+1)';
newstart=bstart*temp;
newstart=newstart';
new(1:L)=newstart;
bend=b(L+2:end,:);
temp=input(end-2*L:end)';
newend=bend*temp;
newend=newend';
new(end-L+1:end)=newend;
temp=conv(input,b(L+1,:));
new(L+1:end-L)=temp(2*L+1:end-2*L);
output=input-new;
end
