clc;
clear;
load p2;
%Set the variables. Type
s = p2;
L_s = length(s);
dt = (1:L_s)/512;
%perform a level 5 decomposition of the signal (again using the db8 wavelet)
[C,L] = wavedec(s,5,'db8');
%To reconstruct the level 5 approximation from C
A5 = wrcoef('a',C,L,'db8',5);
%To reconstruct the details at levels 1, 2, and 3, from C
D1 = wrcoef('d',C,L,'db8',1);
D2 = wrcoef('d',C,L,'db8',2);
D3 = wrcoef('d',C,L,'db8',3);
D4 = wrcoef('d',C,L,'db8',4);
D5 = wrcoef('d',C,L,'db8',5);
%To display the results of the level 3 decomposition
figure(1);
subplot(2,3,1); plot(A5);
title('Approximation A5')
subplot(2,3,2); plot(D1);
title('Detail D1')
subplot(2,3,3); plot(D2);
title('Detail D2')
subplot(2,3,4); plot(D3);
title('Detail D3')
subplot(2,3,5); plot(D4);
title('Detail D4')
subplot(2,3,6); plot(D5);
title('Detail D5')
%to reconstruct the original signal from the wavelet decomposition structure
A0 = waverec(C,L,'db8');
err = s-A0;
%To compare the approximation to the original signal
figure(2);
%subplot(2,1,1);plot(s);title('Original'); %axis off
%subplot(2,1,2);plot(A5);title('Level 5 Approximation');%axis off
plot(dt,A5); %title('A5'); %axis off
xlabel('t /ms');
ylabel('A5 /MPa');
%subplot(3,1,3);plot(err);title('error');
%Remove noise by thresholding. Let's look again at the details of our level 3 analysis.
%To display the details D1, D2, and D3, type
figure(3);
subplot(5,1,1); plot(dt,D1); title('D1');
axis off
subplot(5,1,2); plot(dt,D2); title('D2');
axis off
subplot(5,1,3); plot(dt,D3); title('D3');
axis off
subplot(5,1,4); plot(dt,D4); title('D4');
axis off
subplot(5,1,5); plot(dt,D5); title('D5');
axis off
%correlation 计算自相关函数
c0 = xcorr(A5);
c1 = xcorr(D1);
c2 = xcorr(D2);
c3 = xcorr(D3);
c4 = xcorr(D4);
c5 = xcorr(D5);
figure(4);
dt2 = (-L_s+1 : L_s-1)/512;
subplot(2,3,1); plot(dt2,c0);
xlabel('t /ms');
ylabel('Correlation A5');
%title('Corr A5')
subplot(2,3,2); plot(dt2,c1);
xlabel('t /ms');
ylabel('Correlation D1');
%title('Corr D1')
subplot(2,3,3); plot(dt2,c2);
xlabel('t /ms');
ylabel('Correlation D2');
%title('Corr D2')
subplot(2,3,4); plot(dt2,c3);
xlabel('t /ms');
ylabel('Correlation D3');
%title('Corr D3')
subplot(2,3,5); plot(dt2,c4);
xlabel('t /ms');
ylabel('Correlation D4');
%title('Corr D4')
subplot(2,3,6); plot(dt2,c5);
ylabel('Correlation D5');
xlabel('t /ms');
%title('Corr D5')
%period signal detect
figure(5);
plot(c4); title('Corr D5')
%FFT
y0 = fft(A5);
Py0 = y0.*conj(y0) / L_s;
y1 = fft(D1);
Py1 = y1.*conj(y1) / L_s;
y2 = fft(D2);
Py2 = y2.*conj(y2) / L_s;
y3 = fft(D3);
Py3 = y3.*conj(y3) / L_s;
y4 = fft(D4);
Py4 = y4.*conj(y4) / L_s;
y5 = fft(D5);
Py5 = y5.*conj(y5) / L_s;
df = 512*(0:L_s/2-1)/L_s;
figure(6);
subplot(2,3,1); plot(df,Py0(1:L_s/2));
%title('FFT A5')
xlabel('\omega /kHz')
ylabel('A5功率谱');
subplot(2,3,2); plot(df,Py1(1:L_s/2));
xlabel('\omega /kHz')
ylabel('D1功率谱');%title('FFT D1')
subplot(2,3,3); plot(df,Py2(1:L_s/2));
xlabel('\omega /kHz')
ylabel('D2功率谱');%title('FFT D2')
subplot(2,3,4); plot(df,Py3(1:L_s/2));
xlabel('\omega /kHz')
ylabel('D3功率谱');%title('FFT D3')
subplot(2,3,5); plot(df,Py4(1:L_s/2));
xlabel('\omega /kHz')
ylabel('D4功率谱');%title('FFT D4')
subplot(2,3,6); plot(df,Py5(1:L_s/2));
xlabel('\omega /kHz')
ylabel('D5功率谱');%title('FFT D5')
figure(7);
plot(df,Py4(1:L_s/2));
figure(8);
plot(df,Py5(1:L_s/2));
% perform the actual de-noising, type
[thr,sorh,keepapp] = ddencmp('den','wv',s);
clean = wdencmp('gbl',C,L,'db8',5,thr,sorh,keepapp);
%To display both the original and de-noised signals, type
figure(9);
subplot(2,1,1); plot(s); title('Original')
subplot(2,1,2); plot(clean); title('De-noised');
%differentiate
for i = 1; L_s
t(i) = i;
end
deriv1 = diff(A5);
erro = s - A5;
figure(10);
%subplot(2,1,1); plot(deriv1); title('dP/dt')
%subplot(2,1,2); plot(erro); title('error');
plot(dt(1:L_s-1),deriv1); %title('dP/dt');
xlabel('t /ms');
ylabel('dP/dt /(MPa/ms)');
%fft of original signal
y0 = fft(s);
Py0 = y0.*conj(y0) / L_s;
plot(abs(y0));
xlabel('\omega /kHz')
ylabel('S 功率谱');
寒泊
- 粉丝: 85
- 资源: 1万+
最新资源
- Python API 包装器和库列表.zip
- Python - 与我的 YouTube 频道相关的脚本存储在这里,可以用任何版本的 Python 编写.zip
- PyClass 课程计划.zip
- Puppet 模块用于安装和管理 Python、pip、virtualenvs 和 Gunicorn 虚拟主机 .zip
- jieshao123456
- Java 将本地mp4推流rtsp
- 第7章 聚类算法 - 作业 - 副本.ipynb
- Gartner发布2024年中国网络安全发展趋势
- OpenStack 存储 (Swift) 客户端 代码镜像由 opendev.org 维护 .zip
- 四社区D栋 2.m4a
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈