📄 hannband.m,v
字号:
head 3.0;access;symbols;locks; strict;comment @// @;3.0date 2000.06.13.19.20.22; author gilles; state Exp;branches;next 2.0;2.0date 99.05.21.18.45.40; author mah; state Exp;branches;next 1.1;1.1date 99.02.01.21.21.48; author mah; state Exp;branches;next ;desc@hanning band pass fir (finite impulse response) filter@3.0log@Release 3@text@function [dataout]=hannband(datain,lowstop,lowpass,highpass,highstop)% [dataout]=hannband(datain,lowstop,lowpass,highpass,highstop)%%This function will filter your data using a bandpass%Finite Impulse Response (FIR) filter where a hanning window%will be used.%'lowstop' is the frequency in Hz below which the signal is not transmitted%'lowpass' is the frequency in Hz above which the signal is transmitted%'highpass' is the frequency in Hz below which the signal is transmitted%'highstop' is the frequency in Hz above which the signal is not transmitted%% A hanning window will be used in order to give a % passband ripple of 3dB and a stopband ripple of 40dB in the power domain%% Warning: The program does not check for unreasonable parameters%%This is based off of the theory developed in%Digital Signal Processing by Alan V. Oppenheim & Ronald W. Schafer%%Written by Marko Mah January 1999%$Id: hannband.m,v 2.0 1999/05/21 18:45:40 mah Exp gilles $%$Log: hannband.m,v $%Revision 2.0 1999/05/21 18:45:40 mah%Release 2%%Revision 1.1 1999/02/01 21:21:48 mah%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.ca disp('[dataout]=hannband(datain,lowstop,lowpass,highpass,highstop)')smpint=datain.fh{8}; %smpint is the sampling intervaltrclength=datain.fh{7}; %trclength is the trace lengthnrec=datain.fh{12}; %nrec is number of records is filedataout=datain;fsample=1/smpint; %fsample is the sampling freq. in HzWls=lowstop*2*pi/fsample; %normalized low stop frequency in Rads/secWlp=lowpass*2*pi/fsample; %normalized low pass frequency in Rads/secWhp=highpass*2*pi/fsample; %normalized high pass frequency in Rads/secWhs=highstop*2*pi/fsample; %normalized high stop frequency in Rads/sec%% the following calculates the low pass part of the filter% transwidth is the transwidth of the filter% M is the order of the filtertranswidth=Whs-Whp;M=floor(6.2*pi/transwidth);M=2*ceil(M/2); % this is to make sure M is evenMhalf=(M-1)/2;n=[0:1:M-1];Wc=(Whp+Whs)/2; % Wc is the cutoff frequency%hd is the desired impulse response of the filter%eps is added in to make sure division by zero does not occurhd=sin(Wc*(n-Mhalf+eps))./(pi*(n-Mhalf+eps));%w_hann is the hanning window or finite duration windoww_hann=0.5*(1-cos(2*pi*n/(M-1)));hlow=hd.*w_hann; %h is the impulse response of the lowpass hanning filter%% the following calculates the high pass part of the filter% transwidth is the transwidth of the filter% M is the order of the filtertranswidth=Wlp-Wls;M=floor(6.2*pi/transwidth);M=2*ceil(M/2); % this is to make sure M is evenMhalf=(M-1)/2;n=[0:1:M-1];Wc=(Wlp+Wls)/2; % Wc is the cutoff frequency%hd is the desired impulse response of the filter%eps is added in to make sure division by zero does not occurhd=(sin(pi*(n-Mhalf+eps))-sin(Wc*(n-Mhalf+eps)))./(pi*(n-Mhalf+eps));%w_hann is the hanning window or finite duration windoww_hann=0.5*(1-cos(2*pi*n/(M-1)));hhigh=hd.*w_hann; %h is the impulse response of the highpass hanning filter%% the following calculates the total impulse responseh=conv(hlow,hhigh);h=h'; %to put h in column format instead of row formatdisp('Order of filter is:')M=length(h)lencor=floor(length(h)/2); %length correction to the datapos=[lencor+1:1:trclength+lencor]; %is the position of the resultant data in the temp variablefor COUNT1=1:nrec [a,ntraces]=size(datain.dat{COUNT1}); %ntraces is the number of traces in the record for COUNT2=1:ntraces temp=conv(datain.dat{COUNT1}(:,COUNT2),h); %convolves the highpass filter with the data dataout.dat{COUNT1}(:,COUNT2)=temp(pos,1); %out puts the filtered data using the positions defined by pos end %for COUNT2end %for COUNT1@2.0log@Release 2@text@d23 1a23 1%$Id: hannband.m,v 1.1 1999/02/01 21:21:48 mah Exp mah $d25 3@1.1log@Initial revision@text@d23 4a26 2%$Id: Exp $%$Log: $d28 1@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -