clear;
clc;
[S,fs,nbits]=wavread('C:\Users\HSF\Desktop\sound\beiyou.wav');
s=S(1:length(S));
figure(1)
subplot(311);
plot(s); ylabel('s');
title('原始信号');
axis tight;
[ca,cd]=dwt(s,'db2');%用db2小波函数进行一维离散小波变换
subplot(323);
plot(ca);ylabel('ca');
title('低频系数ca');
axis tight;
subplot(324);
plot(cd);ylabel('cd');
title('高频系数cd');
axis tight;
s1=idwt(ca,cd,'db2');%用db2小波函数进行信号重构
subplot(313);
plot(s1);ylabel('s1');
title('单尺度小波重构');
axis tight;
err=norm(s-s1);
[c,l]=wavedec(s,3,'db2');%用db2小波函数进行3尺度分解
ca3=appcoef(c,l,'db2',3);%从小波分解结构中[c,l]中提取低频系数
cd3=detcoef(c,l,3);%从小波分解结构中[c,l]中提取第1、2、3层低频系数
cd2=detcoef(c,l,2);
cd1=detcoef(c,l,1);
s2=waverec(c,l,'db2');
figure(2)
subplot(311);
plot(s); ylabel('s');
title('原始信号');
axis tight;
subplot(312);
plot(c); ylabel('c');
title('信号的3尺度小波分解结构');
axis tight;
subplot(313);
plot(s2); ylabel('s2');
title('多尺度小波重构');
axis tight;
err2=norm(s-s2);
仿真结果如下:
单尺度小波分解和重构
多尺度小波分解与重构