function dout = filter_nr(vect, data, wgtscale); % % dout = filter_nr(weights, data, wgtscale); % % Non-recursive filtering using centered weights % % Inputs: % weights are the non-recursive weights (e.g., [1 2 1]/4) % data will be smoothed in the column dimension % wgtscale (optional): flag (0 = use raw weights, 1 = make % sum of 'weights' = 1). % % Outputs: % dout is the filtered output data. If the length of weights % is odd, then there will be no phase shift. But, the % first (length(weights)-1)/2 points are affected by the % endpoints. % if nargin == 2; wgtscale = 1; end if ndims(data) > 2; reshape_data = 1; sz_dat = size(data); data = reshape(data, sz_dat(1), prod(sz_dat(2:end))); else reshape_data = 0; end lvect = length(vect); if ~mod(lvect,2); error('This will introduce a phase shift. Please use odd number of weights'); end if wgtscale; vect = vect/sum(vect); end [ntim, nx] = size(data); kp = ((length(vect)-1)/2)+[1:ntim]; dout = repmat(NaN, [ntim nx]); for i = 1:nx; tem = conv(vect, data(:,i)); dout(:,i) = tem(kp); end if reshape_data; dout = reshape(dout, sz_dat); end