function [varargout] = wavefilter(wname,type)
%wavefilter函数创建分解和重建滤波器
% [varargout] = wavefilter(wname,type)返回用于计算快速小波变
% 换和反变换的分解和\或重建滤波器
%
% 例如:
% [ld,hd,lr,hr] = wavefilter('haar') 获取‘Haar’小波的分解
% 高通和低通滤波器(ld,hd)
% 及其重构高通和低通滤波器
% (lr,hr)
% [ld,hd] = wavefilter('Haar','d') 获取分解滤波器(ld,hd)
% [lr,hr] = wavefilter('Haar','r') 获取重构滤波器(ld,hd)
%
% INPUTS:
% WNAME WAVELET NAME
% --------------------------------------------------------
% 'Haar'or 'db1' Haar
% 'db4' 4th order Daubechies
% 'sym4' 4th order symlets
% 'bior6.8' Cohen-Daubechies-Feauveau biorhogonal
% 'jpeg9.7' Antonini-Barlaud-Mathieu-Daubechies
%
% TYPE FILTER TYPE
% --------------------------------------------------------
% 'd' Decomposition filters
% 'r' Reconstruction filters
%
% See also WAVEFAST and WAVEBACK.
% Check the input and output arguments.
error(nargchk(1,2,nargin));
if(nargin == 1 & nargout ~= 4)|(nargin == 2 & nargout ~= 2)
error('输出变量的数量错误。')
end
if nargin == 1 & ~ischar(wname)
error('WNAME必须是字符串')
end
if nargin == 2 & ~ischar(type)
error('TYPE必须是字符串')
end
% 创建所需小波的滤波器
switch lower(wname)
case{'haar','db1'}
ld = [1 1]/sqrt(2);
hd = [-1 1]/sqrt(2);
lr = ld;
hr = -hd;
case 'db2'
ld = [-0.1294 0.2241 0.8365 0.4830];
hd = [-0.4830 0.8365 -0.2241 -0.1294];
lr = [0.4830 0.8365 0.2241 -0.1294];
hr = [-0.1294 -0.2241 0.8365 -0.4830];
case 'db3'
ld = [0.0352 -0.0854 -0.1350 0.4599 0.8069 0.3327];
hd = [-0.3327 0.8069 -0.4599 -0.1350 0.0854 0.0352];
lr = [0.3327 0.8069 0.4599 -0.1350 -0.0854 0.0352];
hr = [0.0352 0.0854 -0.1350 -0.4599 0.8069 -0.3327];
case'db4'
ld = [-1.059740178499728e-002 3.288301166698295e-002 ...
3.084138183598697e-002 -1.870348117188811e-001 ...
-2.798376941698385e-002 6.308807679295904e-001 ...
7.148465705525415e-001 2.303778133088552e-001];
t = (0:7);
hd = ld;
hd(end:-1:1) = cos(pi*t).*ld;
lr = ld;
lr(end:-1:1) = ld;
hr = cos(pi*t).*ld;
case 'coif1'
ld = [-0.0157 -0.0727 0.3849 0.8526 0.3379 -0.0727];
hd = [0.0727 0.3379 -0.8526 0.3849 0.0727 -0.0157];
lr = [-0.0727 0.3379 0.8526 0.3849 -0.0727 -0.0157];
hr = [-0.0157 0.0727 0.3849 -0.8526 0.3379 0.0727];
case 'coif2'
ld = [-0.0007 -0.0018 0.0056 0.0237 -0.0594 -0.0765...
0.4170 0.8127 0.3861 -0.0674 -0.0415 0.0164];
hd = [-0.0164 -0.0415 0.0674 0.3861 -0.8127 0.4170...
0.0765 -0.0594 -0.0237 0.0056 0.0018 -0.0007];
lr = [0.0164 -0.0415 -0.0674 0.3861 0.8127 0.4170...
-0.0765 -0.0594 0.0237 0.0056 -0.0018 -0.0007];
hr = [-0.0007 0.0018 0.0056 -0.0237 -0.0594 0.0765 ...
0.4170 -0.8127 0.3861 0.0674 -0.0415 -0.0164 ];
case 'coif3'
ld = [-0.0000 -0.0001 0.0005 0.0011 -0.0026 -0.0090...
0.0159 0.0346 -0.0823 -0.0718 0.4285 0.7938...
0.4052 -0.0611 -0.0658 0.0235 0.0078 -0.0038];
hd = [0.0038 0.0078 -0.0235 -0.0658 0.0611 0.4052...
-0.7938 0.4285 0.0718 -0.0823 -0.0346 0.0159...
0.0090 -0.0026 -0.0011 0.0005 0.0001-0.0000];
lr = [-0.0038 0.0078 0.0235 -0.0658 -0.0611 0.4052...
0.7938 0.4285 -0.0718 -0.0823 0.0346 0.0159...
-0.0090 -0.0026 0.0011 0.0005 -0.0001 -0.0000];
hr = [-0.0000 0.0001 0.0005 -0.0011 -0.0026 0.0090...
0.0159 -0.0346 -0.0823 0.0718 0.4285 -0.7938...
0.4052 0.0611 -0.0658 -0.0235 0.0078 0.0038];
case 'sym4'
ld = [-7.576571478927333e-002 -2.963552764599851e-002 ...
4.976186676320155e-001 8.037387518059161e-001 ...
2.978577956052774e-001 -9.921954357684722e-002 ...
-1.260396726203783e-002 3.222310060404270e-002];
t = (0:7);
hd = ld;
hd(end:-1:1) = cos(pi*t).*ld;
lr = ld;
lr(end:-1:1) = ld;
hr = cos(pi*t).*ld;
case'bior6.8'
ld = [0 1.908831736481291e-003 -1.914286129088767e-003 ...
-1.699063986760234e-002 1.193456527972926e-002 ...
4.973290349094079e-002 -7.726317316720414e-002 ...
-9.405920349573646e-002 4.207962846098268e-001 ...
8.259229974584023e-001 4.207962846098268e-001 ...
-9.405920349573646e-002 -7.7263173167204143e-002 ...
4.973290349094079e-002 1.193456527972926e-002 ...
-1.699063986760234e-002 -1.914286129088767e-003 ...
1.908831736481291e-003];
hd = [0 0 0 1.442628250562444e-002 -1.446750489679015e-002 ...
-7.872200106262882e-002 4.036797903033992e-002 ...
4.178491091502746e-001 -7.589077294536542e-001 ...
4.178491091502746e-001 4.036797903033992e-002 ...
-7.872200106262882e-002 -1.446750489679015e-002 ...
1.442628250562444e-002 0 0 0];
t = (0:17);
lr = cos(pi*(t+1)).*hd;
hr = cos(pi*t).*ld;
case'jpeg9.7'
ld = [0 0.02674875741080976 -0.01686411844287495 ...
-0.07822326652898785 0.2668641184428723 ...
0.6029490182363579 0.2668641184428723 ...
-0.07822326652898785 -0.01686411844287495 ...
0.02674875741080976];
hd = [0 -0.09127176311424948 ...
0.05754352622849957 0.5912717631142470...
-1.115087052456994 0.5912717631142470 ...
0.05754352622849957 -0.09127176311424948...
0 0];
t = (0:9);
lr = cos(pi*(t+1)).*hd;
hr = cos(pi*t).*ld;
otherwise
error('不能识别的小波名称(WNAME)。');
end
% 输出所需滤波器
if(nargin == 1)
varagout(1:4) = {ld,hd,lr,hr};
else
switch lower(type(1))
case 'd'
varargout = {ld,hd};
case 'r'
varargout = {lr,hr};
otherwise
error('不能识别的滤波器类型TYPE。');
end
end