3
$\begingroup$
plot(fft(fft(1:100),inverse = "true")/100)
plot(1:100)

In the above example, I was expecting the plots to be identical.

The first, however, returns: enter image description here

while the second returns: enter image description here

which is what I would have expected after inverting (so as to retrieve the original series, the vector $\{x_{t}\} = (1, \dots , 1000)$). Why is this not the case and how can I retrieve the original series from its FFT?

EDIT: It seems that it must be due to the "Re" function, however each returned number is (for the $j$th element of the vector) $x_{j} = x_{j} + 0i$.

$\endgroup$
1
$\begingroup$

Your first plot is not analogous to the second plot which is why they look so different. In the following R code I will take your initial series, transform it via the unitary DFT, inverse transform it, and then plot graphs that compare the two series. As you can see, they are almost the same, other than a small amount of rounding error.

#Create series of values with FFT and inverse-FFT
SERIES1 <- 1:100;
FFT     <- fft(SERIES1)/sqrt(length(SERIES1));
SERIES2 <- fft(FFT, inverse = TRUE)/sqrt(length(SERIES1));

#plot series against each other
plot(SERIES1, Mod(SERIES2), main = 'Effect of FFT and inverse-FFT on series',
     xlab = 'Original Series', ylab = 'Modulus of Second Series');

#plot differences (due to rounding)
plot(SERIES1 - Mod(SERIES2), main = 'Effect of FFT and inverse-FFT on series',
     xlab = 'Index', ylab = 'Difference between Series Modulus');

enter image description here

enter image description here

$\endgroup$
3
$\begingroup$

The problem is that you're feeding a complex valued array to plot, so it is plotting both the imaginary Im() and the real part Re(), as you can see by the axis labels.

To achieve what you want you need to feed only the real part:

plot(Re(fft(fft(1:100),inverse = "true")/100))

Now, the reason the imaginary part is not equal 0, but rather is around 1e-14, might just be a rounding error.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.