why FFT result and IFFT result has diffrent in very small value? how to avoid this to increase precission?

14 vues (au cours des 30 derniers jours)
I read from the book that IFFT from FFT result as ifft(ftt(signal)) wil give us the original signal. I try to substract both of them, but i get very small difference of both of them. Does it mean my coding is not corect or limitation in precission calculation by matlab (caused by rounded maybe).
here I provide my code, please help me to evaluate and show if there is a mistake that i make
clc
clear
t=0:0.01:2;
n=length(t);
srate=100; %sampling rate
nyq=srate/2;
data=5*sin(2*pi*2*t)+3*sin(2*pi*10*t);
%dataX=fft(data(:,2))/n;
hz=linspace(0,nyq,floor(n/2)+1);
dataX=fft(data)/n;
recon_data=ifft(dataX)*n;
figure(7), clf
subplot(411),plot(t,data)
subplot(412),plot(hz,2*abs(dataX(1:length(hz))),'-r')
xlim([0 15]), xticks(1:1:15)
subplot(413),plot(t,data,'-b',t,real(recon_data),'--r',linewidth=2)
subplot(414),plot(t,real(recon_data)-data)

Réponse acceptée

David Goodmanson
David Goodmanson le 15 Sep 2023
Modifié(e) : David Goodmanson le 16 Sep 2023
Hi nirwana,
This is totally normal behavior, just computation being computation. Matlab uses double precision arithmetic with approximately 16 decmal digits. So you would expect some imprecision down around several parts in 10^16, which is what you get here. You can get more precision using vpa (variable precision arithmetic), but most people feel that once you know what is going on, precision at the level you are getting already is perfectly acceptable.
Of course there are situations such as obtaining a small result by subtracting two very large numbers, where the error can become unacceptable. Then you would have to change the method of calulation, but that's not the case here.

Plus de réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by