clear all
close all

N = 16;
x = randn(1,N);
y = randn(1,N);

X = fft(x);
Y = fft(y);


z = x + 1i*y;
Z = fft(z);


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

X2 = (Zre + Zreflip)/2 + 1i * (Zim - Zimflip)/2;
Y2 = (Zim + Zimflip)/2 - 1i * (Zre - Zreflip)/2;

figure(1)
subplot(411)
    plot(abs(X2),'bo-')
    hold on
    plot(abs(X),'rx-')
    legend('From X', 'From Z')
    title('abs(X)')    
subplot(412)
    plot(angle(X2),'bo-')
    hold on
    plot(angle(X),'rx-')
    legend('From X', 'From Z')
title('angle(X)')    
subplot(413)

    plot(abs(Y2),'bo')
    hold on
    plot(abs(Y),'rx-')
    legend('From X', 'From Z')
title('abs(Y)')    
subplot(414)
    plot(angle(X2),'bo-')
    hold on
    plot(angle(X),'rx-')
    legend('From X', 'From Z')
    title('angle(Y)')