-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FFTS output difference with fft in Matlab #55
Comments
Hi! It cannot be a big problem, but it would help if you could provide code snippet how you have used FFTS? And have you looked at the examples and test cases? |
@linkotec I use java jni call:
And this code use JWave https://github.com/cscheiblich/JWave (output same with matlab fft)
But it give difference output. I guess it may has the same spectrum but i am not sure. |
I assume that "displaySamples" contains complex numbers, in-order re1 im1 re2 im2... And the actual FFT length is FFT_size/2, as FFT_size is the size of float array. Right away I don't see anything wrong, but what is magnitude of difference between JWave and FFTS? FFTS uses internally 32 bit float, and JWave uses Java native 64 bit double all the way, so that will result in loss of accuracy when using FFTS. |
@linkotec I have edited the code above to use real, not complex, it is 1d array with float or double. And then i get magnitude by those code:
But it far difference, i don't know if i miss understand about ffts. I tested with simple array and they are not the same. |
This is the code i test:
FFTS:
|
I am sure that the problem is lack of FFTS documentation #12, but there might also be a bug in JNI. I am not using Java or JNI interface so I can only provide you with C versions and explanation. Here is MSVC C code version of your complex problem:
Input x has 8 complex numbers, where imaginary parts are set to zero, thus real numbers. After execute output X contains 8 complex numbers. The result is "same" as with Matlab:
But your input is pure real numbers, so you should use real valued transform. Now if you look at https://github.com/anthonix/ffts/blob/master/include/ffts.h , comment says "The output of a real-to-complex transform is N/2+1 complex numbers, where the redundant outputs have been omitted." When input data is purely real numbers, DFT output satisfies the Hermitian redundancy; output[n-i] is complex conjugate of output[i]. Output[0] is the DC, output[N/2] is the Nyquist. Here is real version in C:
Input x has 8 real numbers, and output is (8/2)+1=5 complex numbers,
I didn't find any open issues or commits regarding JNI, but for some reason your test is missing the Nyquist frequency, last component -4.0000000 + 0.00000000i This needs more testing. |
Yes you are right, JNI code has some bug (maybe JNI author not understand real DFT in FFTS ) https://github.com/anthonix/ffts/blob/master/java/jni/ffts_jni.c he use the same size, it must be the length of input and output array. After fix this, the result the same with you. |
If you can push your fix, I would like to include that to my repo. I have totally discarded GNU autoconf configure scripts, so there may be a lot of things to fix. I cannot make any promises for Android support, but I have now enabled the issue tab. |
Hello, I am converting code from Matlab to java/c to use in Android device. I can do this with pure java fft lib like Jtransform and Jwave but it slow. I want to use FFTS but the out put not the same, i don't know why.
The text was updated successfully, but these errors were encountered: