function y = dtft(f,x,nvec)
%dtft  Compute the discrete-time Fourier transform.
%
%   y = sum_n xn*exp(-j*2*pi*f*n),
%
%   where n takes values from the vector
%   nvec = [n1,...,n2], and
%   x = [ x_{n1}, ..., x_{n2} ].

fvec = reshape(f,1,prod(size(f))); % convert f to row vector
y = x*exp(-j*2*pi*nvec.'*fvec);
y = reshape(y,size(f)); % make output have shape of f.
