📄 setf03.m
字号:
function ErrCode=SetF03(FrameFile,SizeF,Use)
% SetF03 Set F using initial values from DCT/Haar/LOT/ELT/eye/randn
% The size of F is given by the SizeF variable.
% This file makes SetF01 and SetF02 (for most cases) redundant.
% The FrameFile is created, or overwritten, with the new initial values.
%
% ErrCode=SetF03(FrameFile,SizeF,Use);% ErrCode=SetF03(FrameFile,SizeF,bin2dec('01100111')); % LP+BP from DCT, BP from Haar% -----------------------------------------------------------------------------------
% 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
% SizeF - This should be the size of F, ex 1D signal: NxKxP
% (if P is not given, P=1).
% We should have N/4 as an integer
% Use - an integer specifying which synthesis vectors to use,
% The N synthesis vectors from each transform are divided into
% 4 groups, from low-pass to high-pass. The bits that are set
% in Use specify which to use, one bit selects N/4 vectors.
% Note that the bits are numbered from the right to the left!
% bit 1-4 DCT vectors (1 is LP group, 2 and 3 BP, and 4 is HP)
% bit 5-8 Haar vectors,
% bit 9-12 LOT vectors, only if P>=2
% bit 13-16 ELT vectors, only if P>=4
% bit 17-20 eye-matrix vectors or unit-vectors
% If total is fewer than K then the frame is fillud up with randn vectors
% If Use is 0, only random synthesis vectors are used
% Use - an example signal (of size NKPx1) which gives the initial vectors
% ------------------------------------------------------------------------------------
%----------------------------------------------------------------------
% Copyright (c) 2000. 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 19.12.2000 KS: function made
% Ver. 1.1 03.12.2002 KS: moved from ..\Frames to ..\FrameTools
%----------------------------------------------------------------------
Mfile='SetF03';
ErrCode=0;
% RandnSeed=sum(100*clock); % a true random value
RandnSeed=1762;
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='';
Mdim=1;
F=1;
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','','arg1',[],'arg2',[],'arg3',[],'arg4',[],'arg5',[]);
History='';
SNRtot=[];
% now set the variables to the wanted values
if length(SizeF)==2; SizeF=[SizeF,1]; end;
if length(SizeF) ~= 3
disp([Mfile,': not a legal size of SizeF, see help.']);
ErrCode=2;
return
end
N=SizeF(1);
K=SizeF(2);
P=SizeF(3);
if (P==1); Type='b'; else; Type='o'; end;
if rem(N,4)
disp([Mfile,': not a legal value of N, see help.']);
ErrCode=2;
return
end
F=zeros(N*P,K); % first all is zero
Use=Use(:);
if length(Use)==1
% LPdh is set if low-pass vectors for both DCT and Haar are to be used
% since two vectors then will be equal one is removed.
if (bitget(Use,1) & bitget(Use,5)); LPdh=1; else LPdh=0; end;
bits=0;
for k=1:32; bits=bits+bitget(Use,k); end;
if ((bits*N/4)>(K+LPdh))
disp([Mfile,': more vectors wanted than allowed by the size of the frame.']);
ErrCode=4;
return
end
%
% Get the standard synthesis vectors
tDCT=idct(eye(N));
tHAAR=GetHaar(N);
tLOT=GetLOT(N,0.95); % rxx=0.95
tELT=GetELT(N,0.7,0.95); % p=0.7 and rxx=0.95
tEYE=eye(N);
% now place them into F
k=1:(N/4); % where to pace the first ones
np=(ceil(P/2)-1)*N+(1:N);
if bitget(Use,1); F(np,k)=tDCT(:,1:(N/4)); k=k+N/4; end;
if bitget(Use,2); F(np,k)=tDCT(:,(N/4)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,3); F(np,k)=tDCT(:,(N/2)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,4); F(np,k)=tDCT(:,(3*N/4)+(1:(N/4))); k=k+N/4; end;
if LPdh
if N>=8
F(np,k(1:(N/4-1)))=tHAAR(:,2:(N/4)); k=k+N/4-1;
end
else
if bitget(Use,5); F(np,k)=tHAAR(:,1:(N/4)); k=k+N/4; end;
end
if bitget(Use,6); F(np,k)=tHAAR(:,(N/4)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,7); F(np,k)=tHAAR(:,(N/2)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,8); F(np,k)=tHAAR(:,(3*N/4)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,17); F(np,k)=tEYE(:,1:(N/4)); k=k+N/4; end;
if bitget(Use,18); F(np,k)=tEYE(:,(N/4)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,19); F(np,k)=tEYE(:,(N/2)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,20); F(np,k)=tEYE(:,(3*N/4)+(1:(N/4))); k=k+N/4; end;
if P>=2
% use vectors from the LOT
np=(ceil((P-1)/2)-1)*N+(1:(2*N));
if bitget(Use,9); F(np,k)=tLOT(:,1:(N/4)); k=k+N/4; end;
if bitget(Use,10); F(np,k)=tLOT(:,(N/4)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,11); F(np,k)=tLOT(:,(N/2)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,12); F(np,k)=tLOT(:,(3*N/4)+(1:(N/4))); k=k+N/4; end;
end
if P>=4
% use vectors from the LOT
np=(ceil((P-3)/2)-1)*N+(1:(4*N));
if bitget(Use,13); F(np,k)=tELT(:,1:(N/4)); k=k+N/4; end;
if bitget(Use,14); F(np,k)=tELT(:,(N/4)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,15); F(np,k)=tELT(:,(N/2)+(1:(N/4))); k=k+N/4; end;
if bitget(Use,16); F(np,k)=tELT(:,(3*N/4)+(1:(N/4))); k=k+N/4; end;
end
%
t1='Synthesis vectors from ';
if bitget(Use,1) | bitget(Use,2) | bitget(Use,3) | bitget(Use,4)
t1=[t1,'DCT('];
temp='';
if bitget(Use,1); t1=[t1,temp,'LP']; temp=','; end;
if bitget(Use,2); t1=[t1,temp,'BP1']; temp=','; end;
if bitget(Use,3); t1=[t1,temp,'BP2']; temp=','; end;
if bitget(Use,4); t1=[t1,temp,'HP']; temp=','; end;
t1=[t1,') '];
end
if bitget(Use,5) | bitget(Use,6) | bitget(Use,7) | bitget(Use,8)
t1=[t1,'Haar('];
temp='';
if bitget(Use,5); t1=[t1,temp,'LP']; temp=','; end;
if bitget(Use,6); t1=[t1,temp,'BP1']; temp=','; end;
if bitget(Use,7); t1=[t1,temp,'BP2']; temp=','; end;
if bitget(Use,8); t1=[t1,temp,'HP']; temp=','; end;
t1=[t1,') '];
end
if (P>=2) & (bitget(Use,9) | bitget(Use,10) | bitget(Use,11) | bitget(Use,12))
t1=[t1,'LOT('];
temp='';
if bitget(Use,9); t1=[t1,temp,'LP']; temp=','; end;
if bitget(Use,10); t1=[t1,temp,'BP1']; temp=','; end;
if bitget(Use,11); t1=[t1,temp,'BP2']; temp=','; end;
if bitget(Use,12); t1=[t1,temp,'HP']; temp=','; end;
t1=[t1,') '];
end
if (P>=4) & (bitget(Use,13) | bitget(Use,14) | bitget(Use,15) | bitget(Use,16))
t1=[t1,'ELT('];
temp='';
if bitget(Use,13); t1=[t1,temp,'LP']; temp=','; end;
if bitget(Use,14); t1=[t1,temp,'BP1']; temp=','; end;
if bitget(Use,15); t1=[t1,temp,'BP2']; temp=','; end;
if bitget(Use,16); t1=[t1,temp,'HP']; temp=','; end;
t1=[t1,') '];
end
if bitget(Use,17) | bitget(Use,18) | bitget(Use,19) | bitget(Use,20)
t1=[t1,'eye('];
temp='';
if bitget(Use,17); t1=[t1,temp,'1']; temp=','; end;
if bitget(Use,18); t1=[t1,temp,'2']; temp=','; end;
if bitget(Use,19); t1=[t1,temp,'3']; temp=','; end;
if bitget(Use,20); t1=[t1,temp,'4']; temp=','; end;
t1=[t1,') '];
end
if k(1)<=K
% add the random synthesis vectors
randn('state',RandnSeed);
F(:,k(1):K)=randn(N*P,K-k(1)+1);
t1=[t1,'randn(seed=',int2str(RandnSeed),') '];
end
t1(length(t1))='.';
InitialF.arg3=Use;
elseif length(Use)==(N*K*P)
t1='Synthesis vectors from a user supplied signal.';
F=reshape(Use,N*P,K);
else
t1='Synthesis vectors generated by random.';
randn('state',RandnSeed);
F=randn(N*P,K);
end
for k=1:K % normalize each colum vector of F
temp=F(:,k)'*F(:,k);
if temp>0
F(:,k)=F(:,k)/sqrt(temp);
if sum(F(:,k))<0; F(:,k)=-F(:,k); end;
end
end
if (P>1) % reshape F into its constituent matrices
temp=F;
F=zeros(N,K,P);
for p=1:P
F(:,:,p)=temp(((p-1)*N+1):(p*N),:);
end
end
Fbest=F;
InitialF.Prog1=Mfile;
InitialF.arg1=FrameFile;
InitialF.arg2=SizeF;
History=[Mfile,' ',datestr(now),', initialized the frame ',FrameFile,' using',...
' N=',int2str(N),' K=',int2str(K),' P=',int2str(P)];
History=char(History,t1); % t1 specify more detailed the initial values
% 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
ErrCode=3;
return
end
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -