%采样频率
fs=12000;
load 1.mat;%故障
xdata=X224_BA_time(1:1024); xdata=(xdata-mean(xdata))/std(xdata,1);
%时域波形
figure(1);
N=1024;
plot(1:N,xdata,'k-');
xlabel('时间 t/n');
ylabel('电压 V/v');
%db10小波进行4层分解
%一维小波分解
[c,l]=wavedec(xdata,4,'db10');
%重构第1~4层细节信号
d4=wrcoef('d',c,l,'db10',4);
d3=wrcoef('d',c,l,'db10',3);
d2=wrcoef('d',c,l,'db10',2);
d1=wrcoef('d',c,l,'db10',1);
%显示细节信号
figure(2);
subplot(4,1,1);
plot(d4,'k-','LineWidth',2);
ylabel('d4');
subplot(4,1,2);
plot(d4,'k-','LineWidth',2);
ylabel('d3');
subplot(4,1,3);
plot(d4,'k-','LineWidth',2);
ylabel('d2');
subplot(4,1,4);
plot(d4,'k-','LineWidth',2);
ylabel('d1');
xlabel('时间 t/s');
%第1层细节信号的包络谱
y=hilbert(d1);
ydata=abs(y);
y=y-mean(y);
nfft=10240;
p=abs(fft(ydata,nfft));
figure(3);
plot((0:nfft/2- l)/nfft*fs,p(l:nfft/2),'k-');
xlabel('频率 f/Hz');
ylabel('功率谱 P/W');