function [new_data,wavelet_power]=fliter(data,wavename) %'db5'
 
[a b] = size(data);
if(a>b); data=data'; end;           %data:n*N 导联*采样点

n=size(data,1);    %导联数目   
for i=1:n
%%%去噪
level=8;   
%%%%%%%%%%进行小波变换8层  
[C,L]=wavedec(data(i,:),level,wavename);  
%%%%%%%提取尺度系数，  
A1=appcoef(C,L,wavename,1);  
A2=appcoef(C,L,wavename,2);  
A3=appcoef(C,L,wavename,3);  
A4=appcoef(C,L,wavename,4);  
A5=appcoef(C,L,wavename,5);  
A6=appcoef(C,L,wavename,6);  
A7=appcoef(C,L,wavename,7);  
A8=appcoef(C,L,wavename,8);  
%%%%%%%提取细节系数  
D1=detcoef(C,L,1);  
D2=detcoef(C,L,2);  
D3=detcoef(C,L,3);  
D4=detcoef(C,L,4);  
D5=detcoef(C,L,5);  
D6=detcoef(C,L,6);  
D7=detcoef(C,L,7);  
D8=detcoef(C,L,8);  
%%%%%%%%%%%%重构  
A8=zeros(length(A8),1); %去除基线漂移,8层低频信息  
A8=A8';
RA7=idwt(A8,D8,wavename);  
RA6=idwt(RA7(1:length(D7)),D7,wavename);  
RA5=idwt(RA6(1:length(D6)),D6,wavename);  
RA4=idwt(RA5(1:length(D5)),D5,wavename);  
RA3=idwt(RA4(1:length(D4)),D4,wavename);  
RA2=idwt(RA3(1:length(D3)),D3,wavename);  
D2=zeros(length(D2),1);%去除高频噪声，2层高频噪声  
D2=D2';
RA1=idwt(RA2(1:length(D2)),D2,wavename);  
D1=zeros(length(D1),1);%去除高频噪声，1层高频噪声  
D1=D1';
y1=idwt(RA1(1:length(D1)),D1,wavename);  
new_data(i,:)= y1;  %去噪信号

%%%%%%%%%%提取能量特征
ED = [norm(D3)^2, norm(D4)^2, norm(D5)^2, norm(D6)^2, norm(D7)^2, norm(D8)^2];
EA = [norm(A1)^2, norm(A2)^2, norm(A3)^2, norm(A4)^2, norm(A5)^2, norm(A6)^2, norm(A7)^2];
E = sum(ED)+sum(EA);
wavelet_power = [ED,EA]./E;
end

