Converting some matlab to C (or C++)
Afficher commentaires plus anciens
Hi there,
I have been working through the Matlab function fir2 -
I'm converting it to C++ line by line.
I'm currently at the following section in the m-file where it performs the Fourier Time Shift -
% Fourier time-shift.
dt = 0.5 .* (nn - 1) rad = -dt .* sqrt(-1) .* pi .* (0:npt-1) ./ (npt-1);
I can find dt, ok.
But for rad, I'm getting 'NaN', due to the sqrt(-1) operation. So I'm thinking I need to be handling the imaginary \ complex number here with something like std::complex
I'm reading this part of the matlab code as something equivalent to this in C -
!!! Please see attached file as I couldnt write formatted C++ code here.. Thanks !!!
The C++ output looks ok for the imaginary part, but the real part is non zero, and also negative. So I must be doing something wrong here..
Any ideas?
Thanks in advance
2 commentaires
Adam
le 12 Fév 2015
What does sqrtMinusOne output as in debug?
Is it precisely 0 - 1i?
If not then I assume the error is just a rounding error, but otherwise it is hard to see why it is non-zero with only multiplication operations.
It is a while since I used std::complex so I assume it overloads multiplication by a double otherwise your code just wouldn't compile anyway!
Gilbert S
le 12 Fév 2015
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!