Your calculation of remcarrphase appears to be incorrect. In the MATLAB code, it is calculated as the remainder after division of trigarg(blksize+1) by 2*PI. In the C++ version, it is calculated as:
CODE
remcarrphase= trigarg[blksize]-((trigarg[blksize]/(2*PI)) *(2*PI))
However, if you perform an algebraic simplification of this, you wind up with:
CODE
remcarrphase= trigarg[blksize]-trigarg[blksize]
//therefore
remcarrphase=0
Based on the MATLAB code, you should be using the modulus function in the C++ version instead:
CODE
remcarrphase= fmod( trigarg[blksize], (2.0*PI) );
This returns and assigns the appropriate remainder-after-division to remcarrphase. Though given that this variable doesn't get used anywhere after that point (at least in the code you've posted), I'm not sure if that will fix your problem.
When you're debugging like this, where you know what the values SHOULD be at any given point, it's good practice to output the values of your variables (the scalar ones, at least) to the console. That way, you can compare them and see where exactly the problem is arising.
Also, it's a good idea to post a "minimal working example" code, with all of the necessary variables declared an initialized, all of the necessary headers and a main() routine, so that the other members can actually run it and see what's going on. Frequently, when you're paring down the code to the minimum amount of code required to generate the same problem, you will discover the problem yourself. Additionally, it makes it way easier on everyone else, because we either don't have to spend a lot of time getting the code to a point where it actually works, or we don't have to make a guess about what's wrong with code that doesn't actually work in the form presented (which is the case here).
Hope that helps. I can't tell if there are also other problems, but that's at least one thing tha you can check up on

-jjh
This post has been edited by jjhaag: 25 Nov, 2007 - 03:16 PM