function out=ApDm(x,M,N,U)
%
% function out=ApDm(x,M,N,U)
%
% compute aperture filtered Dirichlet function
%   out=sum_{k=-L}^L U(k) Dm(x+k,M,N)
% over N mod period
%
% uses the routine Dm.m

% written by D.G. Long at BYU 10 Dec. 2005

if length(U) == 1  % special case
  out=U(1)*Dm(x,M,N);
else
  L=(length(U)-1)/2;
  k=[-L:L];
  X=mod(x+k(1)+N,N);
  out=U(1)*Dm(X,M,N);
  for l=2:length(U)
    X=mod(x+k(l)+N,N);
    out=out+U(l)*Dm(X,M,N);
  end
end