资源简介
采用最小广义距离译码算法,对进入AWGN信道的(7,4)循环码组进行纠错检错,当信噪比(10db)很大时译码成功,信噪比很小时(如0.1db)译码失败
代码片段和文件信息
#include
#include
#include
#define N 7
#define K 4
#define D 3
double test_date[N];
typedef struct cycle_code{
int c[N];
int m[K];
float dB;
double infor[N];
int c_quan[N];
}cycle_code;
void coding(cycle_code *codec);
void AWGN(cycle_code *codec);
void decode(cycle_code *codec);
void quantize(cycle_code *codec);
void coding(cycle_code *codec)
{
int reg[3] = { 0 }; //定义3位移存器
int i temp count = 0;
for (i = 0; i {
temp = codec->m[i] ^ reg[2];
reg[2] = reg[1];
reg[1] = temp^reg[0];
reg[0] = temp;
codec->c[count++] = codec->m[i];
}
for (i = 2; i >= 0; i--)
codec->c[count++] = reg[i];
printf(“经(74)循环编码后的码组为:“);
for (i = 0; i printf(“%d “ codec->c[i]);
}
void AWGN(cycle_code *codec)
{
double gngauss(double mean double sigma);
int i;
printf(“\n请输入信噪比:“);
scanf(“%f“ &codec->dB);
printf(“经过%.1fdB的信道后,信息输出为:“ codec->dB);
for (i = 0; i {
codec->infor[i] = codec->c[i] * 2 - 1 + gngauss(0 1 / sqrt(pow(10 0.1*codec->dB)));
codec->infor[i] = log(exp(pow((codec->infor[i] + 1) 2) / (2 * 1 / pow(10 0.1*codec->dB)))) - log(exp(pow((codec->infor[i] - 1) 2) / (2 * 1 / pow(10 0.1*codec->dB))));
printf(“%f:“ codec->infor[i]);
if (codec->infor[i] >= fabs(codec->dB))
codec->infor[i] = fabs(codec->dB);
else if (codec->infor[i] <= -fabs(codec->dB))
codec->infor[i] = -fabs(codec->dB);
else
codec->infor[i] /= fabs(codec->dB);
printf(“%f “ codec->infor[i]);
}
}
double gngauss(double mean double sigma)
{
double v1 v2 w x;
do
{
v1 = 2.0*rand() / RAND_MAX - 1.0;
v2 = 2.0*rand() / RAND_MAX - 1.0;
w = v1*v1 + v2*v2;
} while (w >= 1.0 || w == 0);
if (!w)
{
x = 0;
}
else
{
x = v1*sqrt(-2.0*log(w) / w);
}
return (mean + sigma*x);
}
void quantize(cycle_code *codec)
{
int i;
printf(“\n量化后输出序列:“);
for (i = 0; i < N; i++)
{
if (codec->infor[i] > 0)
codec->c_quan[i] = 1;
else if (codec->infor[i] < 0)
{
codec->c_quan[i] = -1;
}
else
codec->c_quan[i] = 0;
printf(“%d “ codec->c_quan[i]);
}
}
void decode
评论
共有 条评论