| 1 |
|
| /* This program simulates fractional Gaussian noise or fractional */
|
| 2 |
|
| /* Brownian motion using the Paxson algorithm. */
|
| 3 |
|
| /* The C-packages Ranlib and Meschach are used, both available */
|
| 4 |
|
| /* via Netlib (http://www.netlib.org). */
|
| 5 |
|
|
|
| 6 |
|
| /* References: */
|
| 7 |
|
| /* 1) V. Paxson (1997), */
|
| 8 |
|
| /* Fast, approximate synthesis of fractional Gaussian noise for */
|
| 9 |
|
| /* generating self-similar network traffic, */
|
| 10 |
|
| /* Computer Communication Review, Vol. 27, pp. 5-18. */
|
| 11 |
|
| /* 2) A.B. Dieker and M. Mandjes (2002), */
|
| 12 |
|
| /* On spectral simulation of fractional Brownian motion, */
|
| 13 |
|
| /* submitted for publication. */
|
| 14 |
|
|
|
| 15 |
|
| /* Copyright Ton Dieker */
|
| 16 |
|
| /* Centre of Mathematics and Computer Science (CWI) Amsterdam */
|
| 17 |
|
| /* April 2002 */
|
| 18 |
|
|
|
| 19 |
|
| /* ton@cwi.nl */
|
| 20 |
|
| /* Modified to remove the dependence on meschach by Walter Szeliga */
|
| 21 |
|
| /* Mar 2005 */
|
| 22 |
|
|
|
| 23 |
|
| #include "paxson.h"
|
| 24 |
|
| #include "fft.h"
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
1 |
| void paxson(long *num, double *H, double *L, int *cum, long *seed1,
|
| 28 |
|
| long *seed2, double *output) {
|
| 29 |
|
| /* function that generates a fractional Brownian motion or fractional */
|
| 30 |
|
| /* Gaussian noise sample using the approximate Paxson method. */
|
| 31 |
|
| /* Input: *num determines the sample size N by N=2^(*num) */
|
| 32 |
|
| /* *H the Hurst parameter of the trace */
|
| 33 |
|
| /* *L the sample is generated on [0,L] */
|
| 34 |
|
| /* *cum = 0: fractional Gaussian noise is produced */
|
| 35 |
|
| /* = 1: fractional Brownian motion is produced */
|
| 36 |
|
| /* *seed1 seed1 for the random generator */
|
| 37 |
|
| /* *seed2 seed2 for the random generator */
|
| 38 |
|
| /* Output: *seed1 new seed1 of the random generator */
|
| 39 |
|
| /* *seed2 new seed2 of the random generator */
|
| 40 |
|
| /* *output the resulting sample is stored in this array */
|
| 41 |
|
| long i, n, halfn, generator;
|
| 42 |
|
| double scaling;
|
| 43 |
|
| double *pow_spec;
|
| 44 |
|
| double aux;
|
| 45 |
|
| complex *a;
|
| 46 |
|
|
|
| 47 |
1 |
| n = pow(2,*num);
|
| 48 |
1 |
| halfn = n/2;
|
| 49 |
|
|
|
| 50 |
|
| /* set random generator and seeds */
|
| 51 |
1 |
| snorm();
|
| 52 |
1 |
| generator = 1;
|
| 53 |
1 |
| gscgn(1, &generator);
|
| 54 |
1 |
| setall(*seed1,*seed2);
|
| 55 |
|
|
|
| 56 |
|
| /* allocate memory */
|
| 57 |
1 |
| pow_spec = (double*) malloc( (halfn+1) * sizeof(double));
|
| 58 |
|
|
|
| 59 |
|
| /* approximate spectral density */
|
| 60 |
1 |
| FGN_spectrum(pow_spec,halfn,*H);
|
| 61 |
|
|
|
| 62 |
|
| /* real part of Fourier transform of a_re + i a_im gives sample path */
|
| 63 |
1 |
| a = malloc(n*sizeof(complex));
|
| 64 |
1 |
| a[0].re = 0.;
|
| 65 |
1 |
| a[0].im = 0.;
|
| 66 |
33 |
▶ | for(i=1; i<=halfn; i++) {
|
Branch: 1 branch
| Branch | True | False | Total |
| for(i=1; i<=halfn; i++) {
|
32 |
1 |
33 |
|
| 67 |
32 |
| aux = sqrt(pow_spec[i]);
|
| 68 |
32 |
| a[i].re = aux*snorm();
|
| 69 |
32 |
| a[i].im = aux*snorm();
|
| 70 |
|
| }
|
| 71 |
32 |
▶ | for(i=halfn+1; i<n; i++) {
|
Branch: 1 branch
| Branch | True | False | Total |
| for(i=halfn+1; i<n; i++) {
|
31 |
1 |
32 |
|
| 72 |
31 |
| a[i].re = a[n-i].re;
|
| 73 |
31 |
| a[i].im = -a[n-i].im;
|
| 74 |
|
| }
|
| 75 |
|
|
|
| 76 |
|
| /* real part of Fourier transform of a_re + i a_im gives sample path */
|
| 77 |
1 |
| fft(n,a,1,1.0);
|
| 78 |
|
|
|
| 79 |
|
| /* rescale to obtain a sample of size 2^(*n) on [0,L] */
|
| 80 |
1 |
| scaling = pow(*L/n,*H)/sqrt(2*n);
|
| 81 |
65 |
▶ | for(i=0; i<n; i++) {
|
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<n; i++) {
|
64 |
1 |
65 |
|
| 82 |
64 |
| output[i] = scaling*(a[i].re);
|
| 83 |
64 |
▶ | if (*cum && i>0) {
|
Branch: 2 branches
| Branch | True | False | Total |
| if (*cum && i>0) {
|
0 |
64 |
64 |
| if (*cum && i>0) {
|
0 |
0 |
0 |
|
| 84 |
0 |
| output[i] += output[i-1];
|
| 85 |
|
| }
|
| 86 |
|
| }
|
| 87 |
|
|
|
| 88 |
|
| /* store the new random seeds and free memory */
|
| 89 |
1 |
| getsd(seed1,seed2);
|
| 90 |
|
|
|
| 91 |
1 |
| free(pow_spec);
|
| 92 |
1 |
| free(a);
|
| 93 |
1 |
| }
|
| 94 |
|
|
|