


boxfilt Low-pass filters [and subsamples] using boxcar filter[s]
USAGE: [ulp]=boxfilt(u,nbox)
or
[ulp,jdlp]=boxfilt(u,nbox,jd)
or
[ulp,jdlp]=boxfilt(u,nbox,jd,nsub)
Input: u = matrix with time series in each column
nbox = number of points to boxfilter (must be odd)
jd = julian day time vector (optional)
nsub = subsamboxing interval for the output low-pass data (optional)
Output: ulp = low-pass filtered data
jdlp = julian time vector corresponding to the data ulp.
Example: [ulp,jdlp]=boxfilt(u,[6 6 7],jd,6);
applies successive boxcar filters of 6, 6 and then 7,
then subsamples the output every 6 hours
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Version 1.0 (4/4/97) Rich Signell (rsignell@usgs.gov)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Version 2.0 (1/10/99) Rich Signell (rsignell@usgs.gov)
allows for successive boxcar filters to be applied by
making NBOX a vector. I've done this mainly for input
to Foreman's Tidal Program, which can scale up higher
frequency tidal coefficients if the sucessive filtering
information is specified.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0001 function [ufilt,jdf]=boxfilt(u,nbox,jd,nsamp) 0002 % boxfilt Low-pass filters [and subsamples] using boxcar filter[s] 0003 % 0004 % USAGE: [ulp]=boxfilt(u,nbox) 0005 % or 0006 % [ulp,jdlp]=boxfilt(u,nbox,jd) 0007 % or 0008 % [ulp,jdlp]=boxfilt(u,nbox,jd,nsub) 0009 % 0010 % Input: u = matrix with time series in each column 0011 % nbox = number of points to boxfilter (must be odd) 0012 % jd = julian day time vector (optional) 0013 % nsub = subsamboxing interval for the output low-pass data (optional) 0014 % 0015 % Output: ulp = low-pass filtered data 0016 % jdlp = julian time vector corresponding to the data ulp. 0017 % 0018 % Example: [ulp,jdlp]=boxfilt(u,[6 6 7],jd,6); 0019 % applies successive boxcar filters of 6, 6 and then 7, 0020 % then subsamples the output every 6 hours 0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0022 % Version 1.0 (4/4/97) Rich Signell (rsignell@usgs.gov) 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 % Version 2.0 (1/10/99) Rich Signell (rsignell@usgs.gov) 0025 % allows for successive boxcar filters to be applied by 0026 % making NBOX a vector. I've done this mainly for input 0027 % to Foreman's Tidal Program, which can scale up higher 0028 % frequency tidal coefficients if the sucessive filtering 0029 % information is specified. 0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0031 0032 nnbox=nbox; 0033 for ii=1:length(nnbox); 0034 nbox=nnbox(ii); 0035 %filter weights 0036 box=ones(nbox,1)./nbox; 0037 [m,n]=size(u); 0038 if(min(m,n)==1), 0039 m=length(u); 0040 n=1; 0041 u=u(:); 0042 end 0043 if (m<length(box)), 0044 disp('data too short for this filter!!'); 0045 return 0046 end 0047 ufilt=zeros(m-nbox+1,n); 0048 for i=1:n, 0049 uf=conv(u(:,i),box); 0050 ufilt(:,i)=uf(nbox:(length(uf)-(nbox-1))); 0051 end 0052 jdf=conv(jd(:),box); 0053 jdf=jdf(nbox:(length(jdf)-(nbox-1))); 0054 end 0055 [m,n]=size(ufilt); 0056 if (nargin==4) 0057 ufilt=ufilt([1:nsamp:m],:); 0058 jdf=jdf([1:nsamp:m]); 0059 end