📄 other_functions.c
字号:
#include "turbo_code_Log_MAP.h"
#include "other_functions.h"
/*---------------------------------------------------------------
FUNCTION:
void gen_source(int *data, int length)
DESCRIPTION:
This function generate the source bits for simulation.
PARAMETERS:
INPUT:
length - Length of needed data.
OUTPUT:
data - Contains pointer to source data sequence.
RETURN VALUE:
None
---------------------------------------------------------------*/
void gen_source(int *data, int length)
{
double temp;
int i;
for (i=0; i<length; i++)
{
//temp = (double)rand()/RAND_MAX;
temp = random_turbo();
if (temp <= 0.5)
{
*(data+i) = 0;
}
else
{
*(data+i) = 1;
}
}
}
/*---------------------------------------------------------------
FUNCTION:
void AWGN(int *send, double *r, double sigma, int totallength)
DESCRIPTION:
This function simulate a AWGN channel.
PARAMETERS:
INPUT:
send - Input bit sequence need to add noise.
sigma - Standard deviation of AWGN noise
totallength - Length of "send".
OUTPUT:
r - Contains pointer to the data sequence added with gaussian white noise.
RETURN VALUE:
None
---------------------------------------------------------------*/
void AWGN(float *send, float *r, float sigma, int totallength)
{
int i;
double *noise = (double *)malloc(sizeof(double)*totallength);
double seed = 3.0 - (double)((rand() & RAND_MAX)/(double)RAND_MAX)/10e6;
mgrns(0,sigma,seed,totallength,noise);
for(i=0; i<totallength; i++)
{
*(r+i) = (float)( *(send+i) + *(noise+i) );
}
free(noise);
}
/*
* 函数介绍:产生长度为n的高斯随机序列
* 输入参数:mean:均值
sigma:标准差
seed:一个随机种子
* 输出参数:a:长度为n的高斯随机序列
* 返回值: 返回一个trellis结构
*/
void mgrns(double mean,double sigma,double seed,int n,double *a)
{ int i,k,m;
double s,w,v,t;
s=65536.0; w=2053.0; v=13849.0;
for (k=0; k<=n-1; k++)
{
t=0.0;
for (i=1; i<=12; i++)
{
seed=seed*w+v; m=(int)(seed/s);
seed=seed-m*s; t=t+(seed)/s;
}/*按照中心极限定理产生服从高斯分布的随机数*/
*(a+k)=mean+sigma*(t-6.0);
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -