Hello,
I have two codes here. Matlab code is the reference code and I have written this C++ code from that.Don’t worry about the values because i just want to know if the logic of the C++ code is same as MATLAB code coz I am getting some incorrect values as output. However I have declared a few values so that u get some clue of its datatype.
Promptcode, earlycode and latecode each has a random combination of +/- 1’s.
Cacode has 1025 random combination of +/- 1’s. Assuming that you won’t bother much on these variable values, please check the logic of the two.
Here’s the matlab code [Reference code]:
Here’s the C++ code:
Thanks,
Prads
I have two codes here. Matlab code is the reference code and I have written this C++ code from that.Don’t worry about the values because i just want to know if the logic of the C++ code is same as MATLAB code coz I am getting some incorrect values as output. However I have declared a few values so that u get some clue of its datatype.
Promptcode, earlycode and latecode each has a random combination of +/- 1’s.
Cacode has 1025 random combination of +/- 1’s. Assuming that you won’t bother much on these variable values, please check the logic of the two.
Here’s the matlab code [Reference code]:
Code:
tcode = (remCodePhase-earlyLateSpc) : ... codePhaseStep : ... ((blksize-1)*codePhaseStep+remCodePhase-earlyLateSpc); tcode2 = ceil(tcode) + 1; earlyCode = caCode(tcode2); % Define index into late code vector tcode = (remCodePhase+earlyLateSpc) : ... codePhaseStep : ... ((blksize-1)*codePhaseStep+remCodePhase+earlyLateSpc); tcode2 = ceil(tcode) + 1; lateCode = caCode(tcode2); % Define index into prompt code vector tcode = remCodePhase : ... codePhaseStep : ... ((blksize-1)*codePhaseStep+remCodePhase); tcode2 = ceil(tcode) + 1; promptCode = caCode(tcode2); remCodePhase = (tcode(blksize) + codePhaseStep) - 1023.0; %% Generate the carrier frequency to mix the signal to baseband ----------- time = (0:blksize) ./ settings.samplingFreq; % Get the argument to sin/cos functions trigarg = ((carrFreq * 2.0 * pi) .* time) + remCarrPhase; remCarrPhase = rem(trigarg(blksize+1), (2 * pi)); % Finally compute the signal to mix the collected data to % bandband...baseband carrCos = cos(trigarg(1:blksize)); carrSin = sin(trigarg(1:blksize)); %% Generate the six standard accumulated values --------------------------- % First mix to baseband qBasebandSignal = carrCos .* rawSignal; iBasebandSignal = carrSin .* rawSignal; % Now get early, late, and prompt values for each I_E = sum(earlyCode .* iBasebandSignal); Q_E = sum(earlyCode .* qBasebandSignal); I_P = sum(promptCode .* iBasebandSignal); Q_P = sum(promptCode .* qBasebandSignal); I_L = sum(lateCode .* iBasebandSignal); Q_L = sum(lateCode .* qBasebandSignal);
Code:
long int i_ecode=0,i_lcode=0,i_pcode=0,tcode2,blksize; int *cacode=new int[1025],i_time, i_trigarg; int *earlycode=new int[38200],*latecode=new int[38200],*promptcode=new int[38200]; double *carrcos=new double[38200],*carrsin=new double[38200],*ibasebandsignal=new double[38200], *qbasebandsignal=new double[38200]; double *temp1=new double[38200],*temp2=new double[38200],*temp3=new double[38200]; double *temp4=new double[38200],*temp5=new double[38200],*temp6=new double[38200]; double i_e=0,q_e=0,i_p=0,q_p=0,i_l=0,q_l=0; double tcode,remcodephase,earlylatespc,codephasestep, *time=new double[38200], *trigarg=new double[38200], carrfreq ; for(tcode=remcodephase-earlylatespc;tcode<=((blksize-1)*codephasestep+remcodephase-earlylatespc);) { tcode2=ceil(tcode)+1; earlycode[i_ecode]=cacode[tcode2-1]; i_ecode+=1; tcode=tcode+codephasestep; } for(tcode=remcodephase+earlylatespc;tcode<=((blksize-1)*codephasestep+remcodephase+earlylatespc);) { tcode2=ceil(tcode)+1; latecode[i_lcode]=cacode[tcode2-1]; i_lcode+=1; tcode=tcode+codephasestep; } for(tcode=remcodephase;tcode<=((blksize-1)*codephasestep+remcodephase);) { tcode2=ceil(tcode)+1; promptcode[i_pcode]=cacode[tcode2-1]; i_pcode+=1; tcode=tcode+codephasestep; } remcodephase=tcode-1023.0; //========================Generate the carrier frequency to mix the signal to baseband=================================== for(i_time=0;i_time<=blksize;i_time++) { settings.samplingfreq=38000; time[i_time]= i_time/settings.samplingfreq; trigarg[i_time]=((carrfreq*2*PI)*time[i_time]) + remcarrphase; } remcarrphase= trigarg[blksize]-((trigarg[blksize]/(2*PI)) *(2*PI)); for(i_trigarg=0;i_trigarg<=blksize-1;i_trigarg++) { carrcos[i_trigarg]=cos(trigarg[i_trigarg]); carrsin[i_trigarg]=sin(trigarg[i_trigarg]); } //======================== Generate the six standard accumulated values =================================== for(i_trigarg=0;i_trigarg<=blksize-1;i_trigarg++) { qbasebandsignal[i_trigarg]=carrcos[i_trigarg]*rawsignal[i_trigarg]; ibasebandsignal[i_trigarg]=carrsin[i_trigarg]*rawsignal[i_trigarg]; temp1[i_trigarg]=earlycode[i_trigarg]*ibasebandsignal[i_trigarg]; i_e=i_e+temp1[i_trigarg]; temp2[i_trigarg]=earlycode[i_trigarg]*qbasebandsignal[i_trigarg]; q_e=q_e+temp2[i_trigarg]; temp3[i_trigarg]=promptcode[i_trigarg]*ibasebandsignal[i_trigarg]; i_p=i_p+temp3[i_trigarg]; temp4[i_trigarg]=promptcode[i_trigarg]*qbasebandsignal[i_trigarg]; q_p=q_p+temp4[i_trigarg]; temp5[i_trigarg]=latecode[i_trigarg]*ibasebandsignal[i_trigarg]; i_l=i_l+temp5[i_trigarg]; temp6[i_trigarg]=latecode[i_trigarg]*qbasebandsignal[i_trigarg]; q_l=q_l+temp6[i_trigarg]; }
Prads