fid = fopen ( 'C:\MATLAB7\work\30.19.txt','rt');a=fscanf(fid,'%f');s=a(1:12000);ls=length(s);figure(1);subplot(221);plot(s);Ylabel('s');title('原始信号');grid;[c,l]=wavedec(s,3,'db1'); %采用db1小波并对信号进行三层分解\x0bca3=appcoef

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 08:54:28
fid=fopen(''C:\MATLAB7\work\30.19.txt'',''rt'');a=fscanf(fid,''%f'');s=a(1:12000);ls=length(s);figure(1);s

fid = fopen ( 'C:\MATLAB7\work\30.19.txt','rt');a=fscanf(fid,'%f');s=a(1:12000);ls=length(s);figure(1);subplot(221);plot(s);Ylabel('s');title('原始信号');grid;[c,l]=wavedec(s,3,'db1'); %采用db1小波并对信号进行三层分解\x0bca3=appcoef
fid = fopen ( 'C:\MATLAB7\work\30.19.txt','rt');
a=fscanf(fid,'%f');
s=a(1:12000);
ls=length(s);
figure(1);
subplot(221);
plot(s);
Ylabel('s');
title('原始信号');
grid;
[c,l]=wavedec(s,3,'db1'); %采用db1小波并对信号进行三层分解\x0b
ca3=appcoef(c,l,'db1',3); %提取小波分解的低频系数\x0b
cd3=detcoef(c,l,3); %提取第三层的高频系数\x0b
cd2=detcoef(c,l,2); %提取第二层的高频系数\x0b
cd1=detcoef(c,l,1); %提取第一层的高频系数\x0b
%下面对信号进行强制消噪处理\x0b
cdd3=zeros(1,length(cd3));
cdd2=zeros(1,length(cd2));
cdd1=zeros(1,length(cd1));
c1=[ca3,cdd3,cdd2,cdd1];
s1=waverec(c1,l,'db1');%〔c1,l〕为新的分解结构\x0b
subplot(222);
plot(s1);%画出对信号进行强制消噪的波形图\x0b
title('强制消噪波形图');
grid;
%下面利用默认阈值进行消噪处理\x0b
%用ddencmp函数获得信号的默认阈值,使用wdencmp命令函数来实现消噪过程\x0b
[thr,sorh,keepapp]=ddencmp('den',wv',s);
s2=wdencmp('gbl',c,l,'db1',3,thr,sorh,keepapp);
subplot(223);
plot(s2);
title('默认阈值消噪后的信号');
grid;
%下面给定的软阈值进行消噪\x0b
cd1soft=wthresh(cd1,'s',1.456);%对第一层的高频系数,阈值取为1.456\x0b
cd2soft=wthresh(cd2,'s',1.832);%对第二层的高频系数,阈值取为1.832\x0b
cd3soft=wthresh(cd3,'s',2.786);%对第三层的高频系数,阈值取为2.786\x0b
c2=[ca3,cd3soft,cd2soft,cd1soft];
s3=waverec(c2,l,'db1');%〔c2,l〕为给定阈值量化后的分解结构\x0b
subplot(224);
plot(s3);
title('给定软阈值消噪后的信号');
grid;
Error using ==> horzcat
运行后报错:
All matrices on a row in the bracketed expression must have the
same number of rows.
Error in ==> xiaozao03 at 23
c1=[ca3,cdd3,cdd2,cdd1];

fid = fopen ( 'C:\MATLAB7\work\30.19.txt','rt');a=fscanf(fid,'%f');s=a(1:12000);ls=length(s);figure(1);subplot(221);plot(s);Ylabel('s');title('原始信号');grid;[c,l]=wavedec(s,3,'db1'); %采用db1小波并对信号进行三层分解\x0bca3=appcoef
All matrices on a row in the bracketed expression must have the
same number of rows.
按字面意思是,在括号中的表达式这一行,所有的数列必须有相同的行数.
括号里的表达式可能指这个:c1=[ca3,cdd3,cdd2,cdd1];
错误行数发生在23行 xiaozao03参数.

发错地方了吧