?? other_functions.c
字號(hào):
#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);
}
/*
* 函數(shù)介紹:產(chǎn)生長(zhǎng)度為n的高斯隨機(jī)序列
* 輸入?yún)?shù):mean:均值
sigma:標(biāo)準(zhǔn)差
seed:一個(gè)隨機(jī)種子
* 輸出參數(shù):a:長(zhǎng)度為n的高斯隨機(jī)序列
* 返回值: 返回一個(gè)trellis結(jié)構(gòu)
*/
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;
}/*按照中心極限定理產(chǎn)生服從高斯分布的隨機(jī)數(shù)*/
*(a+k)=mean+sigma*(t-6.0);
}
return;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -