C中函数调用出错 [英] Error in function call in C

查看:84
本文介绍了C中函数调用出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SPADecoder函数不返回任何值。我在

SPADecoder函数

中添加了Print语句,而不是打印任何语句和值。



我无法找到

SPADecoder函数

中的错误。请指出我。谢谢



 #include< stdio.h> 
#include< math.h>

#define COL 204
#define COL_P 2
#define ROWS_P 1020

int codecheck(int(* h)[2],int x [])
{
int i,j,m,f; // flags
int sum = 0;
int y [COL];
for(i = 0; i< COL; i ++)
y [i] = 0;
m = 1;
f = -1;
for(i = 0; i< ROWS_P; i ++)
{
for(j = 0; j< COL_P; j ++)
{
if(h [ j] [0] == m)
{
y [m] = y [m] + x [h [j] [1] -1];
f ++;
}
}
y [m] = y [m]%2;
m = m + 1;
i = f + 1;
}

for(i = 0; i< COL; ++ i)
{
sum = sum + y [i];
}
if(sum == 0)
{
返回1;
}
其他
{
返回-1;
}

}

int codesum(int y [])
{
int sum = 0;
for(int i = 0; i< COL; i ++)
sum + = y [i];
// cout<< 总和= <<总和<< ENDL;
if(sum> 0)
返回0;
其他
返回1;
}

/ * void ModulationSchemeValues(int modulationScheme,int noOfSymbols,double var,float d,float rate,double snr)
{
switch(modulationScheme)
{
case 0:
// cout<<case 0<< endl;
var = 1 /(2 * rate * snr);
noOfSymbols = COL;
d = 1;
休息;
案例1:
// cout<<case 1<< endl;
var = 1 /(4 * rate * snr);
noOfSymbols = COL / 2;
d = 1 / sqrt(2);
休息;
case 2:
// cout<<case 2<< endl;
var = 1 /(8 * rate * snr);
noOfSymbols = COL / 4;
d = 1 / sqrt(10);
默认值:
var = 1 /(2 * rate * snr);
noOfSymbols = COL;
d = 1;
休息;
}
printf(%d%d%f%f%f%d,modulationScheme,noOfSymbols,var,d,rate,snr);
}

void InitializeChannelLLR(double var,int modulationScheme,int noOfSymbols,int x [],float noise [],double L_ch [],float d,int(* h)[2 ],双LLR [])
{

int j = 0; //临时标志
int k = 0,t;
for(int i = 0; i< noOfSymbols; i ++)//使用randnoise函数将噪声引入所有零码字
{

x [j] = d;
noise [j] =(x [j])+ 0.8;
L_ch [j] = 2 * noise [j] / var;
j ++;


}


for(int j = 0; j< ROWS_P; j ++)
{
// cout< ;<enter loop<< endl;
// cout<< J = << J<< ENDL; //<< J<< \t;
t = h [j] [1] -1;
LLR [j] = L_ch [t];
}
// cout<<L_ch initialize done \ n;

} * /

int SPADecoder(double LLR [],int(* h)[2],double LLR_ret [],double L_ch [],double L_dec [] ,int y [])
{

double temp;
int z;
int i,j,k;
for(i = 0; i< ROWS_P; i ++)
{
temp = 1;
for(j = 0; j< ROWS_P; j ++)
{
if(j!= i&& h [j] [0] == h [i] [0 ])
{
temp = temp * tanhf(LLR [j] / 2);
}
}
LLR_ret [i] = log((1 + temp)/(1 - temp)); //下限和上限LLR

if(LLR_ret [i]> 40)
{
LLR_ret [i] = 40;
}
else if(LLR_ret [i]< -40)
{
LLR_ret [i] = - 40;
}

}

for(i = 0; i< COL; i ++)/
{
L_dec [i] = L_ch [一世];
}


for(i = 1; i< COL + 1; i ++)
{
for(j = 0; j< ROWS_P; j ++)
{
if(h [j] [1] == i)
{
L_dec [i-1] = L_dec [i-1] + LLR_ret [j ]。
}

}

if(L_dec [i-1]< = 0)
{
y [i-1] = 1;
}
其他
{
y [i-1] = 0;
}

}


// z = codesum(y,col);
z = codecheck(h,y); //检查解码后的代码字是否全为零

if(z == 1)//如果完全解码则退出解码循环
{
return z;
}

for(i = 0; i< ROWS_P; i ++)
{
temp = 0;
for(j = 0; j< ROWS_P; j ++)
{
if(j!= i&& h [j] [1] == h [i] [1 ])
{
temp = temp + LLR_ret [j];
k = h [i] [1];

}
}
LLR [i] = temp + L_ch [k-1];
}
返回z;
}

int main()
{

//标志和计数器
int z,i,j,N,k, ber_count,循环,T,和;
float d = 1;
浮动利率= 0.5;

int maxTransmissions = 20,decoderIterations = 10,maxErrors = 50,errorsAccumulated = 0;
int y [COL]; /
int L,O,R,M = 0;

double var = 0,snr;
双倍温度; // temp variable

float noise [COL];
double L_ch [COL],L_dec [COL];
双LLR [ROWS_P],LLR_ret [ROWS_P];
双BER [11];
float snr_db [] = {0,1,2,3,4};
int snr_range = 5,snr_count;
int x [] = {1,1,1,0,0,1,0,1,0,1,0,0,1,1,0,1,0,1,0,1, 0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,1,1, 1,0,0,0,0,1,0,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,1,0, 1,0,1,1,0,1,1,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,1, 1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,0, 1,0,0,1,1,0,1,1,1};
int ret,row = 0;
double error_bits,error;
int modulationScheme = 0,noOfSymbols = 204;
int h [ROWS_P] [COL_P] = {{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130}, {1177},{1190},{1203},{2,2},{2,15},{2,75},{2,80},{2,86},{2104},{2121}, {2141},{2144},{2191},{3,3},{3,31},{3,32},{3,42},{3101},{3105},{3153},{3159 },{3178},{3199},{4,4},{4,37},{4,71},{4,75},{4,85},{4106},{4111},{4114 },{4127},{4164},{5,5},{5,17},{5,42},{5,72},{5,87},{5107},{5141},{5158 },{5193},{5197},{6,4},{6,6},{6,17},{6,78},{6102},{6108},{6162},{6165}, {6167},{6174},{7,7},{7,23},{7,73},{7,80},{7,83},{7109},{7118},{7168}, {7177},{7178},{8,8},{8,33},{8,37},{8.73},{8100},{8110},{8156},{8173},{8192 },{8197},{9,9},{9,40},{9,41},{9,88},{9,92},{9103},{9111},{9173},{9181 },{9199},{10,10},{10,14},{10,23},{10,53},{10,93},{10107},{10112},{10137},{10167 },{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11110},{11113},{11,116},{11170 },{11191},{12,1},{12,12},{12,25},{12,86},{12,97},{12108},{12114},{12124},{12161 },{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13115 },{13137},{13,140},{13146},{13160},{14,14},{14,31},{14,40},{14,58},{14,95},{14116 },{14,121},{14166},{14174},{14203},{15,15},{15,68},{15,70},{15,87},{15101},{15109}, {15113},{15,117},{15165},{15180},{16,4},{16,16},{16,59},{16.67},{16,92},{16118}, {16125},{16131},{16138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17119}, {17161},{17190},{17194},{17198},{18,18},{18,47},{18,62},{18,85},{18,93},{18120}, {18122},{18125},{18146},{18181},{19,19},{19,22},{19,23},{19,37},{19,57},{19121}, {19126},{19130},{19131},{19143},{20,1},{20,20},{20,50},{20,51},{20,99},{20106}, {20122},{20169},{20179},{20200},{21,21},{21,32},{21,62},{21,72},{21,98},{21123}, {21126},{21154},{21168},{21204},{22,22},{22,31},{22,44},{22,89},{22,98},{22124}, {22141},{22,160},{22169},{22176},{23,23},{23,32},{23,61},{23,65},{23,99},{23125}, {23132},{23,133},{23147},{23152},{24,16},{24,24},{24,42},{24,73},{24,77},{24126}, {24142},{24,145},{24146},{24147},{25,5},{25,24},{25,25},{25,5 5},{25,67},{25127},{25133},{25165},{25178},{25185},{26,10},{26,26},{26,27},{26, 40},{26,85},{26128},{26147},{26155},{26,160},{26,200},{27,22},{27,27},{27,42},{27, 50},{27,74},{27108},{27129},{27154},{27,170},{27195},{28,2},{28,28},{28,63},{28, 67},{28,94},{28130},{28,150},{28171},{28187},{28192},{29,29},{29,48},{29,69},{29, 79},{29,90},{29116},{29131},{29159},{29176},{29200},{30,7},{30,30},{30,53},{30, 58},{30,94},{30127},{30132},{30140},{30162},{30189},{31,29},{31,31},{31,64},{31, 77},{31,94},{31117},{31133},{31167},{31183},{31190},{32,20},{32,30},{32,32},{32, 74},{32,78},{32115},{32134},{32151},{32181},{32194},{33,11},{33,33},{33,47},{33, 76},{33,81},{33109},{33135},{33154},{33155},{33179},{34,2},{34,7},{34,34},{34, 71},{34,76},{34136},{34138},{34159},{34182},{34183},{35,27},{35,29},{35,35},{35, 60},{35,86},{35123},{35137},{35149},{35166},{35189},{36,17},{36,35},{36,36},{36, 48},{36,100},{36138},{36139},{36146},{36163},{36168},{37,5},{37,3 4},{37,37},{37,38},{37,69},{37117},{37139},{37145},{37169},{37203},{38,38},{38, 56},{38,76},{38,92},{38101},{38106},{38123},{38140},{38161},{38170},{39,39},{39,41} ,{39,60},{39,76},{39,78},{39125},{39141},{39142},{39175},{39198},{40,2},{40,35} ,{40,40},{40,43},{40,93},{40114},{40135},{40142},{40148},{40158},{41,1},{41,2} ,{41,13},{41,41},{41,59},{41109},{41119},{41132},{41143},{41157},{42,11},{42,42} ,{42,43},{42,92},{42,95},{42115},{42117},{42144},{42156},{42204},{43,7},{43.9} ,{43,43},{43,45},{43,56},{43122},{43145},{43192},{43194},{43201},{44,10},{44,44} ,{44,75},{44,83},{44,95},{44110},{44135},{44146},{44157},{44180},{45,45},{45,63} ,{45,79},{45,81},{45,97},{45127},{45139},{45147},{45148},{45195},{46,34},{46,46} ,{46,61},{46,66},{46,77},{46105},{46144},{46148},{46197},{46201},{47,14},{47,20} ,{47,46},{47,47},{47,83},{47124},{47128},{47132},{47149},{47159},{48,8},{48,13} ,{48,26},{48,48},{48,62},{48149},{48,150},{48174},{48193},{48195 },{49,15},{49,21},{49,25},{49,49},{49,51},{49145},{49149},{49,151},{49177},{49188 },{50,8},{50,49},{50,50},{50,54},{50,89},{50105},{50126},{50152},{50164},{50165 },{51,43},{51,51},{51,66},{51,68},{51,91},{51131},{51,133},{51153},{51187},{51189 },{52.1},{52,39},{52,45},{52,52},{52,54},{52110},{52140},{52150},{52154},{52163 },{53,8},{53,53},{53,60},{53,64},{53,90},{53138},{53155},{53157},{53194},{53204 },{54,12},{54,28},{54,54},{54,60},{54,82},{54112},{54139},{54151},{54156},{54183 },{55,3},{55,17},{55,37},{55,55},{55,99},{55112},{55148},{55157},{55172},{55189 },{56,20},{56,31},{56,56},{56,80},{56,91},{56152},{56156},{56158},{56162},{56180 },{57,28},{57,57},{57,66},{57,81},{57,89},{57134},{57137},{57159},{57172},{57196 },{58,5},{58,58},{58,70},{58,78},{58,91},{58118},{58149},{58154},{58160},{58201 },{59,18},{59,24},{59,59},{59,88},{59,96},{59150},{59,152},{59161},{59179},{59183 },{60,21},{60,38},{60,55},{60,59},{60,60},{60162},{60,176},{60187},{ 60190},{60197},{61,61},{61,69},{61,74},{61,93},{61101},{61111},{61128},{61163},{61193} {61196},{62,6},{62,7},{62,35},{62,62},{62,96},{62103},{62113},{62129},{62164} ,{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63121},{63134},{63165},{63175} {63188},{64.4},{64,26},{64,64},{64,79},{64,84},{64119},{64134},{64136},{64166} {64168},{65,12},{65,13},{65,52},{65,57},{65,65},{65106},{65138},{65142},{65167} {65176},{66,24},{66,30},{66,52},{66,66},{66102},{66112},{66117},{66122},{66135},{ 66168},{67,6},{67,57},{67,67},{67,85},{67,97},{67140},{67169},{67182},{67184},{ 67186},{68,6},{68,58},{68,68},{68,71},{68,90},{68134},{68143},{68145},{68152},{ 68170},{69,54},{69,57},{69,59},{69,69},{69,77},{69103},{69104},{69114},{69136},{ 69171},{70,19},{70,24},{70,56},{70,70},{70100},{70105},{70114},{70128},{70129},{70172} ,{71,14},{71,52},{71,63},{71,70},{71,71},{71120},{71169},{71173},{71178},{71196} ,{72,11},{72,25},{72,39},{72,66},{72,72},{72120},{ 72130},{72132},{72174},{72199},{73,48},{73,49},{73,64},{73,73},{73,98},{73111},{ 73175},{73179},{73201},{73202},{74,9},{74,15},{74,58},{74,74},{74,84},{74107},{ 74120},{74135},{74164},{74176},{75,28},{75,41},{75,70},{75,75},{75,96},{75133},{ 75155},{75166},{75177},{75202},{76,26},{76,45},{76,65},{76,76},{76,94},{76144},{ 76158},{76172},{76178},{76203},{77,10},{77,13},{77,77},{77,84},{77,87},{77127},{ 77151},{77163},{77179},{77191},{78,49},{78,55},{78,65},{78,78},{78,90},{78122},{ 78130},{78139},{78180},{78182},{79,33},{79,43},{79,67},{79,79},{79,99},{79123},{ 79141},{79181},{79188},{79202},{80,18},{80,19},{80,35},{80,46},{80,80},{80153},{ 80167},{80182},{80188},{80193},{81,9},{81,16},{81,36},{81,55},{81,81},{81143},{ 81160},{81183},{81186},{81191},{82,10},{82,11},{82,79},{82,82},{82,96},{82108},{ 82111},{82126},{82172},{82184},{83,12},{83,36},{83,69},{83,83},{83,87},{83148},{ 83174},{83185},{83202},{83204},{84,45},{84,47},{84,48},{84,75}, {84,84},{84108},{84123},{84142},{84153},{84186},{85,9},{85,46},{85,53},{85,54}, {85,85},{85115},{85121},{85129},{85177},{85187},{86,22},{86,64},{86,83},{86,86}, {86,91},{86107},{86116},{86171},{86188},{86199},{87,8},{87,22},{87,61},{87,81}, {87,87},{87104},{87,120},{87182},{87189},{87198},{88,32},{88,33},{88,39},{88,51}, {88,88},{88129},{88143},{88171},{88180},{88190},{89,3},{89,21},{89,52},{89,89}, {89100},{89103},{89109},{89115},{89125},{89191},{90,20},{90,40},{90,44},{90,61},{90 ,90},{90118},{90137},{90153},{90184},{90192},{91.6},{91,23},{91,29},{91,84},{91 ,91},{91144},{91155},{9117​​3},{91185},{91193},{92,14},{92,49},{92,72},{92,92},{92102 },{92147},{92171},{92185},{92186},{92194},{93,5},{93,21},{93,29},{93,65},{93,93 },{93105},{93110},{93119},{93,184},{93195},{94,39},{94,80},{94,82},{94,94},{94,98 },{94107},{94113},{94131},{94166},{94196},{95,30},{95,47},{95,50},{95,63},{95,95 },{95104},{95118},{95161},{95163},{95197},{96,25},{96,34} ,{96,56},{96,68},{96,96},{96,116},{96181},{96186},{96196},{96198},{97,36},{97,38} ,{97,46},{97,89},{97,97},{97113},{97136},{97150},{97157},{97199},{98.3},{98,12} ,{98,18},{98,30},{98,98},{98136},{98170},{98187},{98198},{98,200},{99,53},{99,62} ,{99,74},{99,97},{99,99},{99104},{99119},{99156},{99185},{99201},{100,16},{100,68} {100,82},{100,95},{100,100},{100106},{100124},{100158},{100195},{100202},{101,19},{101,36},{ 101,41},{101,72},{101101},{101112},{101124},{101162},{101164},{101203},{102,3},{102,38},{102, 51},{102,86},{102,102},{102128},{102173},{102175},{102184},{102204}};


printf(encoder \\\
);

for(L = 0; L <204; L ++)
{
printf(%d,x [L]);
}
// printf(\ n Matrix \ n);
/ * for(M = 0; M< ROWS_P; M ++)
{
循环数组的第二维,在本例中为4
for(O = 0; O< ; COL_P; O ++)
{
printf(%d \ t,h [M] [O]);
}
printf(\ n); (br_count = 0; snr_count< snr_range; snr_count ++)
{
// cout<<db = SNR中的解码器运行...
} * /

<<< snr_db [snr_count]<< endl;
snr = pow(10,(snr_db [snr_count] / 10));

printf(\ n ModulationSchemeValue \ n);

printf(\ n%d%d%f%f%f%d \ n,modulationScheme,noOfSymbols,var,d,rate,snr);
// ModulationSchemeValues(modulationScheme,noOfSymbols,var,d,rate,snr); //根据调制方案确定各种值

var = 1 /(2 * rate * snr);
noOfSymbols = COL;
d = 1;
printf(\ n%d%d%f%f%f%d \ n,modulationScheme,noOfSymbols,var,d,rate,snr);

printf(\ n);
//从SNR计算噪声方差
BER [snr_count] = 0; //初始化BER
// normal_distribution< double> dist(0.0,1);
N = 0;
errorsAccumulated = 0;

printf(\\\
InitializeChannelLLR \ n);
while(errorsAccumulated< = maxErrors&& N< = maxTransmissions)
{
N ++;

for(int i = 0; i< noOfSymbols; i ++)/
{

x [M] = d;
noise [M] =(x [M])+ 0.8;
L_ch [M] = 2 * noise [M] / var;
M ++;

}


for(int M = 0; M< ROWS_P; M ++)
{

R = h [M] [1] -1;
LLR [M] = L_ch [R];

}
printf(%d,LLR [M]);


for(looping = 0; looping< decoderIterations; looping ++)
{

z = SPADecoder(LLR,h,LLR_ret,L_ch,L_dec, Y);

}

if(z == 1)//如果正确解码则该代码字的BER为零

{

BER [snr_count] = BER [snr_count] +0;

}
else //如果没有正确解码,可以计算BER
{
error_bits = 0;
for(i = 0; i< COL; i ++)
{
if(y [i]!= 0)
{
error_bits ++;

}
}
errorsAccumulated + = error_bits;
error = error_bits /(double)COL;
BER [snr_count] = BER [snr_count] +错误;
}
if(N%300 == 0)
printf(iteration =%d \t errors accumulation =%d \ n,N,errorsAccumulated);
}

BER [snr_count] = BER [snr_count] /(double)N; //在所有解码迭代中平均BER。
BER [snr_count] = BER [snr_count] /(double)N; //在所有解码迭代中平均BER。
printf(snr =%lf \ tBER [%d] =%lf \ n,snr_db [snr_count],snr_count,BER [snr_count]);

}

返回0;
}





我的尝试:



我已经尝试了很多次,

SPADecoder函数

没有返回任何值。

解决方案

< blockquote>调试器是你的朋友。

如果你的print语句没有被执行,那么代码执行永远不会到达它们,这是显而易见的。调试器是能够找出原因的最强大的工具。


编译并不意味着你的代码是正确的! :笑:

将开发过程想象成编写电子邮件:成功编译意味着您使用正确的语言编写电子邮件 - 例如英语而不是德语 - 而不是电子邮件包含您的邮件想发送。



所以现在你进入第二阶段的发展(实际上它是第四或第五阶段,但你将在之后的阶段进入):测试和调试。



首先查看它的作用,以及它与你想要的有何不同。这很重要,因为它可以为您提供有关其原因的信息。例如,如果程序旨在让用户输入一个数字并将其翻倍并打印答案,那么如果输入/输出是这样的:

输入预期输出实际输出
1 2 1
2 4 4
3 6 9
4 8 16

然后很明显问题出在将它加倍的位 - 它不会将自身加到自身上,或者将它乘以2,它会将它自身相乘并返回输入的平方。

所以,你可以查看代码和很明显,它在某处:

  int   Double  int   value 
{
return value * ;
}



一旦你知道可能出现的问题,就开始使用teh调试器找出原因。在你的行上设一个断点:

  for (looping =  0 ;循环< decoderIterations;循环++)



并运行你的应用程序。在执行代码之前,请考虑代码中的每一行应该做什么,并将其与使用Step over按钮依次执行每一行时实际执行的操作进行比较。它符合您的期望吗?如果是这样,请转到下一行。

如果没有,为什么不呢?它有何不同?



这是一项非常值得开发的技能,因为它可以帮助你在现实世界和发展中。和所有技能一样,它只能通过使用来改善!



是的,我可能会告诉你问题是什么 - 但这并不难做到,你会在同一时间学到一些非常值得的东西!


"SPADecoder" Function not returning any value. I have added Print statement inside the

"SPADecoder" Function

its not Printing any statements and values.

I am unable to find out the error in

"SPADecoder" Function

. Please point out me. Thanks

#include <stdio.h>
#include <math.h>

#define COL 204
#define COL_P 2
#define ROWS_P 1020

int codecheck(int (*h)[2],int x[])
{
    int i,j,m,f; //flags
	int sum = 0;
	int y[COL];
    for (i=0;i<COL;i++)
	y[i]=0;
	m=1;
	f=-1;
	for(i=0;i<ROWS_P;i++)
	{
		for(j=0;j<COL_P;j++)
		{
			if(h[j][0]==m)
			{
				y[m]=y[m] + x[h[j][1]-1];
					f++;
			}
		}
		y[m]=y[m]%2;
		m=m+1;
		i=f+1;
	}

	for (i = 0; i < COL; ++i)
		{
			sum =sum+ y[i];
		}
	if (sum == 0)
		{
			return 1;
		}
	else
		{
			return -1;
		}

}

int codesum (int y[])
{
    int sum=0;
    for(int i=0;i<COL;i++)
        sum+=y[i];
    //cout<< "sum="<< sum<<endl;
    if(sum>0)
        return 0;
    else
        return 1;
}

/*void ModulationSchemeValues (int modulationScheme, int noOfSymbols, double var, float d, float rate, double snr)
{
           switch (modulationScheme)
            {
                case 0:
                    //cout<<"case 0"<<endl;
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
                case 1:
                    //cout<<"case 1"<<endl;
                    var=1/(4*rate*snr);
                    noOfSymbols = COL/2;
                    d=1/sqrt(2);
                    break;
                case 2:
                    //cout<<"case 2"<<endl;
                    var=1/(8*rate*snr);
                    noOfSymbols = COL/4;
                    d=1/sqrt(10);
                default:
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
            }
    printf("%d %d %f %f %f %d",modulationScheme,noOfSymbols, var, d,rate, snr);
}

void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, int x[], float noise[], double L_ch[], float d, int (*h)[2], double LLR[])
{

    int j=0;   // temporary flags
   int k=0,t;
    for(int i=0;i<noOfSymbols;i++)							// using randnoise function introducing noise to all zero codeword
    {

            x[j]=d;
            noise[j]=(x[j])+0.8;
            L_ch[j]= 2*noise[j]/var;
            j++;


    }


    for(int j=0;j<ROWS_P;j++)
    {
        //cout<<"enter loop"<<endl;
        //cout<< "j="<<j<<endl;  //<<j<<"\t";
        t=h[j][1]-1;
        LLR[j]=L_ch[t];
    }
    //cout<<"L_ch initialize done \n";

}*/

int SPADecoder(double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[])
{

    double temp;
    int z;
    int i,j,k;
    for(i=0;i<ROWS_P;i++)
    {
        temp=1;
        for(j=0;j<ROWS_P;j++)
        {
            if(j!=i && h[j][0]==h[i][0])
            {
                temp=temp * tanhf(LLR[j]/2);
            }
        }
        LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR

        if(LLR_ret[i] > 40)
        {
            LLR_ret[i]=40;
        }
        else if(LLR_ret[i]<-40)
        {
            LLR_ret[i]=-40;
        }

    }

    for(i=0;i<COL;i++)							/
    {
        L_dec[i]=L_ch[i];
    }


    for(i=1;i<COL+1;i++)						
    {
        for(j=0;j<ROWS_P;j++)
        {
            if(h[j][1]==i)
            {
                L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
            }

        }

        if(L_dec[i-1]<=0)						
        {
            y[i-1]=1;
        }
        else
        {
            y[i-1]=0;
        }

    }


    //z = codesum(y,col);
    z=codecheck(h,y); // checking whether the decoded codeword is all zero or not

    if(z==1)								// if decoded perfectly exit the deoding loop
    {
        return z;
    }
   
    for(i=0;i<ROWS_P;i++)
    {
        temp=0;
        for(j=0;j<ROWS_P;j++)
        {
            if(j!=i && h[j][1]==h[i][1])
            {
                temp=temp + LLR_ret[j];
                k=h[i][1];

            }
        }
        LLR[i] = temp+L_ch[k-1];
    }
return z;
}

int main()
{

	// flags and counters
    int z,i,j,N,k,ber_count,looping,t,sum;
    float d=1;
	float rate=0.5;

	int maxTransmissions=20,decoderIterations=10,maxErrors=50,errorsAccumulated=0;
	int y[COL];	/
    int L,O,R,M=0;

	double var=0,snr;
	double temp; 								//temp variable

    float noise[COL];
    double L_ch[COL],L_dec[COL];
	double LLR[ROWS_P],LLR_ret[ROWS_P];
	double BER[11];
    float snr_db[]={0,1,2,3,4};
    int snr_range=5,snr_count;
	int x[]={1,1,1,0,0,1,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,1,1,1,0,0,0,0,1,0,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,1,0,1,0,1,1,0,1,1,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,1,0,1,1,1};
    int  ret,row=0;
	double error_bits,error;
    int modulationScheme = 0,noOfSymbols=204;
    int h[ROWS_P][COL_P]={{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106},{100,124},{100,158},{100,195},{100,202},{101,19},{101,36},{101,41},{101,72},{101,101},{101,112},{101,124},{101,162},{101,164},{101,203},{102,3},{102,38},{102,51},{102,86},{102,102},{102,128},{102,173},{102,175},{102,184},{102,204}};


	printf("encoder \n");

	for (L = 0; L < 204; L++)
    {
      printf("%d",x[L]);
    }
    //printf(" \n Matrix \n");
/*for(M=0; M<ROWS_P; M++)
{
   loop for second dimension of array which is 4 in this example
     for(O=0;O<COL_P;O++)
     {
         printf("%d \t",h[M][O]);
     }
     printf("\n");
}*/

    for(snr_count=0;snr_count<snr_range;snr_count++)
	{
      //  cout<<"Decoder run for SNR in db=" <<snr_db[snr_count]<<endl;
				snr=pow(10,(snr_db[snr_count]/10));

                 printf(" \n ModulationSchemeValue \n");

                 printf(" \n%d %d %f %f %f %d\n",modulationScheme,noOfSymbols, var, d,rate, snr);
				//ModulationSchemeValues (modulationScheme, noOfSymbols, var, d, rate, snr);  // determining various values based on modulation scheme

                var=1/(2*rate*snr);
                noOfSymbols = COL;
                d=1;
                printf(" \n%d %d %f %f %f %d\n",modulationScheme,noOfSymbols, var, d,rate, snr);

                printf("\n");
        					// calulating noise variance from SNR
				BER[snr_count]=0;									// initializing BER
             //   normal_distribution<double> dist(0.0, 1);
                N=0;
                errorsAccumulated=0;

                printf(" \n InitializeChannelLLR\n");
				while(errorsAccumulated<=maxErrors && N<=maxTransmissions)
				{
                        N++;

                        for(int i=0;i<noOfSymbols;i++)							/
                           {

                                x[M]=d;
                                noise[M]=(x[M])+0.8;
                                L_ch[M]= 2*noise[M]/var;
                                M++;

                            }


                       for(int M=0;M<ROWS_P;M++)
                           {

                               R=h[M][1]-1;
                               LLR[M]=L_ch[R];

                          }
                               printf(" %d",LLR[M]);
                       

                           for(looping=0;looping<decoderIterations;looping++)
						   {

                              z = SPADecoder(LLR, h, LLR_ret, L_ch, L_dec, y);

						   }

                          if(z==1)											// if decoded correctly BER for that codeword is zero

                          {

                             BER[snr_count]=BER[snr_count]+0;

                          }
                         else 												// if not decoded properly calulating the BER
                          {
                            error_bits=0;
                            for(i=0;i<COL;i++)
									{
										if(y[i]!=0)
										{
											error_bits++;

										}
									}
                            errorsAccumulated+=error_bits;
                            error=error_bits/(double)COL;
                            BER[snr_count]=BER[snr_count]+error;
                          }
                       if(N%300==0)
                           printf("iteration=%d \t errors accumulated=%d \n",N,errorsAccumulated);
                }

                    BER[snr_count]=BER[snr_count]/(double)N; 					// averaging BER over all decoding iterations.
                    BER[snr_count]=BER[snr_count]/(double)N; 					// averaging BER over all decoding iterations.
					printf("snr=%lf\tBER[%d]=%lf \n",snr_db[snr_count],snr_count,BER[snr_count]);

    }

    return 0;
}



What I have tried:

I have tried lot of times,

"SPADecoder" Function 

not returning any values.

解决方案

The debugger is your friend.
If your print statements are not executed, then code execution never reaches them, that's obvious. The debugger is the most powerful tool able to find out why.


Compiling does not mean your code is right! :laugh:
Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.

So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.

Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:

Input   Expected output    Actual output
  1            2                 1
  2            4                 4
  3            6                 9
  4            8                16

Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:

int Double(int value)
   {
   return value * value;
   }


Once you have an idea what might be going wrong, start using teh debugger to find out why. Put a breakpoint on your line:

for(looping=0;looping<decoderIterations;looping++)


and run your app. Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?

This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!

Yes, I could probably tell you what "the problem" is - but it's not difficult to do this yourself, and you will learn something really worthwhile at the same time!


这篇关于C中函数调用出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆