📄 mallatsuanfa.m
字号:
%%本程序采用Mallat算法对信号进行小波分析
clc;clear;
%% 1.正弦小波定义
f1=50; %频率1
f2=100; %频率2
fs=2*(f1+f2); %采样频率
Ts=1/fs; %采样时间间隔
N=120; %采样点数
n=1:N;
y=sin(2*pi*f1*n*Ts)+sin(2*pi*f2*n*Ts);
% figure(1)
% subplot(2,1,1)
% plot(y)
% title('原始信号')
% subplot(2,1,2)
% stem(abs(fft(y)));
% title('原始信号频谱')
%% 2.小波滤波器
h=wfilters('db30','l');
g=wfilters('db30','h');
% figure(5)
% subplot(2,1,1);
% plot(h);
% subplot(2,1,2);
% plot(g);
h=[h,zeros(1,N-length(h))];
g=[g,zeros(1,N-length(g))];
% figure(4)
% subplot(2,1,1);
% plot(h);
% subplot(2,1,2);
% plot(g);
% figure(2);
% subplot(2,1,1)
% stem(abs(fft(h)));
% title('分解低通滤波器频谱');
% subplot(2,1,2)
% stem(abs(fft(g)));
% title('分解高通滤波器频谱');
%% 3.MALLET 分解算法(圆周卷积的快速傅里叶变换实现)
sig1=ifft(fft(y).*fft(h));
sig2=ifft(fft(y).*fft(g));
% figure(3);
% subplot(2,2,1);
% plot(real(sig1));
% title('低频分量');
% subplot(2,2,2);
% plot(real(sig2));
% title('高频分量');
% subplot(2,2,3);
% stem(abs(fft(sig1)));
% title('低频分量频谱');
% subplot(2,2,4);
% stem(abs(fft(sig2)));
% title('高频分量频谱');
%% 4.MALLET重构算法
sig1=dyaddown(sig1);
sig2=dyaddown(sig2);
% figure(8);
% subplot(2,1,1);
% plot(sig1);
% subplot(2,1,2);
% plot(sig2);
sig1=dyadup(sig1);
sig2=dyadup(sig2);
% figure(9);
% subplot(2,1,1);
% plot(sig1);
% subplot(2,1,2);
% plot(sig2);
sig1=sig1(1,[1:N]);
sig2=sig2(1,[1:N]);
hr=h(end:-1:1);
gr=g(end:-1:1);
% figure(5)
% subplot(2,1,1);
% plot(hr);
% subplot(2,1,2);
% plot(gr);
hr=circshift(hr',1)';
gr=circshift(hr',1)';
% figure(6)
% subplot(2,1,1);
% plot(hr);
% subplot(2,1,2);
% plot(gr);
sig1=ifft(fft(hr).*fft(sig1));
sig2=ifft(fft(gr).*fft(sig2));
sig=sig1+sig2;
% figure(10);
% subplot(2,2,1)
% plot(real(sig1));
% title('重构低频信号');
% subplot(2,2,2)
% plot(real(sig2));
% title('重构高频信号');
% subplot(2,2,3)
% stem(abs(fft(sig1)));
% title('重构低频信号频谱');
% subplot(2,2,4)
% stem(abs(fft(sig2)));
% title('重构高频信号频谱');
figure(11);
plot(sig,'r','linewidth',1);
hold on;
plot(y);
legend('重构信号','原始信号')
title('重构信号与原始信号比较');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -