0
$\begingroup$

I apply ifft after fft, but the result is not the same (x-fft(ifft(x)) is different from zero)? Where is the mistake?

$\endgroup$
12
  • 1
    $\begingroup$ Do you mean nonzero such as $10^{-15}$ terms...? (assuming normalized input) $\endgroup$
    – Fat32
    Commented Feb 2, 2022 at 22:26
  • $\begingroup$ No, more 10^7 where x is of the order of 10^8 $\endgroup$
    – userxxxxx
    Commented Feb 3, 2022 at 0:11
  • $\begingroup$ Maybe something with fftshift, but I already checked that... $\endgroup$
    – userxxxxx
    Commented Feb 3, 2022 at 0:11
  • $\begingroup$ Can you provide an example that reproduces the problem? $\endgroup$ Commented Feb 3, 2022 at 1:33
  • $\begingroup$ @GrapefruitlsAwesome: of course, I will edit the question $\endgroup$
    – userxxxxx
    Commented Feb 3, 2022 at 11:33

1 Answer 1

2
$\begingroup$

This is numerical noise. Matlab uses 64-bit floating point numbers and so the results are not the same that you would get with infinite precision or with pencil and paper.

Typical signal to noise ratio would be in the range of 300 dB

See example

%% FFT numerical noise
x = randn(1024,1); % start with normal distributed noise
% FFT and back calculate difference
d = ifft(fft(x))- x;
fprintf('Error = %6.2fdB\n',10*log10(sum(d.^2)./sum(x.^2)));

Comes out below -300dB

Update Complex example:

Same result for complex data

%% complex
x = randn(1024,1)+1i*rand(1024,1); % start with normal distributed noise
% FFT and back calculate difference
d = ifft(fft(x))- x;
% error
fprintf('Error = %6.2fdB\n',10*log10(sum(d.*conj(d))./sum(x.*conj(x))));
$\endgroup$
5
  • $\begingroup$ There is a fairly large difference still (50%) $\endgroup$
    – userxxxxx
    Commented Feb 3, 2022 at 0:10
  • 1
    $\begingroup$ Then you are doing something wrong. I added at example $\endgroup$
    – Hilmar
    Commented Feb 3, 2022 at 0:59
  • $\begingroup$ it is with complex numbers signal $\endgroup$
    – userxxxxx
    Commented Feb 3, 2022 at 11:33
  • $\begingroup$ I edited the question $\endgroup$
    – userxxxxx
    Commented Feb 3, 2022 at 11:38
  • $\begingroup$ @userxxxxx: complex makes no difference here . See updated answer $\endgroup$
    – Hilmar
    Commented Feb 3, 2022 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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