一维信号小波去噪——瞎实操系列

目录

一、code实现

二、GUI实现--Wavelet Analyzer

 


一、code实现

小波进行滤波就是一个小波分解和重构的过程,其基本步骤如下:

% 读数据
load('slp02a.mat');
normal=sig(1:5000,3)';
figure;
plot(normal,'r')
title('Sigal')
legend('normal')
  • 选择合适的小波基函数、对信号进行指定层次的小波分解
figure;
[c1,l1]=wavedec(normal,4,'db6');             %wavedec 小波分解
approx=appcoef(c1,l1,'db6');                 %appcoef 近似系数
[cd1,cd2,cd3,cd4]=detcoef(c1,l1,[1,2,3,4]);  %detcoef 细节系数
subplot(5,1,1)
plot(approx)
title('Approximation Coefficients-Normal')
subplot(5,1,2)
plot(cd4)
title('Level 4 Detail Coefficients-Normal')
subplot(5,1,3)
plot(cd3)
title('Level 3 Detail Coefficients-Normal')
subplot(5,1,4)
plot(cd2)
title('Level 2 Detail Coefficients-Normal')
subplot(5,1,5)
plot(cd1)
title('Level 1 Detail Coefficients-Normal')
  •  对各分解层进行处理、重构
sd1=zeros(1,length(cd1)); 
sd2=zeros(1,length(cd2));      %1-2层置0,3-4层用软阈值函数处理 
sd3=wthresh(cd3,'s',0.006); 
sd4=wthresh(cd4,'s',0.014); 
c2=[approx,sd4,sd3,sd2,sd1]; 
s0=waverec(c2,L,'db6');                 %小波重构 
  •  原信号与重构信号进行时频域对比
figure; %画图
plot(normal,'g');hold on 
plot(s0,'r');legend('before','after');hold off;

t_start = 0;
t_end = 0.5*60*20*3;
sample_rate = 250;      %读采样率
Sampling_points = (t_end - t_start)*sample_rate;
%原信号频谱
y1 = normal; 
fs=250;                       %采样频率
df=fs/(Sampling_points-1) ;   %分辨率
f=(0:Sampling_points-1)*df;   %其中每点的频率
Y1=fft(y1)/Sampling_points*2;   %真实的幅值
figure;
subplot(2,1,1)
plot(f(1:Sampling_points/2),abs(Y1(1:Sampling_points/2)));
%处理过后信号频谱
y2 = s0;
Y2=fft(y2)/Sampling_points*2;   %真实的幅值
subplot(2,1,2)
plot(f(1:Sampling_points/2),abs(Y2(1:Sampling_points/2)));
  • 为选取合适消失矩,可设置评估参数进行多次试验
load('slp02a_denoise.mat');
s0 = slp02a_denoise;
%平均误差
sub = normal - s0;
sub_mean= mean(sub);

%MSE
MSE = sum(sub(:).*sub(:))/numel(sub);%  均方根误差MSE,numel()函数返回矩阵元素个数

%SNR
Ps=sum(sum((s0-mean(mean(s0))).^2)); %signal power
Pn=sum(sum((s0-normal).^2));            %noise power
snr=10*log10(Ps/Pn);

 

二、GUI实现--Wavelet Analyzer

DWT:用于去噪、图片压缩

绘制小波函数和尺度函数:

没显示4层是因为,这里只能显示5层及以上的(不知道为啥)

尺度函数=上一层尺度函数+上一层小波函数

正式开始滤波: 

导入数据:File-Import from Workspace-Import Signal

部分选项设置

界面如图所示

↑ 两条虚线中间的都会被滤除。其中虚线阈值可以手动调,而且四个分解结果,每个都可以分段调阈值

更正:“最大频率”应改为“采样频率”

↑ 残差的直方图,看起来符合白噪声的概率密度函数即正态分布;自相关程度不大

衡量消噪信号与原信号的相似性,有几个衡量指标:如残差的标准差(standard.dev)、残差的绝对偏差(mean abs. dev.)、残差模数(L2 norm)或消噪信号与原信号的模数比。指数越小表示相似程度越高,即越不光滑

 

=====================================================================

参考资料:GUI界面一维小波消噪

 

  • 3
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值