


FOURFILT Fourier low, high, or bandpass filter.
[filtdat]=fourfilt(x,delt,tmax,tmin)
where: x: data series to be filtered
delt: sampling interval
tmax: maximum period filter cutoff
tmin: minimum period filter cutoff
usage: lowpassdata=fourfilt(data,0.5,2000,20)
gives lowpass filter with cutoff at 20.0 sec
tmax set > (length(x)*delt) for no cutoff at low freq end
usage: highpassdata=fourfilt(x,0.5,20,0.9)
gives highpass filter with cutoff at 20.0 sec
tmin set < (2*delt) for no cutoff at high freq end
usage: bandpassdata=fourfilt(x,0.5,20,10)
gives bandpass filter passing 10-20 sec. band
Reference:
Walters, R. A. and Heston, C., 1982. Removing the tidal-period variations from time-series
data using low-pass digital filters. Journal of Physical Oeanography, 12 112-115 .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Version 1.0 (12/4/96) Jeff List (jlist@usgs.gov)
Version 1.1 (1/8/97) Rich Signell (rsignell@usgs.gov)
removed argument for number of points and add error trapping for matrices
Version 1.1b (12/1/2005) Rich Signell (rsignell@usgs.gov)
added reference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0001 function [filtdat]=fourfilt(x,delt,tmax,tmin) 0002 0003 % FOURFILT Fourier low, high, or bandpass filter. 0004 % 0005 % [filtdat]=fourfilt(x,delt,tmax,tmin) 0006 % 0007 % where: x: data series to be filtered 0008 % delt: sampling interval 0009 % tmax: maximum period filter cutoff 0010 % tmin: minimum period filter cutoff 0011 % 0012 % usage: lowpassdata=fourfilt(data,0.5,2000,20) 0013 % 0014 % gives lowpass filter with cutoff at 20.0 sec 0015 % tmax set > (length(x)*delt) for no cutoff at low freq end 0016 % 0017 % usage: highpassdata=fourfilt(x,0.5,20,0.9) 0018 % 0019 % gives highpass filter with cutoff at 20.0 sec 0020 % tmin set < (2*delt) for no cutoff at high freq end 0021 % 0022 % usage: bandpassdata=fourfilt(x,0.5,20,10) 0023 % 0024 % gives bandpass filter passing 10-20 sec. band 0025 % 0026 % Reference: 0027 % Walters, R. A. and Heston, C., 1982. Removing the tidal-period variations from time-series 0028 % data using low-pass digital filters. Journal of Physical Oeanography, 12 112-115 . 0029 % 0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0031 % Version 1.0 (12/4/96) Jeff List (jlist@usgs.gov) 0032 % Version 1.1 (1/8/97) Rich Signell (rsignell@usgs.gov) 0033 % removed argument for number of points and add error trapping for matrices 0034 % Version 1.1b (12/1/2005) Rich Signell (rsignell@usgs.gov) 0035 % added reference 0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0037 [m,n]=size(x); 0038 if(min(m,n)~=1), 0039 disp('fourfilt cannot handle matrices'); 0040 stop 0041 end 0042 npts=length(x); 0043 0044 nby2=npts/2; 0045 tfund=npts*delt; 0046 ffund=1.0/tfund; 0047 0048 % remove the mean from data: 0049 0050 datamean=mean(x); 0051 x=x-datamean; 0052 0053 % fourier transform data: 0054 0055 coeffs=fft(x); 0056 0057 % filter coefficients: 0058 0059 f=ffund; 0060 for i=2:nby2+1 0061 t=1.0/f; 0062 if t > tmax | t < tmin 0063 coeffs(i)=0.0*coeffs(i); 0064 end 0065 f=f+ffund; 0066 end 0067 0068 0069 % calculate the remaining coefficients: 0070 0071 for i=2:nby2 0072 coeffs(npts+2-i)=conj(coeffs(i)); 0073 end 0074 0075 0076 % backtransform data and take real part: 0077 0078 backcoeffs=ifft(coeffs); 0079 filtdat=real(backcoeffs); 0080 0081 % add back the mean: 0082 0083 filtdat=filtdat+datamean;