| 1 |
|
| /*************************************************************************** |
| 2 |
|
| * The code is taken from a file by |
| 3 |
|
| * Christian Schuler |
| 4 |
|
| * Research Institute for Open Communication Systems |
| 5 |
|
| * GMD FOKUS, Hardenbergplatz 2, D-10623 Berlin, Germany |
| 6 |
|
| * Phone : ++49 / (0)30 / 254 99 - 295 |
| 7 |
|
| * email : schuler@fokus.gmd.de |
| 8 |
|
| |
| 9 |
|
| Copyright (c) 1995 The Regents of the University of California. |
| 10 |
|
| All rights reserved. |
| 11 |
|
| |
| 12 |
|
| This code is derived from software contributed to Berkeley by |
| 13 |
|
| Vern Paxson. |
| 14 |
|
| |
| 15 |
|
| The United States Government has rights in this work pursuant |
| 16 |
|
| to contract no. DE-AC03-76SF00098 between the United States |
| 17 |
|
| Department of Energy and the University of California. |
| 18 |
|
| |
| 19 |
|
| Redistribution and use in source and binary forms are permitted |
| 20 |
|
| provided that: (1) source distributions retain this entire |
| 21 |
|
| copyright notice and comment, and (2) distributions including |
| 22 |
|
| binaries display the following acknowledgement: ``This product |
| 23 |
|
| includes software developed by the University of California, |
| 24 |
|
| Berkeley and its contributors'' in the documentation or other |
| 25 |
|
| materials provided with the distribution and in all advertising |
| 26 |
|
| materials mentioning features or use of this software. Neither the |
| 27 |
|
| name of the University nor the names of its contributors may be |
| 28 |
|
| used to endorse or promote products derived from this software |
| 29 |
|
| without specific prior written permission. |
| 30 |
|
| |
| 31 |
|
| THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 32 |
|
| IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 33 |
|
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 34 |
|
| PURPOSE. |
| 35 |
|
| |
| 36 |
|
| -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 37 |
|
| This basically says "do whatever you please with this software except |
| 38 |
|
| remove this notice or take advantage of the University's (or the author's) |
| 39 |
|
| name". |
| 40 |
|
| |
| 41 |
|
| In particular, you are free to redistribute the software, sell it, |
| 42 |
|
| modify it, etc., provided you abide by the terms above. |
| 43 |
|
| |
| 44 |
|
| * |
| 45 |
|
| * description: |
| 46 |
|
| * Generation of Fractional Gaussian Noise by the FFT-Algorithm proposed by |
| 47 |
|
| * Vern Paxson, "Fast Approximation of Self-Similar Network Traffic", |
| 48 |
|
| * Berkeley 1995 |
| 49 |
|
| * Info: |
| 50 |
|
| * "http://town.hall.org/Archives/pub/ITA/html/contrib/fft-fgn.html" |
| 51 |
|
| * |
| 52 |
|
| ***************************************************************************/ |
| 53 |
|
| |
| 54 |
|
| #include <math.h> |
| 55 |
|
| #include "spectrum.h" |
| 56 |
|
| |
| 57 |
|
| |
| 58 |
2 |
| void FGN_spectrum ( double *pow_spec, int n, double H) { |
| 59 |
|
| /* Returns an approximation of the power spectrum for fractional */ |
| 60 |
|
| /* Gaussian noise at the given frequencies lambda and the given Hurst */ |
| 61 |
|
| /* parameter H. */ |
| 62 |
|
| int i; |
| 63 |
|
| double lambda,fact1,a,b,c,g; |
| 64 |
|
| |
| 65 |
|
| /* the result of lgamma will always be positive: */ |
| 66 |
2 |
| g = lgamma(2.0 * H + 1.0); |
| 67 |
|
| |
| 68 |
2 |
| fact1 = 2.0 * sin(M_PI * H) * exp(g); |
| 69 |
|
| |
| 70 |
98 |
▶ | for(i=1; i<n+1; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=1; i<n+1; i++) { |
96 |
2 |
98 |
|
| 71 |
96 |
| lambda = (M_PI * i) / n; |
| 72 |
96 |
| a = fact1 * (1.0 - cos(lambda)); |
| 73 |
96 |
| b = pow(lambda,(-2.0 * H - 1.0)); |
| 74 |
96 |
| c = FGN_B_est_adj(lambda, H); |
| 75 |
96 |
| pow_spec[i] = a * (b + c); |
| 76 |
|
| } |
| 77 |
2 |
| } |
| 78 |
|
| |
| 79 |
|
| |
| 80 |
96 |
| double FGN_B_est (double lambda, double H) { |
| 81 |
|
| /* Returns the estimate for B(lambda,H). */ |
| 82 |
|
| int k; |
| 83 |
|
| double d, dprime, sum1,sum2,result; |
| 84 |
|
| double a[5],b[5]; /* index 0 never used ! */ |
| 85 |
|
| |
| 86 |
96 |
| d = -2.0 * H - 1.0; |
| 87 |
96 |
| dprime = -2.0 * H; |
| 88 |
|
| |
| 89 |
480 |
▶ | for(k=1; k<5; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=1; k<5; k++) { |
384 |
96 |
480 |
|
| 90 |
384 |
| a[k] = 2.0 * k * M_PI + lambda; |
| 91 |
384 |
| b[k] = 2.0 * k * M_PI - lambda; |
| 92 |
|
| } |
| 93 |
|
| |
| 94 |
96 |
| sum1 = 0.0; |
| 95 |
384 |
▶ | for(k=1; k<4; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=1; k<4; k++) { |
288 |
96 |
384 |
|
| 96 |
288 |
| sum1 += pow(a[k],d); |
| 97 |
288 |
| sum1 += pow(b[k],d); |
| 98 |
|
| } |
| 99 |
96 |
| sum2 = 0.0; |
| 100 |
288 |
▶ | for(k=3; k<5; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=3; k<5; k++) { |
192 |
96 |
288 |
|
| 101 |
192 |
| sum2 += pow(a[k],dprime); |
| 102 |
192 |
| sum2 += pow(b[k],dprime); |
| 103 |
|
| } |
| 104 |
96 |
| result = sum1 + (sum2 / (8.0 * M_PI * H)); |
| 105 |
96 |
| return(result); |
| 106 |
|
| } |
| 107 |
|
| |
| 108 |
|
| |
| 109 |
96 |
| double FGN_B_est_adj (double lambda, double H) { |
| 110 |
|
| /* Returns the adjusted estimate for B(lambda,H). */ |
| 111 |
288 |
| return (1.0002 - 0.000134 * lambda) * |
| 112 |
96 |
| (FGN_B_est(lambda,H) - pow(2, -7.65*H - 7.4)); |
| 113 |
|
| } |