 function cv = dtfs1(xv)
%function cv = dtfs1(xv)
% This matlab function computes and returns the N DTFS coefficients
% of a DT periodic signal, given the N samples of that signal
% stored in the input vector xv.

% Caution: unlike C, matlab indexes vectors starting with 1.
% so xv(1) = x(0), xv(2) = x(1), ...
% and cv(1) = c_0, ..., cv(N) = c_{N-1}.  This is important!
% ask if you don't understand the "k+1" in line below!

% You can complete this just by appropriately replacing the
% two ?'s below with about a dozen letters.
% (There are also less efficient ways to do it that require more lines of code.)

% Optional challenge: using matrices, you can rewrite this program
% without *any* loops!
% Try using the "tic" and "toc" commands to compare execution
% speed in this version and in a version with no loops
% for a problem with large "N"

N = length(xv);		% determine signal period (in samples)
n = [0:(N-1)]';		% a handy vector

cv = zeros(N,1);	% allocate space for N DTFS coefficients
			% (do you know why it is preferable to do this here?)

for k=0:(N-1)		% loop over coefficients
	? = exp(-1j * 2 * pi * k * n / N);	% you complete
	cv(k+1) = (1/N) * ?			% you complete
end

% Hint: use a "sum" command somewhere...
