利用连续小波变换函数cwt对带白噪声的正弦信号及正弦加三角波进行变换。在对这两组信号利用wavedec函数及db5进行5层和6层的分解,并利用wrcoef函数对低频和高频分别进行重构。
时间: 2024-02-17 17:04:35 浏览: 32
以下是使用MATLAB编写的代码,实现对带白噪声的正弦信号及正弦加三角波进行连续小波变换、5层和6层分解及重构的操作。
```matlab
% 生成带白噪声的正弦信号
t = 0:0.01:10;
x = sin(2*pi*5*t) + wgn(size(t), 1, 0);
% 进行连续小波变换
[cfs,f] = cwt(x,'bump',0.01);
figure;
subplot(2,1,1);
plot(t,x);
title('原始信号');
subplot(2,1,2);
contourf(t,f,abs(cfs));
title('连续小波变换');
% 对信号进行5层和6层分解
[c,l] = wavedec(x,6,'db5');
a6 = wrcoef('a',c,l,'db5',6);
d6 = wrcoef('d',c,l,'db5',6);
a5 = wrcoef('a',c,l,'db5',5);
d5 = wrcoef('d',c,l,'db5',5);
a4 = wrcoef('a',c,l,'db5',4);
d4 = wrcoef('d',c,l,'db5',4);
a3 = wrcoef('a',c,l,'db5',3);
d3 = wrcoef('d',c,l,'db5',3);
a2 = wrcoef('a',c,l,'db5',2);
d2 = wrcoef('d',c,l,'db5',2);
a1 = wrcoef('a',c,l,'db5',1);
d1 = wrcoef('d',c,l,'db5',1);
% 对低频和高频分别重构
x_rec5 = idwt(a5,d5,'db5');
x_rec6 = idwt(a6,d6,'db5');
figure;
subplot(2,1,1);
plot(t,x);
title('原始信号');
subplot(2,1,2);
plot(t,x_rec5);
title('5层分解重构');
figure;
subplot(2,1,1);
plot(t,x);
title('原始信号');
subplot(2,1,2);
plot(t,x_rec6);
title('6层分解重构');
% 生成正弦加三角波信号
t = 0:0.01:10;
x = sin(2*pi*5*t) + sawtooth(2*pi*2*t);
% 进行连续小波变换
[cfs,f] = cwt(x,'bump',0.01);
figure;
subplot(2,1,1);
plot(t,x);
title('原始信号');
subplot(2,1,2);
contourf(t,f,abs(cfs));
title('连续小波变换');
% 对信号进行5层和6层分解
[c,l] = wavedec(x,6,'db5');
a6 = wrcoef('a',c,l,'db5',6);
d6 = wrcoef('d',c,l,'db5',6);
a5 = wrcoef('a',c,l,'db5',5);
d5 = wrcoef('d',c,l,'db5',5);
a4 = wrcoef('a',c,l,'db5',4);
d4 = wrcoef('d',c,l,'db5',4);
a3 = wrcoef('a',c,l,'db5',3);
d3 = wrcoef('d',c,l,'db5',3);
a2 = wrcoef('a',c,l,'db5',2);
d2 = wrcoef('d',c,l,'db5',2);
a1 = wrcoef('a',c,l,'db5',1);
d1 = wrcoef('d',c,l,'db5',1);
% 对低频和高频分别重构
x_rec5 = idwt(a5,d5,'db5');
x_rec6 = idwt(a6,d6,'db5');
figure;
subplot(2,1,1);
plot(t,x);
title('原始信号');
subplot(2,1,2);
plot(t,x_rec5);
title('5层分解重构');
figure;
subplot(2,1,1);
plot(t,x);
title('原始信号');
subplot(2,1,2);
plot(t,x_rec6);
title('6层分解重构');
```
上述代码中,先生成带白噪声的正弦信号和正弦加三角波信号,并利用`cwt`函数进行连续小波变换,得到频率-时间矩阵。然后,分别利用`wavedec`函数对信号进行5层和6层的小波分解,得到低频和高频系数,再利用`wrcoef`函数对低频和高频分别进行重构。最后,将原始信号和重构后的信号进行对比,观察分解和重构的效果。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)