FFT is getting wrong result when exported to C/C++ by MATLAB Coder
Mostrar comentarios más antiguos
Hi guys,
this is almost exactly the same problem as I got in this question, which is already solved:
In the last case, I explicitly converted every integer variable into double format to force it being calculated exactly enough through all the process. However, as I called the FFT function, this has become more difficult. It seems that the original MATLAB code for FFT is meeting the same problem, but obviously I have no chance to edit the fft source code - even if I had it would be no good solution neither coz I cannot do this for every matlab function in my programming.
For example, a matlab function fft_test is implemented as following:
function X = fft_test(x)
X = abs(fft(x));
end
And after the export in C++ I have a function
extern void fft_test(const emxArray_real_T *x, emxArray_real_T *X);
Given a same input series:
(MATLAB)
for (i=1:1000)
x(i)=sin(2*3.14*(i-1)/50);
end
(C++)
for (int i=0;i<1000;i++)
x_in->data[i]=sin(2*3.14*i/50)
The result in MATLAB is
0.0480, 0.0543, 0.0703, 0.0917, 0.1164, 0.1440, 0.1746, 0.2087, 0.2471 ...
But in C++ it is
2.16108, 0.621004, 0.339259, 0.305906, 0.453614, 0.696989, 0.773992, 0.648152...
Is there any possible solution for this problem? Thanks alot!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!