FFT of real valued even vector in MATLAB is not real

50 Views Asked by At

I am trying to find the PSD of a signal by taking the DFT of its auto-covariance sequence. My code is as follows

% define constants
m = 256;
k = 0:m - 1;
a1 = -0.9;
b1 = 0.8;
sigma = 1;

% compute ACS for positive lags k
r = (sigma^2 / (1 - abs(a1)^2)) * ( (1 + abs(b1)^2) * d(k) + b1 * d(k - 1) + conj(b1) * d(k + 1));
% compute acs from -(m-1) to +(m-1)
acs = [flip(r(2:end)) r];

% compute PSD
phi = fft(acs);


% auxilliary function that helps in the computation of the ACS
% it computes the function
% d(k) = (-a1)^k, k >=0,
%        (-a1*)^(-k), k < 0
function d = d(x)
    a1 = -0.9;
    x1 = x >= 0;
    x2 = ~x1;

    d = x1 .* (-a1).^x + x2 .* (-conj(a1)).^(-x);
end

The acs variable is plotted as

enter image description here

and can be seen to be even. However when i take the fft of the acs the results i get are: for the real part

enter image description here

and for the imaginary part

enter image description here

0

There are 0 best solutions below