gabhades
Newbie level 4
- Joined
- Jan 21, 2013
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,330
Hi guys,
this is almost exactly the same problem as this already solved one:
https://www.mathworks.de/matlabcent...n-directly-called-in-matlab-and-called-in-exp
In the linked case, it can be resolved through explicitly converting 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:
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)
(C++)
The result in MATLAB is
But in C++ it is
Is there any possible solution for this problem? Thanks alot!
this is almost exactly the same problem as this already solved one:
https://www.mathworks.de/matlabcent...n-directly-called-in-matlab-and-called-in-exp
In the linked case, it can be resolved through explicitly converting 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:
Code:
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)
Code:
for (i=1:1000)
x(i)=sin(2*3.14*(i-1)/50);
end
(C++)
Code:
for (int i=0;i<1000;i++)
x_in->data[i]=sin(2*3.14*i/50)
The result in MATLAB is
Code:
0.0480, 0.0543, 0.0703, 0.0917, 0.1164, 0.1440, 0.1746, 0.2087, 0.2471 ...
But in C++ it is
Code:
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!