?? mallatsuanfa.m
字號:
%%本程序采用Mallat算法對信號進行小波分析
clc;clear;
%% 1.正弦小波定義
f1=50; %頻率1
f2=100; %頻率2
fs=2*(f1+f2); %采樣頻率
Ts=1/fs; %采樣時間間隔
N=120; %采樣點數(shù)
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 分解算法(圓周卷積的快速傅里葉變換實現(xiàn))
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重構(gòu)算法
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('重構(gòu)低頻信號');
% subplot(2,2,2)
% plot(real(sig2));
% title('重構(gòu)高頻信號');
% subplot(2,2,3)
% stem(abs(fft(sig1)));
% title('重構(gòu)低頻信號頻譜');
% subplot(2,2,4)
% stem(abs(fft(sig2)));
% title('重構(gòu)高頻信號頻譜');
figure(11);
plot(sig,'r','linewidth',1);
hold on;
plot(y);
legend('重構(gòu)信號','原始信號')
title('重構(gòu)信號與原始信號比較');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -