[228] | 1 | #include <stdlib.h>
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 | #include <math.h>
|
---|
| 4 |
|
---|
[517] | 5 | #ifdef __MWERKS__
|
---|
[682] | 6 | #include "unixmac.h"
|
---|
[517] | 7 | #endif
|
---|
| 8 |
|
---|
[1783] | 9 |
|
---|
[228] | 10 | #include "fmath.h"
|
---|
| 11 |
|
---|
| 12 | #include "bruit.h"
|
---|
| 13 | #include "nbrandom.h"
|
---|
| 14 | // #include "rancern.h"
|
---|
[313] | 15 | // #include "hbook.h"
|
---|
[1783] | 16 | #ifdef OS_MACOSX
|
---|
| 17 | #include <limits.h>
|
---|
| 18 | #endif
|
---|
[228] | 19 |
|
---|
| 20 | // Le code des classes NoiseGenerator RWalkNoise
|
---|
| 21 |
|
---|
[568] | 22 | //++
|
---|
| 23 | // Class NoiseGenerator
|
---|
| 24 | //
|
---|
| 25 | // include bruit.h math.h fmath.h nbrandom.h
|
---|
| 26 | //
|
---|
| 27 | //--
|
---|
| 28 | //++
|
---|
| 29 | //
|
---|
| 30 | // Links Childs
|
---|
| 31 | //
|
---|
| 32 | // RWalkNoise OOFNoise EXPNoise MemNoise SumNoise
|
---|
| 33 | //
|
---|
| 34 | //--
|
---|
| 35 | //++
|
---|
| 36 | // Titre Constructors
|
---|
| 37 | //--
|
---|
[228] | 38 |
|
---|
| 39 | /* --Methode-- */
|
---|
[568] | 40 | //++
|
---|
[228] | 41 | NoiseGenerator::NoiseGenerator(float sigma)
|
---|
[568] | 42 | //
|
---|
| 43 | //--
|
---|
[228] | 44 | {
|
---|
| 45 | if (sigma < 0.) sigma = 1.;
|
---|
| 46 | mNCoups = 0;
|
---|
| 47 | mSigma = sigma;
|
---|
| 48 | //printf("-- NoiseGenerator::NoiseGenerator(%g) (Constructeur) ---\n", sigma);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[568] | 51 | //++
|
---|
| 52 | // Titre Destructor
|
---|
| 53 | //--
|
---|
[228] | 54 | /* --Methode-- */
|
---|
[568] | 55 | //++
|
---|
[228] | 56 | NoiseGenerator::~NoiseGenerator()
|
---|
[568] | 57 | //
|
---|
| 58 | //--
|
---|
[228] | 59 | {
|
---|
| 60 | //printf("-- NoiseGenerator::~NoiseGenerator() (Destructeur) --- \n");
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[568] | 63 |
|
---|
| 64 | //++
|
---|
| 65 | //
|
---|
| 66 | // inline unsigned long int NoiseGenerator::NCoups()
|
---|
| 67 | //--
|
---|
| 68 | //++
|
---|
| 69 | // Titre Public Methods
|
---|
| 70 | //--
|
---|
| 71 |
|
---|
[228] | 72 | /* --Methode-- */
|
---|
[568] | 73 | //++
|
---|
[228] | 74 | float NoiseGenerator::Noise()
|
---|
[568] | 75 | //
|
---|
| 76 | //--
|
---|
[228] | 77 | {
|
---|
| 78 | mNCoups++;
|
---|
| 79 | return(NorRand()*mSigma);
|
---|
| 80 | }
|
---|
[568] | 81 | //++
|
---|
| 82 | // Class RWalkNoise
|
---|
| 83 | //
|
---|
| 84 | // include bruit.h math.h fmath.h nbrandom.h
|
---|
| 85 | //
|
---|
| 86 | //--
|
---|
| 87 | //++
|
---|
| 88 | //
|
---|
| 89 | // Links Parents
|
---|
| 90 | //
|
---|
| 91 | // NoiseGenerator
|
---|
| 92 | //
|
---|
| 93 | //--
|
---|
| 94 | //++
|
---|
| 95 | // Titre Constructor
|
---|
| 96 | //--
|
---|
[228] | 97 |
|
---|
| 98 | /* --Methode-- */
|
---|
[568] | 99 | //++
|
---|
[228] | 100 | RWalkNoise::RWalkNoise(float sigma)
|
---|
| 101 | : NoiseGenerator(sigma)
|
---|
[568] | 102 | //
|
---|
| 103 | //--
|
---|
[228] | 104 | {
|
---|
| 105 | mState = 0.;
|
---|
| 106 | //printf("-- RWalkNoise::RWalkNoise(%g) (Constructeur) ---\n", sigma);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
[568] | 110 | //++
|
---|
| 111 | // Titre Destructor
|
---|
| 112 | //--
|
---|
[228] | 113 | /* --Methode-- */
|
---|
[568] | 114 | //++
|
---|
[228] | 115 | RWalkNoise::~RWalkNoise()
|
---|
[568] | 116 | //
|
---|
| 117 | //--
|
---|
[228] | 118 | {
|
---|
| 119 | //printf("-- RWalkNoise::~RWalkNoise (Destructeur) ---\n");
|
---|
| 120 |
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[568] | 123 | //++
|
---|
| 124 | // Titre Public Methods
|
---|
| 125 | //--
|
---|
[228] | 126 | /* --Methode-- */
|
---|
[568] | 127 | //++
|
---|
[228] | 128 | float RWalkNoise::Noise()
|
---|
[568] | 129 | //
|
---|
| 130 | //--
|
---|
[228] | 131 | {
|
---|
| 132 | mState += NoiseGenerator::Noise();
|
---|
| 133 | return(mState);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[568] | 136 | //++
|
---|
| 137 | // Class OOFNoise
|
---|
| 138 | //
|
---|
| 139 | // include bruit.h math.h fmath.h nbrandom.h
|
---|
| 140 | //
|
---|
| 141 | //--
|
---|
| 142 | //++
|
---|
| 143 | //
|
---|
| 144 | // Links Parents
|
---|
| 145 | //
|
---|
| 146 | // NoiseGenerator
|
---|
| 147 | //
|
---|
| 148 | //--
|
---|
| 149 | //++
|
---|
| 150 | // Titre Constructor
|
---|
| 151 | //--
|
---|
[228] | 152 |
|
---|
| 153 | /* --Methode-- */
|
---|
[568] | 154 | //++
|
---|
[228] | 155 | OOFNoise::OOFNoise(float sigma, int typacf, int mem, float tau)
|
---|
| 156 | : NoiseGenerator(sigma)
|
---|
[568] | 157 | //
|
---|
| 158 | //--
|
---|
[228] | 159 | {
|
---|
| 160 | if (typacf != ACF_Exp) typacf = ACF_Exp;
|
---|
| 161 | // Fonction d'autocorrelation donnant un bruit en 1/f
|
---|
| 162 | //
|
---|
| 163 | mTypACF = typacf;
|
---|
| 164 | if (mem < 1) mem = 1;
|
---|
| 165 | mMemL = mem;
|
---|
| 166 | if (tau < 1.e-6) tau = 1.e-6;
|
---|
| 167 | mTau = tau;
|
---|
| 168 | mState = new double[mem];
|
---|
| 169 | mDyn = new double[mem];
|
---|
| 170 | int i;
|
---|
| 171 | mDyn[0]=1.;
|
---|
| 172 | mState[0]=0.;
|
---|
| 173 | for(i=1; i<mem; i++) {
|
---|
| 174 | mState[i] = 0.; mDyn[i] = 1./sqrt((double)i);
|
---|
| 175 | }
|
---|
| 176 | //printf("-- OOFNoise::OOFNoise(%g,%d,%d,%g) (Constructeur) ---\n",
|
---|
| 177 | // sigma, typacf, mem, tau);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 |
|
---|
[568] | 181 | //++
|
---|
| 182 | // Titre Destructor
|
---|
| 183 | //--
|
---|
[228] | 184 | /* --Methode-- */
|
---|
[568] | 185 | //++
|
---|
[228] | 186 | OOFNoise::~OOFNoise()
|
---|
[568] | 187 | //
|
---|
| 188 | //--
|
---|
[228] | 189 | {
|
---|
| 190 | delete[] mState;
|
---|
| 191 | delete[] mDyn;
|
---|
| 192 | // printf("-- OOFNoise::~OOFNoise (Destructeur) ---\n");
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
[568] | 196 | //++
|
---|
| 197 | // Titre Public Methods
|
---|
| 198 | //--
|
---|
[228] | 199 | /* --Methode-- */
|
---|
[568] | 200 | //++
|
---|
[228] | 201 | float OOFNoise::Noise()
|
---|
[568] | 202 | //
|
---|
| 203 | //--
|
---|
[228] | 204 | {
|
---|
| 205 | int i;
|
---|
| 206 | double rn;
|
---|
| 207 |
|
---|
| 208 | for(i=(mMemL-1); i>0; i--) mState[i] = mState[i-1];
|
---|
| 209 | mState[0] = NoiseGenerator::Noise();
|
---|
| 210 | rn = 0.;
|
---|
| 211 | for(i=0; i< mMemL; i++) rn += mDyn[i]*mState[i];
|
---|
| 212 | return(rn);
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | /* --Methode-- */
|
---|
[568] | 216 | //++
|
---|
[228] | 217 | void OOFNoise::Print()
|
---|
[568] | 218 | //
|
---|
| 219 | //--
|
---|
[228] | 220 | {
|
---|
| 221 | int i,j;
|
---|
| 222 | printf("OOFNoise::Print() MemL=%d Tau= %g \n", mMemL, mTau);
|
---|
| 223 | printf("OOFNoise::Print() Vecteur de Dynamique / Etat : \n");
|
---|
| 224 | for(i=0; i<mMemL-1; i+=2)
|
---|
| 225 | printf("%d: D=%g S=%g | %d: D=%g S=%g \n", i,
|
---|
| 226 | mDyn[i], mState[i], i+1, mDyn[i], mState[i]);
|
---|
| 227 | return;
|
---|
| 228 | }
|
---|
[568] | 229 | //++
|
---|
| 230 | // Class EXPNoise
|
---|
| 231 | //
|
---|
| 232 | // include bruit.h math.h fmath.h nbrandom.h
|
---|
| 233 | //
|
---|
| 234 | //--
|
---|
| 235 | //++
|
---|
| 236 | //
|
---|
| 237 | // Links Parents
|
---|
| 238 | //
|
---|
| 239 | // NoiseGenerator
|
---|
| 240 | //
|
---|
| 241 | //--
|
---|
| 242 | //++
|
---|
| 243 | // Titre Constructor
|
---|
| 244 | //--
|
---|
[228] | 245 |
|
---|
| 246 | /* --Methode-- */
|
---|
[568] | 247 | //++
|
---|
[228] | 248 | EXPNoise::EXPNoise(float sigma, int typacf, int mem, float tau)
|
---|
| 249 | : NoiseGenerator(sigma)
|
---|
[568] | 250 | //
|
---|
| 251 | //--
|
---|
[228] | 252 | {
|
---|
| 253 | if (typacf != ACF_Exp) typacf = ACF_Exp;
|
---|
| 254 | // Fonction d'autocorrelation exponentiel disponible uniquement
|
---|
| 255 | // Reza , Juillet 97
|
---|
| 256 | mTypACF = typacf;
|
---|
| 257 | if (mem < 1) mem = 1;
|
---|
| 258 | mMemL = mem;
|
---|
| 259 | if (tau < 1.e-6) tau = 1.e-6;
|
---|
| 260 | mTau = tau;
|
---|
| 261 | mState = new double[mem];
|
---|
| 262 | mDyn = new double[mem];
|
---|
| 263 | int i;
|
---|
| 264 | for(i=0; i<mem; i++) {
|
---|
| 265 | mState[i] = 0.; mDyn[i] = exp(-(double)i/tau);
|
---|
| 266 | }
|
---|
| 267 | //printf("-- EXPNoise::EXPNoise(%g,%d,%d,%g) (Constructeur) ---\n",
|
---|
| 268 | // sigma, typacf, mem, tau);
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 |
|
---|
[568] | 272 | //++
|
---|
| 273 | // Titre Destructor
|
---|
| 274 | //--
|
---|
[228] | 275 | /* --Methode-- */
|
---|
[568] | 276 | //++
|
---|
[228] | 277 | EXPNoise::~EXPNoise()
|
---|
[568] | 278 | //
|
---|
| 279 | //--
|
---|
[228] | 280 | {
|
---|
| 281 | delete[] mState;
|
---|
| 282 | delete[] mDyn;
|
---|
| 283 | //printf("-- EXPNoise::~EXPNoise (Destructeur) ---\n");
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 |
|
---|
[568] | 287 | //++
|
---|
| 288 | // Titre Public Methods
|
---|
| 289 | //--
|
---|
[228] | 290 | /* --Methode-- */
|
---|
[568] | 291 | //++
|
---|
[228] | 292 | float EXPNoise::Noise()
|
---|
[568] | 293 | //
|
---|
| 294 | //--
|
---|
[228] | 295 | {
|
---|
| 296 | int i;
|
---|
| 297 | double rn;
|
---|
| 298 |
|
---|
| 299 | for(i=(mMemL-1); i>0; i--) mState[i] = mState[i-1];
|
---|
| 300 | mState[0] = NoiseGenerator::Noise();
|
---|
| 301 | rn = 0.;
|
---|
| 302 | for(i=0; i< mMemL; i++) rn += mDyn[i]*mState[i];
|
---|
| 303 | return(rn);
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | /* --Methode-- */
|
---|
[568] | 307 | //++
|
---|
[228] | 308 | void EXPNoise::Print()
|
---|
[568] | 309 | //
|
---|
| 310 | //--
|
---|
[228] | 311 | {
|
---|
| 312 | int i,j;
|
---|
| 313 | printf("EXPNoise::Print() MemL=%d Tau= %g \n", mMemL, mTau);
|
---|
| 314 | printf("EXPNoise::Print() Vecteur de Dynamique / Etat : \n");
|
---|
| 315 | for(i=0; i<mMemL-1; i+=2)
|
---|
| 316 | printf("%d: D=%g S=%g | %d: D=%g S=%g \n", i,
|
---|
| 317 | mDyn[i], mState[i], i+1, mDyn[i], mState[i]);
|
---|
| 318 |
|
---|
| 319 | return;
|
---|
| 320 | }
|
---|
[568] | 321 |
|
---|
| 322 | //++
|
---|
| 323 | // Class MemNoise
|
---|
| 324 | //
|
---|
| 325 | // include bruit.h math.h fmath.h nbrandom.h
|
---|
| 326 | //
|
---|
| 327 | //--
|
---|
| 328 | //++
|
---|
| 329 | //
|
---|
| 330 | // Links Parents
|
---|
| 331 | //
|
---|
| 332 | // NoiseGenerator
|
---|
| 333 | //
|
---|
| 334 | //--
|
---|
| 335 | //++
|
---|
| 336 | // Titre Constructor
|
---|
| 337 | //--
|
---|
| 338 |
|
---|
| 339 |
|
---|
[680] | 340 | // ---------------- $CHECK$ Reza 1/12/99 ------------
|
---|
| 341 | // ----- MAJ MemNoise et SumNoise / version F. Couchot (~couchot/CoSa/Samba/bruit.cc )
|
---|
| 342 | // -----------------------------------------------------------
|
---|
[568] | 343 |
|
---|
[228] | 344 | /* --Methode-- */
|
---|
[568] | 345 | //++
|
---|
[228] | 346 | MemNoise::MemNoise(float sigma, int mem, float tau, int ava)
|
---|
| 347 | : NoiseGenerator(sqrtf(fabsf(tau))*sigma)
|
---|
[568] | 348 | //
|
---|
| 349 | //--
|
---|
[228] | 350 | {
|
---|
| 351 | /* on tire les instants des impulsions successives selon une
|
---|
| 352 | loi de distance exponentielle de duree tau
|
---|
| 353 | */
|
---|
| 354 | const int place = 1000;
|
---|
| 355 | mTypACF = ACF_Exp;
|
---|
| 356 | if (mem < 1) mem = 1;
|
---|
| 357 | mMemL = place;
|
---|
| 358 | mCoupHaut=mem;
|
---|
| 359 | if (tau < 1.) tau = 1.;
|
---|
| 360 | mTau = tau;
|
---|
| 361 | mStPos = new float[place];
|
---|
| 362 | mStNeg = new float[place];
|
---|
| 363 | mTePos = new float[place];
|
---|
| 364 | mTeNeg = new float[place];
|
---|
| 365 | // printf("apres reservation\n");
|
---|
| 366 | int i;
|
---|
| 367 | for(i=0; i<place; i++)
|
---|
| 368 | {
|
---|
| 369 | mStNeg[i] = 0.; mStPos[i] = 0.;
|
---|
| 370 | }
|
---|
| 371 | // printf("apres initialisation tableaux \n");
|
---|
| 372 |
|
---|
| 373 | mNappel=0;
|
---|
| 374 | mNtirage=1;
|
---|
| 375 | mNappLast=0;
|
---|
| 376 | mMemPos=1;
|
---|
| 377 | mMemNeg=1;
|
---|
| 378 | mduree=0.;
|
---|
| 379 | mTePos[0]=0.;
|
---|
| 380 | mTeNeg[0]=0.;
|
---|
| 381 | mTdernier=0.;
|
---|
| 382 |
|
---|
| 383 | Avance(ava);
|
---|
| 384 | // printf("fin du createur MemNoise \n");
|
---|
| 385 | //printf("-- EXPNoise::EXPNoise(%g,%d,%d,%g) (Constructeur) ---\n",
|
---|
| 386 | // sigma, typacf, mem, tau);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 |
|
---|
[568] | 390 | //++
|
---|
| 391 | // Titre Destructor
|
---|
| 392 | //--
|
---|
[228] | 393 | /* --Methode-- */
|
---|
[568] | 394 | //++
|
---|
[228] | 395 | MemNoise::~MemNoise()
|
---|
[568] | 396 | //
|
---|
| 397 | //--
|
---|
[228] | 398 | {
|
---|
| 399 | delete[] mStPos;
|
---|
| 400 | delete[] mStNeg;
|
---|
| 401 | delete[] mTePos;
|
---|
| 402 | delete[] mTeNeg;
|
---|
| 403 | //printf("-- EXPNoise::~EXPNoise (Destructeur) ---\n");
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[568] | 406 | //++
|
---|
| 407 | // Titre Public Methods
|
---|
| 408 | //--
|
---|
[228] | 409 | /* --Methode-- */
|
---|
[568] | 410 | //++
|
---|
[228] | 411 | float MemNoise::Noise()
|
---|
[568] | 412 | //
|
---|
| 413 | //--
|
---|
[228] | 414 | {
|
---|
| 415 | return(Avance(0));
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | /* --Methode-- */
|
---|
[568] | 419 | //++
|
---|
[228] | 420 | float MemNoise::Avance(long Asauter)
|
---|
[568] | 421 | //
|
---|
| 422 | //--
|
---|
[228] | 423 | {
|
---|
| 424 | int i,j;
|
---|
| 425 | float boum;
|
---|
[680] | 426 | float rn = 0;
|
---|
[228] | 427 | float Somme,SbaryT,Poids,BaryT,Approx,Erreur;
|
---|
| 428 | int nReduit;
|
---|
| 429 | const float epsilon=.05;
|
---|
| 430 | // printf("entree dans methode Noise de MemNoise \n");
|
---|
| 431 | long mNsaut;
|
---|
| 432 | for (mNsaut = Asauter ; mNsaut >= 0 ; mNsaut--)
|
---|
| 433 | { // debut mNsaut
|
---|
| 434 | // printf("mNsaut = %ld\n",mNsaut);
|
---|
| 435 | mNappel++;
|
---|
| 436 | mTdernier += 1.;
|
---|
| 437 | for(i=0; i<mMemPos; i++) mTePos[i] += 1.;
|
---|
| 438 | for(i=0; i<mMemNeg; i++) mTeNeg[i] += 1.;
|
---|
| 439 |
|
---|
| 440 | if (mduree < mTdernier)
|
---|
| 441 | {
|
---|
| 442 | /* la duree depuis le dernier tirage est maintenant ecoulee
|
---|
| 443 | on commence par remettre a jour le temps ecoule entre la derniere
|
---|
| 444 | impulsion (celle qu'on va tirer maintenant) et l'instant present */
|
---|
| 445 |
|
---|
| 446 | mTdernier = mTdernier - mduree;
|
---|
| 447 |
|
---|
| 448 | /* puis on tire une nouvelle impulsion de bruit */
|
---|
| 449 |
|
---|
| 450 | boum = NoiseGenerator::Noise();
|
---|
| 451 |
|
---|
| 452 | /* on decale la memoire d'une case vers le passe
|
---|
| 453 | puis on met a jour la case [0] */
|
---|
| 454 |
|
---|
| 455 | if(boum>0)
|
---|
| 456 | {
|
---|
| 457 | for(i=mMemPos; i>0; i--)
|
---|
| 458 | {
|
---|
| 459 | mStPos[i] = mStPos[i-1];
|
---|
| 460 | mTePos[i] = mTePos[i-1];
|
---|
| 461 | }
|
---|
| 462 | mTePos[0] = mTdernier;
|
---|
| 463 | mStPos[0] = boum;
|
---|
| 464 | if (mMemPos<mMemL) mMemPos++;
|
---|
| 465 | /* a chaque tirage, on regroupe les impulsions precedentes */
|
---|
| 466 | for(i=mMemPos-2 ; i>0 ; i--)
|
---|
| 467 | {
|
---|
| 468 | if(mStPos[i]==0.)continue;
|
---|
| 469 | // printf("i,temps,bruit %d,%g,%g \n",i,mTePos[i],mStPos[i]);
|
---|
| 470 | Somme = mStPos[i]/sqrtf(mTePos[i]);
|
---|
| 471 | SbaryT = mStPos[i] * mTePos[i];
|
---|
| 472 | Poids = mStPos[i];
|
---|
| 473 | for(j=i-1 ; j>=0 ; j--)
|
---|
| 474 | {
|
---|
| 475 | // printf(" j,temps,bruit %d,%g,%g \n",j,mTePos[j],mStPos[j]);
|
---|
| 476 | Somme += mStPos[j]/sqrtf(mTePos[j]);
|
---|
| 477 | Poids += mStPos[j];
|
---|
| 478 | SbaryT += mStPos[j] * mTePos[j];
|
---|
| 479 | BaryT = SbaryT / Poids;
|
---|
| 480 | Approx = Poids / sqrtf(BaryT);
|
---|
| 481 | Erreur = (Approx - Somme) / Somme;
|
---|
| 482 | // printf("i,j = %d %d Approx = %g \n",i,j,fabsf(Erreur));
|
---|
| 483 | // printf("Temps,Bruit = %g %g \n",BaryT,Poids);
|
---|
| 484 | if(fabsf(Erreur)<epsilon)
|
---|
| 485 | {
|
---|
| 486 | mStPos[i]=Poids;
|
---|
| 487 | mTePos[i]=BaryT;
|
---|
| 488 | mStPos[j]=0.;
|
---|
| 489 | }
|
---|
| 490 | else break;
|
---|
| 491 | }
|
---|
| 492 | }
|
---|
| 493 | nReduit=0;
|
---|
| 494 | for(i=0; i<mMemPos-1 ; i++)
|
---|
| 495 | {
|
---|
| 496 | if(mStPos[i]!=0)
|
---|
| 497 | {
|
---|
| 498 | mStPos[nReduit]=mStPos[i];
|
---|
| 499 | mTePos[nReduit]=mTePos[i];
|
---|
| 500 | nReduit++;
|
---|
| 501 | }
|
---|
| 502 | }
|
---|
| 503 | mMemPos=nReduit+1;
|
---|
| 504 |
|
---|
| 505 | }
|
---|
| 506 | else
|
---|
| 507 | {
|
---|
| 508 | for(i=mMemNeg; i>0; i--)
|
---|
| 509 | {
|
---|
| 510 | mStNeg[i] = mStNeg[i-1];
|
---|
| 511 | mTeNeg[i] = mTeNeg[i-1];
|
---|
| 512 | }
|
---|
| 513 | mTeNeg[0] = mTdernier;
|
---|
| 514 | mStNeg[0] = boum;
|
---|
| 515 | if (mMemNeg<mMemL) mMemNeg++;
|
---|
| 516 |
|
---|
| 517 |
|
---|
| 518 | /* idem pour negatifs */
|
---|
| 519 | for(i=mMemNeg-2 ; i>0 ; i--)
|
---|
| 520 | {
|
---|
| 521 | if(mStNeg[i]==0.)continue;
|
---|
| 522 | // printf("i,temps,bruit %d,%g,%g \n",i,mTeNeg[i],mStNeg[i]);
|
---|
| 523 | Somme = mStNeg[i]/sqrtf(mTeNeg[i]);
|
---|
| 524 | SbaryT = mStNeg[i] * mTeNeg[i];
|
---|
| 525 | Poids = mStNeg[i];
|
---|
| 526 | for(j=i-1 ; j>=0 ; j--)
|
---|
| 527 | {
|
---|
| 528 | // printf(" j,temps,bruit %d,%g,%g \n",j,mTeNeg[j],mStNeg[j]);
|
---|
| 529 | Somme += mStNeg[j]/sqrtf(mTeNeg[j]);
|
---|
| 530 | Poids += mStNeg[j];
|
---|
| 531 | SbaryT += mStNeg[j] * mTeNeg[j];
|
---|
| 532 | BaryT = SbaryT / Poids;
|
---|
| 533 | Approx = Poids / sqrtf(BaryT);
|
---|
| 534 | Erreur = (Approx - Somme) / Somme;
|
---|
| 535 | // printf("i,j = %d %d Approx = %g \n",i,j,Erreur);
|
---|
| 536 | // printf("Temps,Bruit = %g %g \n",BaryT,Poids);
|
---|
| 537 | if(fabsf(Erreur)<epsilon)
|
---|
| 538 | {
|
---|
| 539 | mStNeg[i]=Poids;
|
---|
| 540 | mTeNeg[i]=BaryT;
|
---|
| 541 | mStNeg[j]=0.;
|
---|
| 542 | }
|
---|
| 543 | else break;
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
| 546 | nReduit=0;
|
---|
| 547 | for(i=0; i<mMemNeg-1 ; i++)
|
---|
| 548 | {
|
---|
| 549 | if(mStNeg[i]!=0)
|
---|
| 550 | {
|
---|
| 551 | mStNeg[nReduit]=mStNeg[i];
|
---|
| 552 | mTeNeg[nReduit]=mTeNeg[i];
|
---|
| 553 | nReduit++;
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
| 556 | mMemNeg=nReduit+1;
|
---|
| 557 | }
|
---|
| 558 | /* on tire la duree a attendre avant la prochaine impulsion de bruit */
|
---|
[680] | 559 | // $CHECK$ avec Francois - rndm() remplace par Reza 10/01/99
|
---|
| 560 | // passage en drand le 1/12/99
|
---|
| 561 | mduree = -mTau*log(drand01());
|
---|
[228] | 562 |
|
---|
| 563 | // if(mNtirage<mMemL) mNtirage++;
|
---|
| 564 | mNtirage++;
|
---|
| 565 | /*
|
---|
| 566 | int idn=1;
|
---|
| 567 | float pds=1.;
|
---|
| 568 | float nul=0.;
|
---|
| 569 | hfill_(&idn,&mduree,&nul,&pds);
|
---|
| 570 | */
|
---|
| 571 | // printf("Ntirage %d,mMemPos,Neg %d,%d, Suppress = %d \n",mNtirage,mMemPos,mMemNeg, Suppress);
|
---|
| 572 | }
|
---|
| 573 | /* On calcule le bruit total */
|
---|
| 574 |
|
---|
| 575 | //printf("mMemPos,Neg,%d %d\n",mMemPos,mMemNeg);
|
---|
| 576 | //for(i=0;i<mMemPos;i++) printf("mTePos %g \n",mTePos);
|
---|
| 577 | //for(i=0;i<mMemNeg;i++) printf("mTeNeg %g \n",mTeNeg);
|
---|
| 578 | if(mNsaut == 0)
|
---|
| 579 | {
|
---|
| 580 | // printf("coucou\n");
|
---|
| 581 | rn = 0.;
|
---|
| 582 | int indlim=0;
|
---|
| 583 | for(i=0; i < mMemPos-1; i++)
|
---|
| 584 | {
|
---|
[782] | 585 | if(mTePos[i] > 1.) break; // Modif F.C et D.Y. 03/2000
|
---|
[228] | 586 | rn += mStPos[i];
|
---|
| 587 | indlim++;
|
---|
| 588 | }
|
---|
| 589 | // float ajout=0.;
|
---|
| 590 | for(i=indlim; i < mMemPos-1; i++) rn += mStPos[i]/sqrtf(mTePos[i]);
|
---|
| 591 | indlim=0;
|
---|
| 592 | for(i=0; i < mMemNeg-1; i++)
|
---|
| 593 | {
|
---|
[782] | 594 | if(mTeNeg[i] > 1.) break; // Modif F.C et D.Y. 03/2000
|
---|
[228] | 595 | rn += mStNeg[i];
|
---|
| 596 | indlim++;
|
---|
| 597 | }
|
---|
| 598 | for(i=indlim; i < mMemNeg-1; i++) rn += mStNeg[i]/sqrtf(mTeNeg[i]);
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
| 601 | return(rn);
|
---|
| 602 | }
|
---|
| 603 | /* --Methode-- */
|
---|
[568] | 604 | //++
|
---|
[228] | 605 | int MemNoise::Print()
|
---|
[568] | 606 | //
|
---|
| 607 | //--
|
---|
[228] | 608 | {
|
---|
| 609 | int i,j,rc=0;
|
---|
| 610 | printf("MemNoise::Print() MemL=%d Tau= %g \n", mMemL, mTau);
|
---|
| 611 | printf("mNtirage= %d , mMemPos= %d , mMemNeg= %d \n",mNtirage,mMemPos,mMemNeg);
|
---|
| 612 | // printf("MemNoise::Print() Vecteur de Dynamique / Etat : \n");
|
---|
| 613 | /* for(i=0; i<mMemL-1; i+=2)
|
---|
| 614 | printf("%d: D=%g S=%g | %d: D=%g S=%g \n", i,
|
---|
| 615 | mDyn[i], mState[i], i+1, mDyn[i], mState[i]);
|
---|
| 616 | */
|
---|
| 617 | return(rc);
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[568] | 620 | //++
|
---|
| 621 | // Class SumNoise
|
---|
| 622 | //
|
---|
| 623 | // include bruit.h math.h fmath.h nbrandom.h
|
---|
| 624 | //
|
---|
[700] | 625 | // Generateur de bruit blanc + 1/f avec fknee
|
---|
| 626 |
|
---|
[568] | 627 | //--
|
---|
| 628 | //++
|
---|
| 629 | //
|
---|
| 630 | // Links Parents
|
---|
| 631 | //
|
---|
| 632 | // NoiseGenerator
|
---|
| 633 | //
|
---|
| 634 | //--
|
---|
| 635 | //++
|
---|
| 636 | // Titre Constructor
|
---|
| 637 | //--
|
---|
[228] | 638 | // Generateur de bruit blanc + 1/f avec fknee
|
---|
| 639 |
|
---|
| 640 |
|
---|
| 641 | /* --Methode-- */
|
---|
[568] | 642 | //++
|
---|
[680] | 643 | SumNoise::SumNoise(float fknee, float sig, int mem, float tau)
|
---|
[228] | 644 | : NoiseGenerator(sig)
|
---|
[568] | 645 | //
|
---|
| 646 | //--
|
---|
[228] | 647 | {
|
---|
| 648 | // Reza 27/01/98 :
|
---|
| 649 | // Je calcule les sigma du MemNoise d'apres la formule de Francois
|
---|
[680] | 650 | // mn = new MemNoise(sig*fknee);
|
---|
| 651 | // mn = new MemNoise(1.4142*sig*sqrtf(fknee),1,10.,1000000); // modif appel FC 13 mai 98.
|
---|
| 652 | mn = new MemNoise(1.4142*sig*sqrt((double)fknee),mem,tau,12000); // FC 13 mai 98. -> Reza 1/12/99
|
---|
[228] | 653 | }
|
---|
| 654 |
|
---|
| 655 |
|
---|
[568] | 656 | //++
|
---|
| 657 | // Titre Destructor
|
---|
| 658 | //--
|
---|
[228] | 659 | /* --Methode-- */
|
---|
[568] | 660 | //++
|
---|
[228] | 661 | SumNoise::~SumNoise()
|
---|
[568] | 662 | //
|
---|
| 663 | //--
|
---|
[228] | 664 | {
|
---|
| 665 | delete mn;
|
---|
| 666 | }
|
---|
| 667 |
|
---|
[568] | 668 | //++
|
---|
| 669 | // Titre Public Methods
|
---|
| 670 | //--
|
---|
[228] | 671 | /* --Methode-- */
|
---|
[568] | 672 | //++
|
---|
[228] | 673 | float SumNoise::Noise()
|
---|
[568] | 674 | //
|
---|
| 675 | //--
|
---|
[228] | 676 | {
|
---|
| 677 | return(NoiseGenerator::Noise() + mn->Noise());
|
---|
| 678 | }
|
---|