Professional Documents
Culture Documents
#include <alloc.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "vdsim.h"
long t;
float 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 = (float) pow(10, ( es_ovr_n0 / 10) );
sigma = (float) 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 = 1 - 2 * *( in_array + t );
/* now generate the gaussian noise point, add it to the channel symbol,
and output the noisy channel symbol */
home.netcom.com/~chip.f/viterbi/ccode/addnoise.html 1/2
09/01/2014 addnoise
double u, r; /* uniform and Rayleigh random variables */
home.netcom.com/~chip.f/viterbi/ccode/addnoise.html 2/2