% Set up sample rate, and function
N = 128;
T = (0:(N-1))/(N-1);
X = T.^3+T.^2+cos(20*T);
%X = rand(size(T))

% symmetric extension and fft
eX = [X,fliplr(X)];
feX = fft(eX);
reX = abs(feX);
aeX = angle(feX);

% plot function
figure(1)
subplot(2,1,1)
plot(X)
axis( [0,N-1,min(X),max(X)]); axis tight
title('original')
subplot(2,1,2)
plot(eX)
axis( [0,2*N-1,min(X),max(X)]); axis tight
title('symmetrically extended')
disp('Press a key'); pause

% plot fft's 
figure(2)
subplot(2,1,1)
plot(reX);  axis tight
title('amplitude of DFT')
subplot(2,1,2)
plot(aeX);  axis tight
title('phase of DFT')
disp('Press a key'); pause

% plot dct
F = (0:(2*N-1));
E = exp(pi*i*F/(2*N));
dctX = real(feX ./E);
figure(3)
subplot(2,1,1)
plot(real(dctX));  axis tight
title('unnormalized DCT')
subplot(2,1,2)
plot(angle(E));  axis tight
title('linearphase')


