clear all
close all

N = 16;
x = randn(1,2*N);
X = fft(x);


xeven   = x(1:2:end);
xodd    = x(2:2:end);

z = xeven + 1i*xodd;
Z = fft(z);


Zre = real(Z);
Zim = imag(Z);
Zreflip = [Zre(1) Zre(end:-1:2)];
Zimflip = [Zim(1) Zim(end:-1:2)];



n = 0:1:N-1;


Xre = (Zre+Zreflip)/2 + cos(pi/N*n).*(Zim+Zimflip)/2 - sin(pi/N*n).*(Zre-Zreflip)/2
Xim = (Zim-Zimflip)/2 - sin(pi/N*n).*(Zim+Zimflip)/2 - cos(pi/N*n).*(Zre-Zreflip)/2

X2 = Xre + 1i*Xim

figure(1)
subplot(211)
plot(real(X(1:N)),'ko-')
hold on
plot(Xre(1:N),'y*-')
subplot(212)
plot(imag(X(1:N)),'ko-')
hold on
plot(Xim(1:N),'y*-')