📄 setf06.m
字号:
function ErrCode=SetF06(FrameFile,wname,Level,a)
% SetF06 Set F as a general filter bank, using initial values from a wavelet
% tree structured filter bank. The wavelet is made by GetWave.m
% The FrameFile will be of Type 'g'
% Also we will always have K==N (corresponds to critically sampled filter bank)
%
% ErrCode=SetF06(FrameFile,wname,Level,a);% -----------------------------------------------------------------------------------
% Arguments:
% ErrCode - 0 is returned if the function execute without error
% 1 an 'unexpected' error occurred, lasterr may explain it
% 2 or larger, another error occurred,
% FrameFile - the name of the mat-file used to store the frame
% wname - name of the wavelet filter, as used in wfilters.m
% also 'db79' for Daubechies 7-9 biorthogonal filter is possible
% Used as argument in GetWave.m
% Level - number of levels to use, use Level=1 to return just
% the synthesis filters
% Used as argument in GetWave.m
% a - indicate the kind of structure imposed on the filter bank
% this affect the G matrix
% 0 - all non-zero variables are free, but zeros are fixed
% a - a is a real number and 0<a<1, then [F,G]=BuildG(Fg,a)
% a should be small!
% 1 - all filter coefficients are free, mut equal filters are
% kept equal.
% a - a is a real number and 1<a<2, then BuildG(Fg,a-1) is used
% but filters are kept equal, (a-1) should be small!
% -----------------------------------------------------------------------------------
%----------------------------------------------------------------------
% Copyright (c) 2001. Karl Skretting. All rights reserved.
% Hogskolen in Stavanger (Stavanger University), Signal Processing Group
% Mail: karl.skretting@tn.his.no Homepage: http://www.ux.his.no/~karlsk/
%
% HISTORY: dd.mm.yyyy
% Ver. 1.0 10.01.2001 KS: function made
% Ver. 1.1 03.12.2002 KS: moved from ..\Frames to ..\FrameTools
%----------------------------------------------------------------------
Mfile='SetF06';
ErrCode=0;
if (nargin < 4); a=0; end; % the default
if (nargin < 3)
disp([Mfile,': wrong number of arguments, see help.']);
ErrCode=2;
return
end
try
if exist([FrameFile,'.mat'])
disp([Mfile,': ',FrameFile,'.mat already exists, it will be overwritten.']);
end
catch
ErrCode=3;
return
end
% initialize the variable in FrameFile
Class='';
Type='g';
Mdim=1;
F=[];
G=[];Dtab=[];Ctab=[];
Fbest=F;
Savg=0;
Mdat=0;
PreProc=struct('Prog1','','Prog2','','Method',[],'arg1',[],'arg2',[],'arg3',[]);
VecSel=struct('Prog1','','arg1',[],'arg2',[],'arg3',[],'arg4',[],'arg5',[]);
InitialF=struct('Prog1',Mfile,'arg1',FrameFile,'arg2',wname,'arg3',Level,'arg4',...
a,'arg5',[]);
History='';
SNRtot=[];
% now set the variables to the wanted values
try
Fg=GetWave(wname,Level); % size is NPxK
catch
disp([Mfile,': error calling GetWave.']);
ErrCode=4;
return
end
[NP,K]=size(Fg);
N=K;
P=NP/N;
if rem(P,1)
disp([Mfile,': P is not integer.']);
ErrCode=5;
return
end
if a<1
[F,G]=BuildG(Fg,a); % F is now Qx1, and G is NPxK
elseif a<2
% let each filter be equal
G=zeros(size(Fg));
[F,G(:,1)]=BuildG(Fg(:,1),a-1);
Q=size(F,1);
for k=1:log2(K)
k1=2^(k-1)+1;k2=2^k;
% the vectors k1:k2 in Fg should be equal!
[f,G(:,k1:k2)]=BuildG(Fg(:,k1:k2),a-1);
if a==1
q=size(f,1)/(k2-k1+1);
else
q=size(f,1);
end
if rem(q,1)
disp([Mfile,': non-integer value of q.']);
q=ceil(q);
end
F=[F;f(1:q)];
G(:,k1:k2)=sign(G(:,k1:k2)).*(abs(G(:,k1:k2))+Q);
Q=Q+q;
I=find(abs(G)>Q);
while length(I)
G(I)=sign(G(I)).*(abs(G(I))-q);
I=find(abs(G)>Q);
end
end
else
disp([Mfile,': strange value of fourth argument, a.']);
ErrCode=6;
return
end
[Q,temp]=size(F);
if temp~=1
disp([Mfile,': possible logical error, size(F) is not correct']);
ErrCode=7;
return
end
if max(G(:))~=Q
disp([Mfile,': possible logical error, max(G(:))~=Q.']);
ErrCode=8;
return
end
% reshape G from NPxK to NxKxP
temp=G;G=zeros(N,K,P);
for p=1:P; G(:,:,p)=temp((1:N)+(p-1)*N,:); end;
% find Ctab and Dtab and SizeF
[Ctab,Dtab]=MapCD(G);
SizeF=size(G);
Fbest=F;
History=char([Mfile,' ',datestr(now),', initialized the frame ',FrameFile],...
['using wavlet ',wname,' ',int2str(Level),' levels, giving N=K=',...
int2str(N),' P=',int2str(P),' Q=',int2str(Q)]);
% save the frame in a file
try
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
catch
disp([Mfile,': error saving ',FrameFile,'.']);
ErrCode=9;
return
end
return
% testing
clear all
FrameFile='test';
wname='db79';
Level=3;
a=1;
ErrCode=SetF06(FrameFile,wname,Level,a);
load(FrameFile);
Fg=BuildFg(F,G);
disp(['The value of Q is ',int2str(max(G(:))),'==',int2str(size(F,1))]);
SizeF
PlotF(Fg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -