function yf = dtwin(y, f_dt, win_type)


[nr, nc] = size(y);

x = (1:nr)';
% Detrend each column.
for j = 1:nc
   yc = y(:,j);
   c = polyfit(x,yc,f_dt);
   y(:,j) = yc - polyval(c, x);
end

% Build the window. 
if win_type == 'w'
   w = 1 - ( (x - 0.5*(nr-1)) / (0.5*(nr+1)) ).^2;
elseif win_type == 'p'
   w = 1 - abs( (x - 0.5*(nr-1)) / (0.5*(nr+1)) );
elseif win_type == 'n'
   w = ones(nr,1);
else
   error('dtwin: invalid win_type; must be w, p, or n');
end

%Normalize to preserve variance.
rmsw = sqrt(mean(w.^2));
w = w/rmsw;

% Window each column
ww = w(:,ones(1,nc));
yf = y .* ww;

