awgn
/* Modnumlib Scicos interfacing function
* Copyright (C) 2009-2011 Alan Layec
*
* This library 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.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU 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.
*/
/* awgn Scicos Additive White Gaussian Noise channel block
* Type 4 simulation function ver 1.0 - scilab-3.0
* 23 décembre 2004 - IRCOM GROUP - Author : A.Layec
*/
/* REVISION HISTORY :
* $Log$
*/
#include <scicos/scicos_block.h>
#include "modnum_lib.h"
/* Cette fonction de simulation calcule un vecteur aléatoire gaussien
* par la méthode "Muler Box" et l'ajoute au vecteur complexe d'entrée
*
* y1[i]=u1[i]+mean+sigma*sqrt(-log(rand1))*cos(2*%pi*rand2)
* y2[i]=u2[i]+mean+sigma*sqrt(-log(rand1))*sin(2*%pi*rand2)
*
* où mean et sigma sont des paramètres et rand1 et rand2 sont
* des variables aléatoires uniformément réparties
*
* entrée régulière : u1[0..nu-1] vecteur des parties rélles des échantillons d'entrée
* u2[0..nu-1] vecteur des parties imaginaires des échantillons d'entrée
* sortie régulière : y1[0..ny-1] vecteur des parties rélles des échantillons de sortie
* y2[0..ny-1] vecteur de parties imaginaires des échantillons de sortie
* entrée évènementielle : Dates de déclenchement
* sortie évènementeille : néant
*
* paramètre entier : néant
* paramètre réel : rpar[0] : valeur du sigma
* rpar[1] : valeur de la moyenne
*/
/*prototype*/
void awgn(scicos_block *block,int flag)
{
/*déclaration des variables*/
double *u1,*u2;
double *z1,*z2;
double *y1,*y2;
int k;
int ny;
int my=1;
/*récupération de l'adresses des ports réguliers*/
u1=(double *)block->inptr[0];
u2=(double *)block->inptr[1];
y1=(double *)block->outptr[0];
y2=(double *)block->outptr[1];
/*récupère taille de sortie*/
ny=block->outsz[0];
if(flag==4) { /*flag 4*/
if ((*block->work=scicos_malloc(sizeof(double)*2*ny))== NULL) {
set_block_error(-16);
return;
}
z1=*block->work;
z2=&z1[ny];
/*Appel noiseiq_c*/
noiseiq_c(&ny,&my,&block->rpar[0],&block->rpar[1],&z1[0],&z2[0]);
}
/*Le flag 2 calcule le registre de sortie y*/
else if(flag==2) {
z1=*block->work;
z2=&z1[ny];
/*Appel noiseiq_c*/
noiseiq_c(&ny,&my,&block->rpar[0],&block->rpar[1],&z1[0],&z2[0]);
}
else if((flag==1)||(flag==6)) {
z1=*block->work;
z2=&z1[ny];
/*Appel complxa_c*/
cmplxadd_c(&ny,(k=1,&k),&u1[0],&u2[0],&z1[0],&z2[0],&y1[0],&y2[0]);
}
else if(flag==5) {
scicos_free(*block->work);
}
}