论坛里有,请参考一下
clear all
clc;
load('c:\temp\1.txt');
s1=X1;
fs=500000; %采样频率
t=1:max(size(s1));
t=1000*t./fs;
t=t';
plot(s1),title('plot(s1)'),grid on;
%axis([0,51.2,-10000,10000]);
xlabel('时间(t) 单位:ms');
ylabel('电压(V)');
title('原始信号');
%小波分解
[c,l]=wavedec(s1,4,'db4');
[cd1,cd2,cd3,cd4]=detcoef(c,l,[1 2 3 4]);
ca4=appcoef(c,l,'db4',4);
a4=wrcoef('a',c,l,'db4',4);
d4=wrcoef('d',c,l,'db4',4);
d3=wrcoef('d',c,l,'db4',3);
d2=wrcoef('d',c,l,'db4',2);
d1=wrcoef('d',c,l,'db4',1);
%不需要的系数置零
caa4=zeros(size(ca4));
%消噪后信号重构,并画图
cl=[caa4‘,cd4’,cd3‘,cd2’,cd1‘]
s2=waverec(cl,l,'db4');
figure(2);
plot(t,s2);title('消噪后重构信号');grid on; |