📄 agc.m,v
字号:
head 3.0;access;symbols;locks; strict;comment @// @;3.0date 2000.06.13.19.19.36; author gilles; state Exp;branches;next 2.0;2.0date 99.05.21.18.45.02; author mah; state Exp;branches;next 1.5;1.5date 99.02.04.15.24.39; author mah; state Exp;branches;next 1.4;1.4date 99.02.04.14.23.12; author mah; state Exp;branches;next 1.3;1.3date 99.01.11.17.16.58; author mah; state Exp;branches;next 1.2;1.2date 99.01.08.15.24.46; author adam; state Exp;branches;next 1.1;1.1date 99.01.06.19.09.00; author kay; state Exp;branches;next ;desc@@3.0log@Release 3@text@function [dataout]=agc(datain,window,type)%[dataout]=agc(datain,window,type)%%This function will do automatic gain control with a running window equation%on the traces in datain.%The size of the sliding window is specified by the parameter 'window' in %seconds.%'type' = 1 use absolute values for normalizing%'type' = 2 use energy values (x^2) for normalizing%%written by Kristen Beaty Dec. 1997%$Id: agc.m,v 2.0 1999/05/21 18:45:02 mah Exp gilles $%$Log: agc.m,v $%Revision 2.0 1999/05/21 18:45:02 mah%Release 2%%Revision 1.5 1999/02/04 15:24:39 mah%fixed problem with energy agc i.e. option 2%%Revision 1.4 1999/02/04 14:23:12 mah%fixed bug%%Revision 1.3 1999/01/11 17:16:58 mah%added comments through out program%put in error checking for type%fixed up type 2 method including energy balancing%optimized program for speed%fixed up redundancy near end of trace%,%%Revision 1.2 1999/01/08 15:24:46 adam%Add reset to trace length for large window and fixed boundary error%%Revision 1.1 1999/01/06 19:09:00 kay%Initial revision%%%Copyright (C) 1998 Seismology and Electromagnetic Section/%Continental Geosciences Division/Geological Survey of Canada%%This library is free software; you can redistribute it and/or%modify it under the terms of the GNU Library General Public%License as published by the Free Software Foundation; either%version 2 of the License, or (at your option) any later version.%%This library is distributed in the hope that it will be useful,%but WITHOUT ANY WARRANTY; without even the implied warranty of%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%Library General Public License for more details.%%You should have received a copy of the GNU Library General Public%License along with this library; if not, write to the%Free Software Foundation, Inc., 59 Temple Place - Suite 330,%Boston, MA 02111-1307, USA.%%DSI Consortium%Continental Geosciences Division%Geological Survey of Canada%615 Booth St.%Ottawa, Ontario%K1A 0E9%%email: dsi@@cg.nrcan.gc.cadisp('[dataout]=agc(datain,window,type)')dataout=datain;tstart=datain.fh{9}; %start time in secondsint=datain.fh{8}; %sampling interval in secondssamples=datain.fh{7}; %number of points per tracenrec=datain.fh{12}; %number of records in datainw=round(window/int)+1; %convert 'window' from seconds to indexespt=round(w/2); %index of point in the centre of the window% the following checks to see if the window chosen is too largeif w>=samples %error check w = samples-1; pt=round(w/2); ntime = (samples - 1)*int; text = sprintf('WARNING! Window has been reset to %8.5f s',ntime); disp(text)end %if% the following checks to see if the either type 1 or 2 has been chosenif((type ~=1) & (type ~=2)) type=1; text = sprintf('WARNING! Type has been reset to 1'); disp(text)end %if% the following for loop applies the agc to each recordfor COUNT=1:nrec % the following applies the method of agc specified by type switch type case 1 %absolute values % first take the absolute value of the data and divide by w to make it faster temp=abs(datain.dat{COUNT})/w; % first determine the average in the window fact=sum(temp(1:w,:)); facteps=fact+eps; %to get rid of divide by zero problem % now apply this to the first half of the window factgr=meshgrid(facteps,1:pt); %factgr is a grid of the correction factors dataout.dat{COUNT}(1:pt,:)=datain.dat{COUNT}(1:pt,:)./factgr; % now apply the agc to the centre portion of the trace using a for loop for k=1:samples-w % the correction factor fact is being recalculated after each position moved fact=fact-temp(k,:)+temp(k+w,:); facteps=fact+eps; dataout.dat{COUNT}(k+pt,:)=datain.dat{COUNT}(k+pt,:)./facteps; end %for % now apply this correction factor to the last half of the window i=(k+pt+1):samples; %i are the positions that still need to be corrected factgr=meshgrid(facteps,i); %factgr is a grid of the correction factors dataout.dat{COUNT}(i,:)=datain.dat{COUNT}(i,:)./factgr; case 2 %squared values % first square the data and divide by w to make it faster temp=datain.dat{COUNT}.*datain.dat{COUNT}/w/w; % first determine the average in the window fact=sum(temp(1:w,:)); facteps=sqrt(fact+eps); %get rid of divide by zero problem add eps % now apply this to the first half of the window factgr=meshgrid(facteps,1:pt); %factgr is a grid of the correction factors dataout.dat{COUNT}(1:pt,:)=datain.dat{COUNT}(1:pt,:)./factgr; % now apply the agc to the centre portion of the trace using a for loop for k=1:samples-w % the correction factor fact is being recalculated after each position moved fact=fact-temp(k,:)+temp(k+w,:); facteps=sqrt(fact+eps); dataout.dat{COUNT}(k+pt,:)=datain.dat{COUNT}(k+pt,:)./facteps; end %for % now apply this correction factor to the last half of the window i=(k+pt+1):samples; %i are the positions that still need to be corrected factgr=meshgrid(facteps,i); %factgr is a grid of the correction factors dataout.dat{COUNT}(i,:)=datain.dat{COUNT}(i,:)./factgr; % the following balances the energy from trace to trace temp=dataout.dat{COUNT}.*dataout.dat{COUNT}; fact=sum(temp); fact=sqrt(fact); i=find(fact==0); fact(i)=1; %avoid divide by zero error for dead traces factgr=meshgrid(fact,1:samples); dataout.dat{COUNT}=dataout.dat{COUNT}./factgr; %applies the correction end %typeend %loop over records@2.0log@Release 2@text@d14 1a14 1%$Id: agc.m,v 1.5 1999/02/04 15:24:39 mah Exp mah $d16 3@1.5log@fixed problem with energy agc i.e. option 2@text@d14 1a14 1%$Id: agc.m,v 1.4 1999/02/04 14:23:12 mah Exp mah $d16 3@1.4log@fixed bug@text@d14 1a14 1%$Id: agc.m,v 1.3 1999/01/11 17:16:58 mah Exp mah $d16 3d118 1a118 1 temp=datain.dat{COUNT}.*datain.dat{COUNT}/w;d121 1a121 1 facteps=fact+eps; %get rid of divide by zero problemd129 1a129 1 facteps=fact+eps;@1.3log@added comments through out programput in error checking for typefixed up type 2 method including energy balancingoptimized program for speedfixed up redundancy near end of trace,@text@d14 1a14 1%$Id: agc.m,v 1.2 1999/01/08 15:24:46 adam Exp $d16 8d96 1d98 1a98 1 factgr=meshgrid(fact,1:pt); %factgr is a grid of the correction factorsd104 2a105 1 dataout.dat{COUNT}(k+pt,:)=datain.dat{COUNT}(k+pt,:)./fact;d110 1a110 1 factgr=meshgrid(fact,i); %factgr is a grid of the correction factorsd118 1d120 1a120 1 factgr=meshgrid(fact,1:pt); %factgr is a grid of the correction factorsd126 2a127 1 dataout.dat{COUNT}(k+pt,:)=datain.dat{COUNT}(k+pt,:)./fact;d132 1a132 1 factgr=meshgrid(fact,i); %factgr is a grid of the correction factors@1.2log@Add reset to trace length for large window and fixed boundary error@text@d13 2a14 1%$Id: agc.m,v 1.1 1999/01/06 19:09:00 kay Exp adam $d16 3d21 28a49 1d57 2a58 2%convert 'window' from seconds to indexesw=round(window./int)+1;d61 2a62 4if w==samples pt=samples-1; w = samples -1;elseif w>samples %error checkd64 1a64 1 pt = samples -1;d66 1a66 1 text = sprintf('Window has been reset to %8.5f s',ntime);d68 1a68 1end %if/elsed70 1a70 1nrec=datain.fh{12}; %number of records in dataind72 7d80 1d84 6a89 2 fact=sum(abs(datain.dat{COUNT}(1:w,:)))./w; factgr=meshgrid(fact,1:pt);d91 1d93 2a94 1 fact=fact-abs(datain.dat{COUNT}(k,:))./w+abs(datain.dat{COUNT}(k+w,:))./w;d98 5d104 8a111 3 fact=sum(datain.dat{COUNT}(1:w,:).*datain.dat{COUNT}(1:w,:))./w; factgr=meshgrid(fact,1:pt); dataout.dat{COUNT}(i,:)=datain.dat{COUNT}(i,:)./factgr;d113 2a114 2 fact=fact-datain.dat{COUNT}(k,:).*datain.dat{COUNT}(k,:)./w; fact=fact+datain.dat{COUNT}(k+w,:).*datain.dat{COUNT}(k+w,:)./w;d117 16a132 4 end %case i=k+1:samples; factgr=meshgrid(fact,i); dataout.dat{COUNT}(i,:)=datain.dat{COUNT}(i,:)./factgr;@1.1log@Initial revision@text@d7 1a7 1%The size of the sliding window is specified by the parameter 'window' ina11 1%DSI customized VSP processing softwared13 4a17 29%$Id:$%$Log:$%%Copyright (C) 1998 Seismology and Electromagnetic Section/%Continental Geosciences Division/Geological Survey of Canada%%This library is free software; you can redistribute it and/or%modify it under the terms of the GNU Library General Public%License as published by the Free Software Foundation; either%version 2 of the License, or (at your option) any later version.%%This library is distributed in the hope that it will be useful,%but WITHOUT ANY WARRANTY; without even the implied warranty of%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%Library General Public License for more details.%%You should have received a copy of the GNU Library General Public%License along with this library; if not, write to the%Free Software Foundation, Inc., 59 Temple Place - Suite 330,%Boston, MA 02111-1307, USA.%%DSI Consortium%Continental Geosciences Division%Geological Survey of Canada%615 Booth St.%Ottawa, Ontario%K1A 0E9%%email: dsi@@cg.nrcan.gc.cad31 2a32 1 pt=samples;d34 5a38 1 error('choose a smaller window')@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -