
%
% Applies a discrete filter (coefficients b and a) forward and backward in
% order to add no delay to the original signal
% 
% If asked (removeTransient), it also sets at NaN the first and last
% 2*N+1 values, where N = length(a) (that is, the order of the filter)
%


function out = filter_updn(b,a,in,removeTransient)

tmp = filter(b,a,in);
tmp = filter(b,a,flipud(tmp));
out = flipud(tmp);

if removeTransient
    N = length(a);
    nTrans = 2*N+1;
    out(1:nTrans)         = NaN;
    out(end-nTrans+1:end) = NaN;
end


