1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 Author: 1987 Gary W. Ng
4 **********/
5 
6 /*
7  * Nintegrate.c (noizDens, lnNdens, lnNlstDens, data)
8  *
9  *    This subroutine evaluates the integral of the function
10  *
11  *                                             EXPONENT
12  *                      NOISE = a * (FREQUENCY)
13  *
14  *   given two points from the curve.  If EXPONENT is relatively close
15  *   to 0, the noise is simply multiplied by the change in frequency.
16  *   If it isn't, a more complicated expression must be used.  Note that
17  *   EXPONENT = -1 gives a different equation than EXPONENT <> -1.
18  *   Hence, the reason for the constant 'N_INTUSELOG'.
19  */
20 
21 #include "ngspice/ngspice.h"
22 #include "ngspice/noisedef.h"
23 
24 #define limexp(x) (x > 700 ? exp(700.0)*(1.0+x-700.0) : exp(x))
25 
26 double
Nintegrate(double noizDens,double lnNdens,double lnNlstDens,Ndata * data)27 Nintegrate (double noizDens, double lnNdens, double lnNlstDens, Ndata *data)
28 {
29     double exponent;
30     double a;
31 
32     exponent = (lnNdens - lnNlstDens) / data->delLnFreq;
33     if ( fabs(exponent) < N_INTFTHRESH ) {
34 	return (noizDens * data->delFreq);
35     } else {
36 	a = limexp(lnNdens - exponent*data->lnFreq);
37 	exponent += 1.0;
38 	if (fabs(exponent) < N_INTUSELOG) {
39 	    return (a * (data->lnFreq - data->lnLastFreq));
40         } else {
41 	    return (a * ((exp(exponent * data->lnFreq) - exp(exponent * data->lnLastFreq)) /
42 		    exponent));
43         }
44     }
45 }
46