clear
X = sin(0:pi/1000:3*pi); % 产生正弦信号
Y = awgn(X,10,'measured'); % 加入信噪比为10db的噪声,加入前预估信号的功率(强度)
y=Y-X;
[c,l]=wavedec(y,5,'sym4');
plot(y)
% a6=appcoef('a',c,1,'db3',6);
a5=appcoef(c,l,'sym4',5);
a4=appcoef(c,l,'sym4',4);
a3=appcoef(c,l,'sym4',3);
a2=appcoef(c,l,'sym4',3);
a1=appcoef(c,l,'sym4',1);
d=detcoef(c,l,'sym4',5);;
d5=d{1,5};
d4=d{1,4};
d3=d{1,3};
d2=d{1,2};
d1=d{1,1};
figure(2)
subplot(6,2,1);plot(y);ylabel('幅值');
hold on
% title('原始信号与低频近似系数')
subplot(6,2,2);plot(y);ylabel('幅值');
% % title('原始信号与高频细节系数')
subplot(6,2,3);plot(a1);ylabel('a1');
subplot(6,2,4);plot(d1);ylabel('d1');
subplot(6,2,5);plot(a2);ylabel('a2');
subplot(6,2,6);plot(d2);ylabel('d2');
subplot(6,2,7);plot(a3);ylabel('a3');
subplot(6,2,8);plot(d3);ylabel('d3');
subplot(6,2,9);plot(a4);ylabel('a4');
subplot(6,2,10);plot(d4);ylabel('d4');
subplot(6,2,11);plot(a5);ylabel('a5');
subplot(6,2,12);plot(d5);ylabel('d5');
for i=1:1:5
j=j+1;
a=appcoef(c,l,'sym4',i);
d=detcoef(c,l,'sym4',i);
subplot(12,2,j)
plot(a);
% ylabel(['a',num2str(i)]);
j=j+1;
subplot(12,2,j)
plot(d(1,1));
% ylabel(['d',num2str(i)]);
end
for i=2:2:10
aecmp[i]=detcoef(c,l,'sym4',i);
end
for i=1:1:10
aecmp[i]=detcoef(c,l,'sym4',i);
subplot(10,2,j)
plot(aecmp[i])
% ylabel(['a',num2str(i)]);
end
decmp=detcoef(c,l,'sym4',i);
subplot(12,2,j)
plot(decmp)
ylabel(['d',num2str(i)]);
title('用sym4小波分解7层系数')