Capsim Block Documentation
This star adds white gaussian noise to the input complex data stream.
| Port | Type | Name | |
|---|---|---|---|
| 0 | complex | inp |
| Port | Type | Name | |
|---|---|---|---|
| 0 | complex | out |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | Noise power | float | power | 1.0 | |
| 1 | Seed for random number generator | int | seed | 333 |
| Num | Type | Name | Initial Value | Description |
|---|---|---|---|---|
| 0 | char | rand_state[256] | ||
| 1 | double | max | ||
| 2 | float | dev | sqrt(fabs(power)) |
int i,j,ok;
int numin;
int count = 0;
int trouble;
double s,t,u,v,k,w,x,sqrt(),log();
float y1,y2;
long random();
complex val;
|
|---|
if (power < 0.0) {
fprintf(stderr,"cxaddnoise: improper parameter\n");
return(2);
}
srandom(seed);
max = m;
|
|---|
if ((numin = AVAIL(0)) > 0) {
while(count < numin) {
/****************************************************************/
/* gauss */
/* code written by Prayson Pate */
/* This code generates two random variables that are normally */
/* distributed with mean 0 and variance 1 i.e N(0,1). */
/* The polar method is used to generate normally distributed */
/* samples from a sequence that is uniform on (-1,1). The */
/* resulting distribution is described exactly by N(0,1). */
/* This method is based on the inverse distribution function. */
/****************************************************************/
trouble = 0;
do {
if(++trouble > 100) {
fprintf(stderr,"cxaddnoise: problem with random number generator\n");
return(2);
}
/* get two random numbers in the interval (-1,1) */
s = random();
u = -1.0 + 2.0*(s/max);
t = random();
v = -1.0 + 2.0*(t/max);
w = u*u + v*v;
/* is point (u,v) in the unit circle? */
} while (w >= 1.0 || w == 0.0);
x = sqrt((-2.0 * log(w))/w);
/* find two independent values of y */
y1 = dev * u * x;
y2 = dev * v * x;
/****************** End of Gauss Code ****************************/
IT_IN(0);
if(IT_OUT(0)) {
fprintf(stderr,"cxaddnoise buffer 0 overflow\n");
return(99);
}
val=inp(0);
val.re += y1;
val.im += y2;
out(0)=val;
++count;
}
}
return(0);
|
|---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
Copyright (C) 1989-2002 XCAD Corporation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://capsimtmk.sourceforge.net
XCAD Corporation
Raleigh, North Carolina */
|
|---|
/********************************************************************** cxaddnoise.s ************************************************************************ This star adds white gaussian noise to the input data stream. Param. 1 (float) sets the power of the added noise and should be >= 0. Param. 2 (int) sets a seed for the random number generator. Random sequences can be unique and repeatable for each instance of this star. Modified: August 30, 2001 Sasan Ardalan, Complex Add Noise |
|---|