📄 addnoise.cpp
字号:
/* BPSK BINARY SYMMETRIC CHANNEL SIMULATOR */
/* Copyright (c) 1999, Spectrum Applications, Derwood, MD, USA */
/* All rights reserved */
/* Version 2.0 Last Modified 1999.02.17 */
//#include <alloc.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define PI2 6.283185307179586476925286766559
#include "vdsim.h"
double SeEd=17.0;
double UniformRand(void)
// generate a uniformly distributed random number
{
// MINSTD算法:
double a;
SeEd=48271.0*SeEd;
a=SeEd/2147483647.0;
a=a-(floor(a));
SeEd=a*2147483647.0;
return (a);
}
double GaussNoise(double sigma)
// 产生均值为0, 标准差为Sigma的高斯噪声.
{ // Sigma -- standard deviation of Gaussian noise
return (sigma*sqrt(-log(UniformRand()))*sqrt(2.0)*sin(PI2*UniformRand()));
}
void addnoise(double es_ovr_n0, long channel_len, int *in_array, double *out_array) {
long t;
double mean, es, sn_ratio, sigma, signal;
/* given the desired Es/No (for BPSK, = Eb/No - 3 dB), calculate the
standard deviation of the additive white gaussian noise (AWGN). The
standard deviation of the AWGN will be used to generate Gaussian random
variables simulating the noise that is added to the signal. */
mean = 0;
es = 1;
sn_ratio = (double) pow(10, ( es_ovr_n0 / 10) );
sigma = (double) sqrt (es / ( 2 * sn_ratio ) );
/* now transform the data from 0/1 to +1/-1 and add noise */
for (t = 0; t < channel_len; t++) {
/*if the binary data value is 1, the channel symbol is -1; if the
binary data value is 0, the channel symbol is +1. */
signal = (double) (1 - 2 * *( in_array + t ));
/* now generate the gaussian noise point, add it to the channel symbol,
and output the noisy channel symbol */
*( out_array + t ) = (double) (signal + GaussNoise(sigma));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -