function x = reconstruct(magnitude, phase)
% RECONSTRUCT - Given a vector of magnitudes and a vector
% of phases, construct a signal that has these magnitudes
% and phases as its discrete Fourier series coefficients.
% The arguments are assumed to have odd length, p/2 + 1,
% and the returned vector will have length p.
p = 2 * (length(magnitude) -1);
wo = 2 * pi / p;

x = zeros (1, p);
for n = 0 : p - 1
    for k = 0 : length (magnitude) - 1
        x(n+1) = x(n+1) + magnitude(k+1) * cos(k*wo*n + phase(k+1));
    end
end
plot(x);