⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filtspec.m

📁 Univ. of Calgary CREWS的免费地震研究软件
💻 M
字号:
 function [fltr,f]=filtspec(dt,tmax,fmin,fmax,phase,max_atten)
% FILTSPEC: designs the filter spectrum for FILTF
%
% [fltr,f]=filtspec(dt,tmax,fmin,fmax,phase,max_atten)
% [fltr,f]=filtspec(dt,tmax,fmin,fmax,phase)
% [fltr,f]=filtspec(dt,tmax,fmin,fmax)
%
% FILTSPEC designs and returns the frequency spectrum of the 
% filter which FILTF applies. 
% FILTF filters the input trace in the frequency domain.
% Input trace length in samples (as implied by tmax and dt)
% is automatically padded to the next larger power of two.
% Filter slopes are formed from Gaussian functions.
%
% dt ... temporal sample rate in seconds (must be less than .025s)
% tmax ... temporal length of trace to be filtered
% fmin ... a two element vector specifying:
%        fmin(1) : 3db down point of filter on low end (Hz)
%        fmin(2) : gaussian width on low end
%   note: if only one element is given, then fmin(2) defaults
%         to 5 Hz. Set to [0 0] for a low pass filter  
% fmax ... a two element vector specifying:
%        fmax(1) : 3db down point of filter on high end (Hz)
%        fmax(2) : gaussian width on high end
%   note: if only one element is given, then fmax(2) defaults
%         to 10% of Fnyquist. Set to [0 0] for a high pass filter. 
% phase... 0 ... zero phase filter
%          1 ... minimum phase filter
%          any other number ... constant phase rotation of that
%		   many degrees
%  ****** default = 0 ********
% note: Minimum phase filters are approximate in the sense that
%  the output from FILTF is truncated to be the same length as the
%  input. This works fine as long as the trace being filtered is
%  long compared to the impulse response of your filter. Be wary
%  of narrow band minimum phase filters on short time series. The
%  result may not be minimum phase.
% 
% max_atten= maximum attenuation in decibels
%   ******* default= 80db *********
%
% fltr= complex filter spectrum
%	returned as a column vector
% f= frequency coordinate vector for fltr
%
% by G.F. Margrave, July 1991
%	revised August 1996
% 
 
% determine frequency coordinate vector
  nt= tmax/dt+1;
  nt= 2^nextpow2(nt);
  t= (0:nt-1)*dt;
  tmax=t(length(t));
  fnyq=1/(2*dt);
  nf= nt/2+1;
  df= fnyq/(nf-1);
  f= (0:nf-1)*df;
  
% set defaults
 if nargin < 6
   max_atten=80.;
 end
 if nargin < 5
   phase=0;
 end
 if length(fmax)==1
   fmax(2)=.1/(2.*(t(2)-t(1)));
 end
 if length(fmin)==1
   fmin(2)=5;
 end
 dbd=3.0; % this controls the dbdown values of fmin and fmax

% design low end gaussian
  if fmin(1)>0
   fnotl=fmin(1)+sqrt(log(10)*dbd/20.)*fmin(2);
%HDG removed to be consistent with revised filtf
   % fnotl= round(fnotl/df)*df;
   gnot=10^(-max_atten/20.);
   glow=gnot+gauss(f,fnotl,fmin(2))';
%HDG added to force mean to zero
   glow(1)=0;
  else
   glow=1;
   fnotl=0;
  end
% design high end gaussian
 if fmax(1)>0
  fnoth=fmax(1)-sqrt(log(10)*dbd/20.)*fmax(2);
%HDG removed to be consistent with revised filtf
 % fnoth= round(fnoth/df)*df;
  gnot=10^(-max_atten/20.);
  ghigh=gnot+gauss(f,fnoth,fmax(2))';
 else
  ghigh=1;
  fnoth=0;
 end
% make filter

%HDG removed this error test, as new code handles fnoth<=fnotl
%	if(fnoth<=fnotl & fnoth~= 0)
%		error('filter design error');
%	end
  fltr=ones(nf,1);
%HDG change to floor and ceil
%  nl=fnotl/df+1;
%  nh=fnoth/df+1;
  nl=floor(fnotl/df);
  nh=ceil(fnoth/df);
 % replace if with if from revised filtf
  if nl==0
    fltr=[fltr(1:nh);ghigh(nh+1:length(f))];
  elseif nh==0
    fltr=[glow(1:nl+1);fltr(nl+2:length(f))];
  else
    fltr=[glow(1:nl+1);fltr(nl+2:nf)].*[fltr(1:nh);ghigh(nh+1:length(f))];
    fltr=fltr/max(abs(fltr));
  end
% do phase
  if phase==1
    L1=1:length(fltr);L2=length(fltr)-1:-1:2;
    symspec=[fltr(L1);conj(fltr(L2))];
    cmpxspec=log(symspec)+i*zeros(size(symspec));
    fltr=exp(conj(hilbm(cmpxspec)));
    fltr=fltr(1:length(f));
  else
  	fltr= fltr*exp(i*pi*phase/180);
  end
  

  










⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -