wave_soft_hard_threshold.m

来自「主要用来对钢丝绳漏磁检测信号进行消噪处理」· M 代码 · 共 59 行

M
59
字号
%装载采集的信号wirerope.mat
file4_29=['f:\9_4_29_3.xls'];
x4_29_3=xlsread(file4_29);
wirerope=x4_29_3;
save wirerope;
load wirerope;
%=============================
%将信号中第4500到第27000个采样点赋给s
indx=15600:55000;
s=wirerope(indx);
%=============================
%画出原始信号
subplot(3,1,1);
plot(s);
title('原始信号');

%=============================
%=============================
%=============================
%用db1小波对原始信号进行6层分解并提取系数
[c,l]=wavedec(s,6,'sym12');
a6=appcoef(c,l,'sym12',6);
d6=detcoef(c,l,6);
d5=detcoef(c,l,5);
d4=detcoef(c,l,4);
d3=detcoef(c,l,3);
d2=detcoef(c,l,2);
d1=detcoef(c,l,1);
%=============================
%软阈值进行消噪处理
thr1=thselect(d1,'sqtwolog');%选择固定阈值
thr2=thselect(d2,'sqtwolog');
thr3=thselect(d3,'sqtwolog');%选择固定阈值
thr4=thselect(d4,'sqtwolog');
thr5=thselect(d5,'sqtwolog');%选择固定阈值
thr6=thselect(d6,'sqtwolog');
%用给定的软阈值进行消噪处理
softd1=wthresh(d1,'s',thr1);
softd2=wthresh(d2,'s',thr2);
softd3=wthresh(d3,'s',thr3);
softd4=wthresh(d1,'s',thr4);
softd5=wthresh(d2,'s',thr5);
softd6=wthresh(d3,'s',thr6);
c2=[a6 softd6 softd5 softd4 softd3 softd2 softd1];
s3=waverec(c2,l,'sym12');
subplot(3,1,2);
plot(s3);grid;
title('给定软阈值消噪后的信号');
%硬阈值进行消噪
softd1=wthresh(d1,'h',thr1);
softd2=wthresh(d2,'h',thr2);
softd3=wthresh(d3,'h',thr3);
softd4=wthresh(d1,'h',thr4);
softd5=wthresh(d2,'h',thr5);
softd6=wthresh(d3,'h',thr6);
c3=[a6 softd6 softd5 softd4 softd3 softd2 softd1];
s4=waverec(c3,l,'sym12');
subplot(3,1,3);
plot(s4);grid;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?