?? dwt_1d.m
字號:
%% 本程序用Mallat算法實現小波變換
%% 編程人 沙威(Wei Sha) 安徽大學(Anhui University) ws108@ahu.edu.cn
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('Signal')
subplot(2,1,2)
stem(abs(fft(y)));
title('Amplitude Spectrum')
%% 2.小波濾波器譜分析
h=wfilters('db30','l'); % 低通
g=wfilters('db30','h'); % 高通
h=[h,zeros(1,N-length(h))]; % 補零(圓周卷積,且增大分辨率變于觀察)
g=[g,zeros(1,N-length(g))]; % 補零(圓周卷積,且增大分辨率變于觀察)
figure(3);
subplot(2,1,1)
stem(abs(fft(h)));
title('Low-pass Filter(V_{0})')
subplot(2,1,2)
stem(abs(fft(g)));
title('High-pass Filter(W_{0})')
% 3.MALLET分解算法(圓周卷積的快速傅里葉變換實現)
sig1=ifft(fft(y).*fft(h)); % 低通(低頻分量)
sig2=ifft(fft(y).*fft(g)); % 高通(高頻分量)
figure(5); % 信號圖
subplot(2,1,1)
plot(real(sig1));
title('Low-frequency Component')
subplot(2,1,2)
plot(real(sig2));
title('High-frequency Component')
figure(6); % 頻譜圖
subplot(2,1,1)
stem(abs(fft(sig1)));
title('Amplitude Spectrum of Low-frequency Component')
subplot(2,1,2)
stem(abs(fft(sig2)));
title('Amplitude Spectrum of High-frequency Component')
%% 4.MALLET重構算法
sig1=dyaddown(sig1); % 2抽取
sig2=dyaddown(sig2); % 2抽取
sig1=dyadup(sig1); % 2插值
sig2=dyadup(sig2); % 2插值
sig1=sig1(1,[1:N]); % 去掉最后一個零
sig2=sig2(1,[1:N]); % 去掉最后一個零
hr=h(end:-1:1); % 重構低通
gr=g(end:-1:1); % 重構高通
hr=circshift(hr',1)'; % 位置調整圓周右移一位
gr=circshift(gr',1)'; % 位置調整圓周右移一位
sig1=ifft(fft(hr).*fft(sig1)); % 低頻
sig2=ifft(fft(gr).*fft(sig2)); % 高頻
sig=sig1+sig2; % 源信號
%% 5.比較
figure(7);
subplot(2,1,1)
plot(real(sig1));
title('Reconstructed Low-frequency Signal');
subplot(2,1,2)
plot(real(sig2));
title('Reconstructed High-frequency Signal');
figure(8);
subplot(2,1,1)
stem(abs(fft(sig1)));
title('Spectra of the Reconstructed Low-frequency Signal');
subplot(2,1,2)
stem(abs(fft(sig2)));
title('Spectra of the Reconstructed High-frequency Signal');
figure(9)
plot(real(sig),'r','linewidth',2);
hold on;
plot(y);
legend('Reconstructed Signal','Original Signal')
title('Comparisons between Original Signal and Reconstructed Signal')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -