📄 framedesignex.m
字号:
function F=FrameDesignEx(TestNo,arg1,arg2)
% FrameDesignEx Here we design an example frame for an AR(1) signal.
% The different steps of the design process are briefly
% explained and done. The steps are:
% 1. Decide for the frame structure to use, i.e. size of F, and
% target sparseness factor.
% 2. Prepare the set training vectors, make X.
% also these vectors are stored in a mat-file used during frame design
% see DataFile.m, ex: help DataFile
% 3. Set the initial frame and store it in FrameFile, see: help FrameFile.
% The initial values for the frame may be generated in many ways,
% for example one of the files SetF03, SetF05, ..., could be used,
% see help text for these. SetFnn generates the FrameFile. It may be
% needed to update som of the variables stored in the mat-file.
% An alternative is to use GenLloyd to find the initial values of F,
% then we must remember to store the variables in the mat-file.
% 4. Design the frame using DesignF or DesignFb
% 5. We may now look at the designed frame and plot training results.
% The frame is now ready to use for sparse representation, for examples see
% SignalExpansion.m, ex: Y=SignalExpansion(5,1,255,'FrameEx2s20',0.25);
% Some frame properties can be found by for example
% [a,b,c,d,e,f,g,Ang]=FrameProperties('FrameEx1s20',[2,3,7,8,9,27,28,29,31,32,33]);
%
% F=FrameDesignEx(TestNo,arg1,arg2);
% F=FrameDesignEx(1,0.2);
% F=FrameDesignEx(2,0.2);
%-----------------------------------------------------------------------------------
% arguments:
% F - the designed frame
% TestNo - which test or example to do
% 1 - Design a block-oriented 16x32 frame for an AR(1) signal
% 2 - Continue design from TestNo 1, but now change vector selection method
% 3 - Design a general overlapping frame for an AR(1) signal
% 4 - Design an overlapping frame for an AR(1) signal
% arg1 - for most tests it is target sparseness factor
%-----------------------------------------------------------------------------------
%----------------------------------------------------------------------
% Copyright (c) 2002. 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 03.12.2002 KS: function made
%----------------------------------------------------------------------
Mfile='FrameDesignEx';
F=[];
DataFile='DataX001'; % the file where the set of training vectors, X, is stored during design
TotIt=250; % number of iterations to do
Minutes=60*6; % minutes to use
if nargin<3; arg2=0; end;
if nargin<2; arg1=0; end;
if nargin<1;
Message=[Mfile,': wrong number of arguments, see help.'];
disp(Message);
return
end;
if (TestNo==1)
% step 1.
N=16;K=32;P=1;
disp([Mfile,', Test/example ',int2str(TestNo),', ',int2str(N),'x',int2str(K),...
' block-oriented frame for AR(1) signal.']);
if ((arg1>0) & (arg1<1))
S=arg1; % target sparseness factor
else
S=0.2;
end
% step 2.
L=4000; % number of training vectors
X=filter(1,[1,-0.95],randn(L*N,1)); % AR(1) signal
X=reshape(X,N,L); % here we have L vectors (from a training signal) each of lenght N
Name='AR(1)';
X_DC=0;X_LP=[];SizeX=[N*L,1];
ss2=X(:)'*X(:);
WWT=[];XWT=[];
save(DataFile,'Name','X_DC','X_LP','X','SizeX','ss2','S','WWT','XWT');
% step 3.
FrameFile=['FrameEx',int2str(TestNo),'s',int2str(round(S*100))];
% this m-file is the PreProc method used here
PreProc=struct('Prog1','','Prog2',Mfile,'Method',TestNo,'arg1',arg1,'arg2',arg2,'arg3',[]);
% now set how vector selection should be done
VecSel=struct('Prog1','VSblock','arg1','VSfomp2','arg2',5,'arg3',[],'arg4',[],'arg5',[]);
% generate F and store how initial F is generated
F=GenLloyd(NormalizeF(X),K,1);
% clf;PlotF(F,1,0,0,3); % if we want to look at the vectors
InitialF=struct('Prog1','GenLloyd','arg1','NormalizeF(X)','arg2',K,'arg3',1,'arg4',[],'arg5',[]);
History=[Mfile,' ',datestr(now),', initialized the frame ',FrameFile,' using',...
' N=',int2str(N),' K=',int2str(K),' P=1'];
History=char(History,'Initial values made by Generalized Lloyd Algorithm.');
SNRtot=[];Type='b';Mdat=1;G=[];Dtab=[];Ctab=[];Savg=S;
SizeF=[N,K,P];Mdim=1;Class='AR(1)';Fbest=F;
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
% step 4, here we use DesignFb
disp(' ');
disp([Mfile,': ',datestr(now),' start design of frame ',FrameFile]);
ErrCode=DesignFb(FrameFile,TotIt,Minutes/(24*60));
% step 5
load(FrameFile);
disp(History);
figure(1);clf;PlotF(F,1,0,0,3);
figure(2);clf;PlotSNR(SNRtot,History);
% signal expansion example
Y=SignalExpansion(5,1,255,FrameFile,0.25);
end
if (TestNo==2)
disp([Mfile,', Test/example ',int2str(TestNo),', continue from TesNo 1 with', ...
' block-oriented frame for AR(1) signal.']);
% step 1. values are found when framefile is read
if ((arg1>0) & (arg1<1))
S=arg1; % target sparseness factor
else
S=0.2;
end
% step 2. assume that DataFile is the one made by TestNo 1
% step 3.
FrameFile=['FrameEx1s',int2str(round(S*100))];
load(FrameFile); % load FrameFile from TestNo 1, but store it by another name
FrameFile=['FrameEx',int2str(TestNo),'s',int2str(round(S*100))];
History=char(History,[Mfile,' ',datestr(now),', frame was copied to ',FrameFile,'.']);
F=Fbest;
VecSel=struct('Prog1','VSblock','arg1','VSab2','arg2',5,'arg3',0,'arg4',4,'arg5',[]);
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
% step 4, here we use DesignFb
disp(' ');
disp([Mfile,': ',datestr(now),' start design of frame ',FrameFile]);
ErrCode=DesignFb(FrameFile,2*TotIt,Minutes/(24*60));
% step 5
load(FrameFile); % we want to update VecSel.arg3
VecSel=struct('Prog1','VSblock','arg1','VSab2','arg2',5,'arg3',20,'arg4',4,'arg5',[]);
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
disp(History);
figure(1);clf;PlotF(F,1,0,0,3);
figure(2);clf;PlotSNR(SNRtot,History);
% signal expansion example
Y=SignalExpansion(5,1,255,FrameFile,0.25);
end
if (TestNo==3)
% step 1.
% we will use F with initial values from FIR filters, SetF05
FIRspec=[40,8,0,0.05; 40,8,0,0.2; 28,4,0,0.2; 28,4,0,0.4; 12,4,0,0.5;
14,2,0.1,0.6; 14,2,0.2,0.7 ];
disp([Mfile,', Test/example ',int2str(TestNo),', used some FIR filters ',...
'(SetF05), overlapping frame for AR(1) signal.']);
if ((arg1>0) & (arg1<1))
S=arg1; % target sparseness factor
else
S=0.2;
end
% step 3, first part is done now (since N, K and P are needed but only indirectly given)
FrameFile=['FrameEx',int2str(TestNo),'s',int2str(round(S*100))];
ErrCode=SetF05(FrameFile,FIRspec,1.000001);
if ErrCode
Message=[Mfile,': an error occurred in SetF05.'];
disp(Message);
return;
end
load(FrameFile);
[N,K,P]=size(G);
% step 2.
L=4000; % number of training vectors
X=filter(1,[1,-0.95],randn(L*N,1)); % AR(1) signal
X=reshape(X,N,L); % here we have L vectors (from a training signal) each of lenght N
Name='AR(1)';
X_DC=0;X_LP=[];SizeX=[N*L,1];
ss2=X(:)'*X(:);
WWT=[];XWT=[];
save(DataFile,'Name','X_DC','X_LP','X','SizeX','ss2','S','WWT','XWT');
% step 3.
% change some of the initial values of the frame which were set by SetF05
% the PreProc variable contain som useful information
PreProc=struct('Prog1','','Prog2',Mfile,'Method',TestNo,'arg1',arg1,'arg2',arg2,'arg3',[]);
% it is important to set an appropriate vector selection method. For overlapping frame and
% 1D signal it must be VSolap1 and a suitable method (VSab2 or VSfomp2)
VecSel=struct('Prog1','VSolap1','arg1','VSab2','arg2',10,'arg3',1,'arg4',[],'arg5',[]);
Savg=S; % this is important as SetF05 set this to zero.
Class='AR(1)'; % useful information
Fbest=F;
Mdat=1; % this is important too, since SetF05 set this to zero.
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
% step 4, here we use DesignF
disp(' ');
disp([Mfile,': ',datestr(now),' start design of frame ',FrameFile]);
ErrCode=DesignF(FrameFile,TotIt,Minutes/(24*60));
% step 5, display some information on the designed frame
load(FrameFile); % we want to update VecSel.arg3
VecSel=struct('Prog1','VSolap1','arg1','VSab2','arg2',10,'arg3',20,'arg4',[],'arg5',[]);
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
[a,b,c,d,e,f,g,Ang]=FrameProperties(FrameFile,[2,3,7,8,9,27,28,29,31,32,33]);
[t1,t2]=FrameInfo(FrameFile,1);
pause; % note the symmetry in the frame vectors, there is only 85 free variables
disp(History);
figure(1);clf;PlotF(BuildFg(F,G),1,0,0,3); % BuildFg is needed for general frames
figure(2);clf;PlotSNR(SNRtot,History);
% signal expansion example
Y=SignalExpansion(5,1,255,FrameFile,0.25);
end
if (TestNo==4)
% step 1.
N=8;K=16;P=4;
disp([Mfile,', Test/example ',int2str(TestNo),', ',int2str(N),'x',int2str(K),...
'x',int2str(P),' overlapping frame for AR(1) signal.']);
if ((arg1>0) & (arg1<1))
S=arg1; % target sparseness factor
else
S=0.2;
end
% step 2.
L=6000; % number of training vectors
X=filter(1,[1,-0.95],randn(L*N,1)); % AR(1) signal
X=reshape(X,N,L);
Name='AR(1)';
X_DC=0;X_LP=[];SizeX=[N*L,1];
ss2=X(:)'*X(:);
WWT=[];XWT=[];
save(DataFile,'Name','X_DC','X_LP','X','SizeX','ss2','S','WWT','XWT');
% step 3
FrameFile=['FrameEx',int2str(TestNo),'s',int2str(round(S*100))];
ErrCode=SetF03(FrameFile,[N,K,P],bin2dec('0111011100000011'));
% here we use vectors from DCT, LOT and ELT
if ErrCode
Message=[Mfile,': an error occurred in SetF03.'];
disp(Message);
return;
end
load(FrameFile);
% change some of the initial values of the frame which were set by SetF05
% the PreProc variable contain som useful information
PreProc=struct('Prog1','','Prog2',Mfile,'Method',TestNo,'arg1',arg1,'arg2',arg2,'arg3',[]);
% it is important to set an appropriate vector selection method. For overlapping frame and
% 1D signal it must be VSolap1 and a suitable method (VSab2 or VSfomp2)
VecSel=struct('Prog1','VSolap1','arg1','VSab2','arg2',12,'arg3',2,'arg4',[],'arg5',[]);
Savg=S; % this is important as SetF03 set this to zero.
Class='AR(1)'; % useful information
Fbest=F;
Mdat=1; % this is important too, since SetF03 set this to zero.
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
% step 4, here we use DesignF
disp(' ');
disp([Mfile,': ',datestr(now),' start design of frame ',FrameFile]);
ErrCode=DesignF(FrameFile,TotIt,Minutes/(24*60));
% step 5, display some information on the designed frame
load(FrameFile); % we want to update VecSel.arg3
VecSel=struct('Prog1','VSolap1','arg1','VSab2','arg2',12,'arg3',20,'arg4',[],'arg5',[]);
save(FrameFile,'Class','Type','Mdim','F','SizeF','G','Ctab','Dtab',...
'Fbest','Savg','Mdat','PreProc','VecSel','InitialF','History','SNRtot');
[a,b,c,d,e,f,g,Ang]=FrameProperties(FrameFile,[2,3,7,8,9,27,28,29,31,32,33]);
[t1,t2]=FrameInfo(FrameFile,1);
pause; % note the symmetry in the frame vectors, there is only 85 free variables
disp(History);
figure(1);clf;PlotF(F,1,0,0,3); % BuildFg is needed for general frames
figure(2);clf;PlotSNR(SNRtot,History);
% signal expansion example
Y=SignalExpansion(5,1,255,FrameFile,0.25);
end
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -