I apply ifft
after fft
, but the result is not the same (x-fft(ifft(x))
is different from zero)? Where is the mistake?
-
1$\begingroup$ Do you mean nonzero such as $10^{-15}$ terms...? (assuming normalized input) $\endgroup$– Fat32Feb 2, 2022 at 22:26
-
$\begingroup$ No, more 10^7 where x is of the order of 10^8 $\endgroup$– userxxxxxFeb 3, 2022 at 0:11
-
$\begingroup$ Maybe something with fftshift, but I already checked that... $\endgroup$– userxxxxxFeb 3, 2022 at 0:11
-
$\begingroup$ Can you provide an example that reproduces the problem? $\endgroup$– GrapefruitIsAwesomeFeb 3, 2022 at 1:33
-
$\begingroup$ @GrapefruitlsAwesome: of course, I will edit the question $\endgroup$– userxxxxxFeb 3, 2022 at 11:33
1 Answer
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))));
-
$\begingroup$ There is a fairly large difference still (50%) $\endgroup$ Feb 3, 2022 at 0:10
-
1$\begingroup$ Then you are doing something wrong. I added at example $\endgroup$– HilmarFeb 3, 2022 at 0:59
-
-
-
$\begingroup$ @userxxxxx: complex makes no difference here . See updated answer $\endgroup$– HilmarFeb 3, 2022 at 14:52