📄 setf07.m
字号:
function ErrCode=SetF07(FrameFile)
% SetF07 Set F as a general filter bank with N=8, K=16, P=6 and Q=208
% The FrameFile will be of Type 'g'
% Some values here are chosen to fit the hump in an ecg signal.
%
% ErrCode=SetF07(FrameFile);% -----------------------------------------------------------------------------------
% 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
% -----------------------------------------------------------------------------------
%----------------------------------------------------------------------
% 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 07.05.2001 KS: function made
% Ver. 1.1 04.12.2002 KS: moved from ..\Frames to ..\FrameTools
%----------------------------------------------------------------------
Mfile='SetF07';
ErrCode=0;
if (nargin ~= 1)
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;
Dtab=[];Ctab=[];
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',[],'arg3',[],...
'arg4',[],'arg5',[]);
History='';
SNRtot=[];
% set N, K and P
N=8;K=16;P=6;
F=[];
G=zeros(N*P,K);
% some other values (part of normal ecg signal)
b=[ -11.9412 -12.1618 -12.3088 -12.2794 -13.0147 -13.3676 -14.6471
-16.7941 -20.3971 -25.3088 -31.2353 -36.3235 -40.7647 -45.5882
-49.5882 -47.5294 -35.0441 -13.0441 13.8382 45.0735 86.0882
137.5294 187.0735 223.4118 239.1618 227.3235 179.5588 106.7647
35.7206 -11.4265 -31.8824 -34.3382 -29.3382 -23.7794 -21.4412
-20.6912 -19.8971 -18.8824 -18.3971 -18.4118 -18.8971 -19.0000
-18.9412 -19.1324 -19.3971 -19.6765 -19.6765 -19.3824 0.0]';
b=b(:);b=b(1:48);b1=b;
w=hanning(16);
b(1:8)=b(1:8).*w(1:8);
b(41:48)=b(41:48).*w(9:16);
b=b/sqrt(b'*b);
F=[F;b];
G(:,1)=(1:48)';
b=[b1(1)*0.96;b1(1)*0.97;b1(1)*0.98;b1(1)*0.99;b1(1:44)];
b(1:8)=b(1:8).*w(1:8);
b(41:48)=b(41:48).*w(9:16);
b=b/sqrt(b'*b);
F=[F;b(1:4)];
G(:,2)=[(49:52)';(1:44)'];Q=52;
% the first 2 filter are designed, now make filters 3 and 4 (symmetric)
b=ones(48,1);
b(1:8)=b(1:8).*w(1:8);
b(41:48)=b(41:48).*w(9:16);
b=b/sqrt(b'*b);
F=[F;b(1:24)];q=((Q+1):(Q+24))';Q=Q+24;
G(:,3)=[q;flipud(q)];
b=GetLOT(24);b=b(:,1);
b(1:8)=b(1:8).*w(1:8);
b(41:48)=b(41:48).*w(9:16);
b=b/sqrt(b'*b);
F=[F;b(1:24)];q=((Q+1):(Q+24))';Q=Q+24;
G(:,4)=[q;flipud(q)];
% now make the next 6, LP and BP filters from 24x12 LOT
b1=GetLOT(12,0.95);
for k=1:6
b=-b1(:,k);
b=b/sqrt(b'*b);
F=[F;b(1:12)];q=((Q+1):(Q+12))';Q=Q+12;
G(13:36,4+k)=[q;(1-2*mod(k+1,2))*flipud(q)];
end
% now make the last 6, BP filters from 12x12 DCT
b1=idct(eye(12));
b1=b1(:,5:10);
for k=1:6
b=b1(:,k).*w(3:14);
b=b/sqrt(b'*b);
F=[F;b(1:6)];q=((Q+1):(Q+6))';Q=Q+6;
G(19:30,10+k)=[q;flipud(q).*(1-2*mod(k+1,2))];
end
% now F and G are made, 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 some ad-hoc defined FIR filters, giving N=',...
int2str(N),' K=',int2str(K),' 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';
ErrCode=SetF07(FrameFile);
load(FrameFile);
disp(['The value of Q is ',int2str(max(G(:))),'==',int2str(size(F,1))]);
PlotF(BuildFg(F,G),size(G));
% select some filters adapted to ECG signal
% this find the values for the b used in the function
clear all;
L=20000;
Limit=150;
[x,fs]=GetSignal(11,L);
I=[];
i1=0;i2=0;
for i=25:(L-25)
if x(i)>Limit
if (~i1); i1=i; end
i2=0;
else
if (~i2); i2=i; end
end
if i1 & i2
I=[I,floor((i1+i2)/2)];
i1=0;
end
end
% I=floor(I/4)*4+1;
X=zeros(48,length(I));
for i=1:length(I)
xi=I(i);
X(:,i)=x((xi-24):(xi+23));
end
b=mean(X')';
Y=X-b*ones(1,length(I)); % the errors
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -