I did fft in matlab and in java using jtransforms library but the results are slightly different.
Matlab results:
-0.0530528652679544
-0.00775535711930750 + 0.0281791646147104i
-0.0304104457750988 - 0.209776156064443i
0.266945753193636 + 0.200338044445226i
Jtransforms results:
-0.05305448436232618
-0.007755593801247046 + 0.028180024600812384
-0.03041137385657606 -0.20978255812004887
0.26695389998013486 + 0.20034415846373468
Are the results different or Matlab is just rounding the values?
Description. Y = fft( X ) computes the discrete Fourier transform (DFT) of X using a fast Fourier transform (FFT) algorithm. If X is a vector, then fft(X) returns the Fourier transform of the vector. If X is a matrix, then fft(X) treats the columns of X as vectors and returns the Fourier transform of each column.
Y = fft(X,n,dim); Calculate the double-sided spectrum and single-sided spectrum of each signal. P2 = abs(Y/L); P1 = P2(:,1:n/2+1); P1(:,2:end-1) = 2*P1(:,2:end-1); In the frequency domain, plot the single-sided amplitude spectrum for each row in a single figure.
In MATLAB, the Fourier command returns the Fourier transform of a given function. Input can be provided to the Fourier function using 3 different syntaxes. Fourier(x): In this method, x is the time domain function whereas the independent variable is determined by symvar and the transformation variable is w by default.
Y = fft(y,NFFT)/Datapoints; fs=Datapoints/Length; f = fs/2*linspace(0,1,NFFT/2+1);
There are several different algorithms for doing FFT. In principle they're all equal, but in practice, combined with floating-point arithmetic, the results will be slightly different. Even if the basic FFT algorithm is the same, implementation details such as order of summation can cause differences. Many modern processors do this even if you don't do anything special, depending on the optimization flags.
In your results, the differences are at about 5th significant digit. It's a reasonably small difference. You could try inverse transforming the results (using both Matlab and JTransforms IFTs) to see whether one or the other of the transforms is clearly more accurate.
The differences appear to be larger than normal numerical precision issues for double precision floating point arithmetic. It looks more like one of the FFTs is using some short float arithmetic or data instead, and printing the result out as doubles (which makes all those extra digits a lot of nonsense).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With