/* -*- Mode: Text -*- */ /********************************************************************\ * File: noise.hs * * Date: 04/25/1997 * * Author: Cem Unsal * * Robotics Institute, Carnegie-Mellon University * * unsal@ri.cmu.edu * * * * Description: * * Gaussian random number generator * * From Nummerical Recipes in C by Press et al. * * * * There are two independent Gasussian signals (y1 and y2) * * with: * * mean = 0, variance = 1.0 * * * * The SHIFT (ver 2.10) function random() acts similar to Matlab's * * 'rand' function on a Sun4m running SunOS 4.1.4 * * * * Natural log function is defined as an external C function. The * * function 'ln' described in the Shift manual is not implemented. * * * * External C functions: natlog * * * * This file is distributed under the conditions described in the * * file 'CONDITIONS' which should accompany this file. * \********************************************************************/ #ifndef SAHS_NOISE_HS #define SAHS_NOISE_HS /* External functions */ function natlog(number x) -> number; type Gaussian { state continuous number x1, x2; state number PI := 3.1415927; output continuous number sg1, sg2; // Two independent signals discrete generate; flow default { x1 = random(); x2 = random(); sg1 = sqrt(-2*natlog(x1)) * cos(2*PI*x2); sg2 = sqrt(-2*natlog(x1)) * sin(2*PI*x2); }; } #endif // SAHS_NOISE_HS