Wiener–Khinchin theorem states that autocorrelation function and power spectral density are a Fourier-transform pair - see Wikipidia (and lots of other resources).
That means autocorrelation should be able to be obtained by inverse Fourier transform the spectrum. The following code (run within Octave, with "pkg load signal") shows the Fourier transform of the autocorrelation DOES look like the spectrum, but the inverse Fourier transform of the spectrum does not look like the autocrrelation. What did I do wrong?
### A signal's autocorrelation and its Engergy Spectral Density are Fourier transform pairs.
### signal
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
#plot(x);
### autocorrelation
Rxx = xcorr(x);
#figure();
plot(Rxx); title("Rxx");
### autocorrelation FT
RxxDftAbs = abs(fftshift(fft(Rxx)));
freq = -Fs/2:Fs/length(Rxx):Fs/2-(Fs/length(Rxx));
figure();
plot(freq,RxxDftAbs); title("RxxDftAbs");
### Energy Spectral Density
xdft = abs(fftshift(fft(x)));
x_esd = xdft.^2; # ESD is the same as autocorrelation FT. Here for visualization purpose, using absolute values.
freq = -Fs/2:Fs/length(x_esd):Fs/2-(Fs/length(x_esd));
figure();
plot(freq,x_esd); title("x esd");
### ?????????????
### is it possible to get autocorrelation from the ESD by inverse Fourier transform?
### ?????????????
### IFT of ESD
x_esd_idft_abs = abs(ifft(fftshift(x_esd)));
figure();
plot(x_esd_idft_abs); title("x esd ift");
Thanks in advance.

