§3.9一维小波变换举例
%%%一维小波变换举例%%%
load leleccum % load double array s=leleccum(1:3920)
%% 使用dwt函数实现“单尺度一维离散小波变换”
subplot(1,3,1), plot(s) % plot signal s title('source signal')
[ca1,cd1]=dwt(s,'db1') % 用dwt函数使用指定的小波基函数实现一维离
% 散小波变换,ca1和cd1分别为分解得到的近似分% 量和细节分量,db1是daubechies小波
subplot(1,3,2), plot(ca1)
title('approximation coefficients vector') subplot(1,3,3), plot(cd1)
1
title('deail coefficients vector ')
% % Plot one-D source signal: leleccum
figure,plot(s)
title('leleccum: one-dimension')
% % Plot end
% % 调用upcoef函数,根据近似(低频)分量和细节(高频)分量进行重构
ls=length(s) % LENGTH(X) returns the length of vector X. It is equivalent % to MAX(SIZE(X)) for non-empty arrays and 0 for empty one a1=upcoef('a',ca1,'db1',1,ls) % 调用upcoef函数进行一维系数直接重构 d1=upcoef('d',cd1,'db1',1,ls) figure,plot(a1+d1)
title('Direct reconstruction from 1-D wavelet coefficients')
2
%% 结果表明重构没有出现误差 %%%一维小波变换举例结束%%%
3
(a) Time series of El Niño sea surface temperature. (b) The wavelet power spectrum, using the Morlet wavelet. The x-axis is the wavelet location in time. The y-axis is the wavelet period in years. The black contours are the 10% significance regions, using a red-noise background spectrum. The red areas indicate that high El Niño activity occurred during 1880-1920 and
1965-present, while 1920-1960 was relatively calm.
the Morlet wavelet:
We are given a time series X, with values of n at time index n. Each value is separated in time by a constant time interval dt. The wavelet transform Wn(s) is just the inner product (or convolution) of the wavelet function with our original time series:
x,
(2.3) . . . . . . . . . .
where the asterisk (*) denotes complex conjugate.
4
%%%利用小波进行图像压缩%%%
load woman
y=woman(100:200,100:200) figure,subplot(1,3,1),image(y)
%利用全局域值对图像进行小波变换压缩,并对压缩后的图像进行二维重构变 n=5,w='sym2'
[c,l]=wavedec2(y,n,w)
%Multilevel 2-D wavelet decomposition,进行矩阵y在n级上的小波分解;
%Outputs are the decomposition vector C and the corresponding bookkeeping matrix S;
%n must be a strictly positive integer.w is the wavelet name given by you.
% you can give the filters. %%%%%%%%more
%For [C,S] = wavedec2(X,N,Lo_D,Hi_D), Lo_D is the decomposition low-pass filter
%and Hi_D is the decomposition high-pass filter. % Vector C is organized as
% C = [ A(N) | H(N) | V(N) | D(N) | ...
5
% H(N-1) | V(N-1) | D(N-1) | ... | H(1) | V(1) | D(1) ]. %where A, H, V, D, are row vectors such that % A = approximation coefficients % H = horizontal detail coefficients % V = vertical detail coefficients % D = diagonal detail coefficients
%Each vector is the vector column-wise storage of a matrix. %Matrix S is such that
% S(1,:) = size of approximation coefficients(N)
% S(i,:) = size of detail coefficients(N-i+2) for i = 2, ...N+1 %and S(N+2,:) = size(X)
thr=20
[xd,cxd,lxd,perf0,perfl2]=wdencmp('gbl',c,l,w,n,thr,'h',l) figure, subplot(1,3,2),image(xd) %重构结束
MATLAB Wavelet工具箱关于两维小波变换的DEMO:
6
7