/* rnoise_c subroutine * Rayleigh noise generator * * Copyright (C) 2007-2009 Alan Layec * * This file is part of modnumlib. * * modnumlib is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * modnumlib 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with modnumlib; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ /* REVISION HISTORY : * $Log$ */ #include <math.h> #include <stdlib.h> /*pour RAND_MAX*/ #include "modnum_lib.h" /* rnoise_c routine de calcul d'échantillons bruités de Rayleigh * * Entrées : * n : dimension 1 de la matrice de sortie (scalaire) * m : dimension 2 de la matrice de sortie (scalaire) * sig : parametre (scalaire) * Sorties : * y : matrice de sortie * * dépendances * math.h */ void rnoise_c(int *n,int *m,double *sig,double *y) { /*déclaration des variables*/ int i,l; double rand_m,rand1; int ind_y; /*récupération de la valeur de RAND_MAX*/ rand_m=RAND_MAX; for(l=0;l<(*m);l++) { ind_y = (*n)*l; for(i=0;i<(*n);i++) { /*calcul rand1*/ rand1=rand()/rand_m; /*test rand1*/ while((rand1<=0)||(rand1>=1)) rand1=rand()/rand_m; /*Calcul sortie*/ y[ind_y+i]=sqrt(2*pow((*sig),2)*log(1/(1e-5+1-rand1))); } } return; }