This commit is contained in:
dwarning 2024-02-14 17:50:41 +01:00
parent e8f1cd4c92
commit 20c82a5b1b
4 changed files with 423 additions and 420 deletions

View File

@ -11,23 +11,22 @@ Author: 1987 Gary W. Ng
#include "ngspice/suffix.h"
/*
* BJTnoise (mode, operation, firstModel, ckt, data, OnDens)
*BJTnoise (mode, operation, firstModel, ckt, data, OnDens)
*
* This routine names and evaluates all of the noise sources
* associated with BJT's. It starts with the model *firstModel and
* traverses all of its insts. It then proceeds to any other models
* on the linked list. The total output noise density generated by
* all of the BJT's is summed with the variable "OnDens".
* This routine names and evaluates all of the noise sources
* associated with BJT's. It starts with the model *firstModel and
* traverses all of its insts. It then proceeds to any other models
* on the linked list. The total output noise density generated by
* all of the BJT's is summed with the variable "OnDens".
*/
int
BJTnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
Ndata *data, double *OnDens)
BJTnoise(int mode, int operation, GENmodel*genmodel, CKTcircuit *ckt,
Ndata *data, double *OnDens)
{
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
BJTmodel *firstModel = (BJTmodel *) genmodel;
BJTmodel *firstModel = (BJTmodel*) genmodel;
BJTmodel *model;
BJTinstance *inst;
double tempOnoise;
@ -39,159 +38,159 @@ BJTnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
/* define the names of the noise sources */
static char *BJTnNames[BJTNSRCS] = {
/* Note that we have to keep the order consistent with the
strchr definitions in BJTdefs.h */
"_rc", /* noise due to rc */
"_rb", /* noise due to rb */
"_re", /* noise due to re */
"_ic", /* noise due to ic */
"_ib", /* noise due to ib */
"_1overf", /* flicker (1/f) noise */
"" /* total transistor noise */
/* Note that we have to keep the order consistent with the
strchr definitions in BJTdefs.h */
"_rc", /* noise due to rc */
"_rb", /* noise due to rb */
"_re", /* noise due to re */
"_ic", /* noise due to ic */
"_ib", /* noise due to ib */
"_1overf", /* flicker (1/f) noise */
"" /* total transistor noise */
};
for (model=firstModel; model != NULL; model=BJTnextModel(model)) {
for (inst=BJTinstances(model); inst != NULL;
inst=BJTnextInstance(inst)) {
for (model = firstModel; model != NULL; model = BJTnextModel(model)) {
for (inst = BJTinstances(model); inst != NULL; inst = BJTnextInstance(inst)) {
switch (operation) {
switch (operation) {
case N_OPEN:
case N_OPEN:
/* see if we have to to produce a summary report */
/* if so, name all the noise generators */
/* see if we have to to produce a summary report */
/* if so, name all the noise generators */
if (job->NStpsSm != 0) {
switch (mode) {
if (job->NStpsSm != 0) {
switch (mode) {
case N_DENS:
for (i=0; i < BJTNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->BJTname, BJTnNames[i]);
}
break;
case N_DENS:
for (i = 0; i < BJTNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->BJTname, BJTnNames[i]);
}
break;
case INT_NOIZ:
for (i=0; i < BJTNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->BJTname, BJTnNames[i]);
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->BJTname, BJTnNames[i]);
}
break;
}
}
break;
case INT_NOIZ:
for (i = 0; i < BJTNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->BJTname, BJTnNames[i]);
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->BJTname, BJTnNames[i]);
}
break;
}
}
break;
case N_CALC:
switch (mode) {
case N_CALC:
switch (mode) {
case N_DENS:
NevalSrc(&noizDens[BJTRCNOIZ],&lnNdens[BJTRCNOIZ],
ckt,THERMNOISE,inst->BJTcollCXNode,inst->BJTcolNode,
inst->BJTtcollectorConduct * inst->BJTm);
case N_DENS:
NevalSrc(&noizDens[BJTRCNOIZ],&lnNdens[BJTRCNOIZ],
ckt, THERMNOISE, inst->BJTcollCXNode, inst->BJTcolNode,
inst->BJTtcollectorConduct * inst->BJTm);
NevalSrc(&noizDens[BJTRBNOIZ],&lnNdens[BJTRBNOIZ],
ckt,THERMNOISE,inst->BJTbasePrimeNode,inst->BJTbaseNode,
*(ckt->CKTstate0 + inst->BJTgx) * inst->BJTm);
NevalSrc(&noizDens[BJTRBNOIZ],&lnNdens[BJTRBNOIZ],
ckt, THERMNOISE, inst->BJTbasePrimeNode, inst->BJTbaseNode,
*(ckt->CKTstate0 + inst->BJTgx) * inst->BJTm);
NevalSrc(&noizDens[BJT_RE_NOISE],&lnNdens[BJT_RE_NOISE],
ckt,THERMNOISE,inst->BJTemitPrimeNode,inst->BJTemitNode,
inst->BJTtemitterConduct * inst-> BJTm);
NevalSrc(&noizDens[BJT_RE_NOISE],&lnNdens[BJT_RE_NOISE],
ckt, THERMNOISE, inst->BJTemitPrimeNode, inst->BJTemitNode,
inst->BJTtemitterConduct * inst->BJTm);
NevalSrc(&noizDens[BJTICNOIZ],&lnNdens[BJTICNOIZ],
ckt,SHOTNOISE,inst->BJTcolPrimeNode, inst->BJTemitPrimeNode,
*(ckt->CKTstate0 + inst->BJTcc) * inst->BJTm);
NevalSrc(&noizDens[BJTICNOIZ],&lnNdens[BJTICNOIZ],
ckt, SHOTNOISE, inst->BJTcolPrimeNode, inst->BJTemitPrimeNode,
*(ckt->CKTstate0 + inst->BJTcc) * inst->BJTm);
NevalSrc(&noizDens[BJTIBNOIZ],&lnNdens[BJTIBNOIZ],
ckt,SHOTNOISE,inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
*(ckt->CKTstate0 + inst->BJTcb) * inst->BJTm);
NevalSrc(&noizDens[BJTIBNOIZ],&lnNdens[BJTIBNOIZ],
ckt, SHOTNOISE, inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
*(ckt->CKTstate0 + inst->BJTcb) * inst->BJTm);
NevalSrc(&noizDens[BJTFLNOIZ], NULL, ckt,
N_GAIN,inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
(double)0.0);
noizDens[BJTFLNOIZ] *= inst->BJTm * model->BJTfNcoef *
exp(model->BJTfNexp *
log(MAX(fabs(*(ckt->CKTstate0 + inst->BJTcb)),N_MINLOG))) /
data->freq;
lnNdens[BJTFLNOIZ] =
log(MAX(noizDens[BJTFLNOIZ],N_MINLOG));
NevalSrc(&noizDens[BJTFLNOIZ], NULL, ckt,
N_GAIN, inst->BJTbasePrimeNode, inst->BJTemitPrimeNode,
(double) 0.0);
noizDens[BJTFLNOIZ] *= inst->BJTm * model->BJTfNcoef *
exp(model->BJTfNexp *
log(MAX(fabs(*(ckt->CKTstate0 + inst->BJTcb)), N_MINLOG))) /
data->freq;
lnNdens[BJTFLNOIZ] =
log(MAX(noizDens[BJTFLNOIZ], N_MINLOG));
noizDens[BJTTOTNOIZ] = noizDens[BJTRCNOIZ] +
noizDens[BJTRBNOIZ] +
noizDens[BJT_RE_NOISE] +
noizDens[BJTICNOIZ] +
noizDens[BJTIBNOIZ] +
noizDens[BJTFLNOIZ];
lnNdens[BJTTOTNOIZ] =
log(noizDens[BJTTOTNOIZ]);
noizDens[BJTTOTNOIZ] = noizDens[BJTRCNOIZ] +
noizDens[BJTRBNOIZ] +
noizDens[BJT_RE_NOISE] +
noizDens[BJTICNOIZ] +
noizDens[BJTIBNOIZ] +
noizDens[BJTFLNOIZ];
lnNdens[BJTTOTNOIZ] =
log(noizDens[BJTTOTNOIZ]);
*OnDens += noizDens[BJTTOTNOIZ];
*OnDens += noizDens[BJTTOTNOIZ];
if (data->delFreq == 0.0) {
if (data->delFreq == 0.0) {
/* if we haven't done any previous integration, we need to */
/* initialize our "history" variables */
/* if we haven't done any previous integration, we need to */
/* initialize our "history" variables */
for (i=0; i < BJTNSRCS; i++) {
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
}
for (i = 0; i < BJTNSRCS; i++) {
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
}
/* clear out our integration variables if it's the first pass */
/* clear out our integration variables if it's the first pass */
if (data->freq == job->NstartFreq) {
for (i=0; i < BJTNSRCS; i++) {
inst->BJTnVar[OUTNOIZ][i] = 0.0;
inst->BJTnVar[INNOIZ][i] = 0.0;
}
}
} else { /* data->delFreq != 0.0 (we have to integrate) */
if (data->freq == job->NstartFreq) {
for (i = 0; i < BJTNSRCS; i++) {
inst->BJTnVar[OUTNOIZ][i] = 0.0;
inst->BJTnVar[INNOIZ][i] = 0.0;
}
}
} else {
/* data->delFreq != 0.0 (we have to integrate) */
/* In order to get the best curve fit, we have to integrate each component separately */
/* In order to get the best curve fit, we have to integrate each component separately */
for (i=0; i < BJTNSRCS; i++) {
if (i != BJTTOTNOIZ) {
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
inst->BJTnVar[LNLSTDENS][i], data);
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv ,
lnNdens[i] + data->lnGainInv,
inst->BJTnVar[LNLSTDENS][i] + data->lnGainInv,
data);
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOnoise;
data->inNoise += tempInoise;
if (job->NStpsSm != 0) {
inst->BJTnVar[OUTNOIZ][i] += tempOnoise;
inst->BJTnVar[OUTNOIZ][BJTTOTNOIZ] += tempOnoise;
inst->BJTnVar[INNOIZ][i] += tempInoise;
inst->BJTnVar[INNOIZ][BJTTOTNOIZ] += tempInoise;
for (i = 0; i < BJTNSRCS; i++) {
if (i != BJTTOTNOIZ) {
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
inst->BJTnVar[LNLSTDENS][i], data);
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv,
lnNdens[i] + data->lnGainInv,
inst->BJTnVar[LNLSTDENS][i] + data->lnGainInv,
data);
inst->BJTnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOnoise;
data->inNoise += tempInoise;
if (job->NStpsSm != 0) {
inst->BJTnVar[OUTNOIZ][i] += tempOnoise;
inst->BJTnVar[OUTNOIZ][BJTTOTNOIZ] += tempOnoise;
inst->BJTnVar[INNOIZ][i] += tempInoise;
inst->BJTnVar[INNOIZ][BJTTOTNOIZ] += tempInoise;
}
}
}
}
if (data->prtSummary) {
for (i=0; i < BJTNSRCS; i++) { /* print a summary report */
data->outpVector[data->outNumber++] = noizDens[i];
}
}
break;
}
}
}
if (data->prtSummary) {
for (i = 0; i < BJTNSRCS; i++) {
/* print a summary report */
data->outpVector[data->outNumber++] = noizDens[i];
}
}
break;
case INT_NOIZ: /* already calculated, just output */
if (job->NStpsSm != 0) {
for (i=0; i < BJTNSRCS; i++) {
data->outpVector[data->outNumber++] = inst->BJTnVar[OUTNOIZ][i];
data->outpVector[data->outNumber++] = inst->BJTnVar[INNOIZ][i];
}
} /* if */
break;
} /* switch (mode) */
break;
case INT_NOIZ:
/* already calculated, just output */
if (job->NStpsSm != 0) {
for (i = 0; i < BJTNSRCS; i++) {
data->outpVector[data->outNumber++] = inst->BJTnVar[OUTNOIZ][i];
data->outpVector[data->outNumber++] = inst->BJTnVar[INNOIZ][i];
}
} /* if */
break;
} /* switch (mode) */
break;
case N_CLOSE:
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return(OK);
}
case N_CLOSE:
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return (OK);
}

View File

@ -12,23 +12,22 @@ Modified by Dietmar Warning 2003
#include "ngspice/suffix.h"
/*
* DIOnoise (mode, operation, firstModel, ckt, data, OnDens)
* This routine names and evaluates all of the noise sources
* associated with diodes. It starts with the model *firstModel and
* traverses all of its instancess. It then proceeds to any other
* models on the linked list. The total output noise density
* generated by all of the diodes is summed with the variable
* "OnDens".
*DIOnoise (mode, operation, firstModel, ckt, data, OnDens)
* This routine names and evaluates all of the noise sources
* associated with diodes. It starts with the model *firstModel and
* traverses all of its instancess. It then proceeds to any other
* models on the linked list. The total output noise density
* generated by all of the diodes is summed with the variable
* "OnDens".
*/
int
DIOnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
Ndata *data, double *OnDens)
DIOnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
Ndata *data, double *OnDens)
{
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
DIOmodel *firstModel = (DIOmodel *) genmodel;
DIOmodel *firstModel = (DIOmodel*) genmodel;
DIOmodel *model;
DIOinstance *inst;
double tempOnoise;
@ -39,138 +38,141 @@ DIOnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
/* define the names of the noise sources */
static char *DIOnNames[DIONSRCS] = { /* Note that we have to keep the order */
"_rs", /* noise due to rs */ /* consistent with thestrchr definitions */
"_id", /* noise due to id */ /* in DIOdefs.h */
"_1overf", /* flicker (1/f) noise */
"" /* total diode noise */
static char *DIOnNames[DIONSRCS] = {
/* Note that we have to keep the order
consistent with thestrchr definitions in DIOdefs.h */
"_rs", /* noise due to rs */
"_id", /* noise due to id */
"_1overf", /* flicker (1/f) noise */
"" /* total diode noise */
};
for (model=firstModel; model != NULL; model=DIOnextModel(model)) {
for (inst=DIOinstances(model); inst != NULL; inst=DIOnextInstance(inst)) {
for (model = firstModel; model != NULL; model = DIOnextModel(model)) {
for (inst = DIOinstances(model); inst != NULL; inst = DIOnextInstance(inst)) {
switch (operation) {
switch (operation) {
case N_OPEN:
case N_OPEN:
/* see if we have to to produce a summary report */
/* if so, name all the noise generators */
/* see if we have to to produce a summary report */
/* if so, name all the noise generators */
if (job->NStpsSm != 0) {
switch (mode) {
if (job->NStpsSm != 0) {
switch (mode) {
case N_DENS:
for (i=0; i < DIONSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->DIOname, DIOnNames[i]);
}
break;
case N_DENS:
for (i = 0; i < DIONSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->DIOname, DIOnNames[i]);
}
break;
case INT_NOIZ:
for (i=0; i < DIONSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->DIOname, DIOnNames[i]);
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->DIOname, DIOnNames[i]);
}
break;
}
}
break;
case INT_NOIZ:
for (i = 0; i < DIONSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->DIOname, DIOnNames[i]);
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->DIOname, DIOnNames[i]);
}
break;
}
}
break;
case N_CALC:
switch (mode) {
case N_CALC:
switch (mode) {
case N_DENS:
NevalSrc(&noizDens[DIORSNOIZ],&lnNdens[DIORSNOIZ],
ckt,THERMNOISE,inst->DIOposPrimeNode,inst->DIOposNode,
inst->DIOtConductance * inst->DIOarea * inst->DIOm);
NevalSrc(&noizDens[DIOIDNOIZ],&lnNdens[DIOIDNOIZ],
ckt,SHOTNOISE,inst->DIOposPrimeNode, inst->DIOnegNode,
*(ckt->CKTstate0 + inst->DIOcurrent));
case N_DENS:
NevalSrc(&noizDens[DIORSNOIZ],&lnNdens[DIORSNOIZ],
ckt, THERMNOISE, inst->DIOposPrimeNode, inst->DIOposNode,
inst->DIOtConductance * inst->DIOarea * inst->DIOm);
NevalSrc(&noizDens[DIOIDNOIZ],&lnNdens[DIOIDNOIZ],
ckt, SHOTNOISE, inst->DIOposPrimeNode, inst->DIOnegNode,
*(ckt->CKTstate0 + inst->DIOcurrent));
NevalSrc(&noizDens[DIOFLNOIZ], NULL, ckt,
N_GAIN,inst->DIOposPrimeNode, inst->DIOnegNode,
(double)0.0);
noizDens[DIOFLNOIZ] *= model->DIOfNcoef *
exp(model->DIOfNexp *
log(MAX(fabs(*(ckt->CKTstate0 + inst->DIOcurrent)/inst->DIOm),N_MINLOG))) /
data->freq * inst->DIOm;
lnNdens[DIOFLNOIZ] =
log(MAX(noizDens[DIOFLNOIZ],N_MINLOG));
NevalSrc(&noizDens[DIOFLNOIZ], NULL, ckt,
N_GAIN, inst->DIOposPrimeNode, inst->DIOnegNode,
(double) 0.0);
noizDens[DIOFLNOIZ] *= model->DIOfNcoef *
exp(model->DIOfNexp *
log(MAX(fabs(*(ckt->CKTstate0 + inst->DIOcurrent) / inst->DIOm), N_MINLOG))) /
data->freq * inst->DIOm;
lnNdens[DIOFLNOIZ] =
log(MAX(noizDens[DIOFLNOIZ], N_MINLOG));
noizDens[DIOTOTNOIZ] = noizDens[DIORSNOIZ] +
noizDens[DIOIDNOIZ] +
noizDens[DIOFLNOIZ];
lnNdens[DIOTOTNOIZ] =
log(MAX(noizDens[DIOTOTNOIZ], N_MINLOG));
noizDens[DIOTOTNOIZ] = noizDens[DIORSNOIZ] +
noizDens[DIOIDNOIZ] +
noizDens[DIOFLNOIZ];
lnNdens[DIOTOTNOIZ] =
log(MAX(noizDens[DIOTOTNOIZ], N_MINLOG));
*OnDens += noizDens[DIOTOTNOIZ];
*OnDens += noizDens[DIOTOTNOIZ];
if (data->delFreq == 0.0) {
if (data->delFreq == 0.0) {
/* if we haven't done any previous integration, we need to */
/* initialize our "history" variables */
/* if we haven't done any previous integration, we need to */
/* initialize our "history" variables */
for (i=0; i < DIONSRCS; i++) {
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
}
for (i = 0; i < DIONSRCS; i++) {
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
}
/* clear out our integration variables if it's the first pass */
/* clear out our integration variables if it's the first pass */
if (data->freq == job->NstartFreq) {
for (i=0; i < DIONSRCS; i++) {
inst->DIOnVar[OUTNOIZ][i] = 0.0;
inst->DIOnVar[INNOIZ][i] = 0.0;
}
}
} else { /* data->delFreq != 0.0 (we have to integrate) */
if (data->freq == job->NstartFreq) {
for (i = 0; i < DIONSRCS; i++) {
inst->DIOnVar[OUTNOIZ][i] = 0.0;
inst->DIOnVar[INNOIZ][i] = 0.0;
}
}
} else {
/* data->delFreq != 0.0 (we have to integrate) */
/* To insure accurracy, we have to integrate each component separately */
/* To insure accurracy, we have to integrate each component separately */
for (i=0; i < DIONSRCS; i++) {
if (i != DIOTOTNOIZ) {
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
inst->DIOnVar[LNLSTDENS][i], data);
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv ,
lnNdens[i] + data->lnGainInv,
inst->DIOnVar[LNLSTDENS][i] + data->lnGainInv,
data);
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOnoise;
data->inNoise += tempInoise;
if (job->NStpsSm != 0) {
inst->DIOnVar[OUTNOIZ][i] += tempOnoise;
inst->DIOnVar[OUTNOIZ][DIOTOTNOIZ] += tempOnoise;
inst->DIOnVar[INNOIZ][i] += tempInoise;
inst->DIOnVar[INNOIZ][DIOTOTNOIZ] += tempInoise;
for (i = 0; i < DIONSRCS; i++) {
if (i != DIOTOTNOIZ) {
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
inst->DIOnVar[LNLSTDENS][i], data);
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv,
lnNdens[i] + data->lnGainInv,
inst->DIOnVar[LNLSTDENS][i] + data->lnGainInv,
data);
inst->DIOnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOnoise;
data->inNoise += tempInoise;
if (job->NStpsSm != 0) {
inst->DIOnVar[OUTNOIZ][i] += tempOnoise;
inst->DIOnVar[OUTNOIZ][DIOTOTNOIZ] += tempOnoise;
inst->DIOnVar[INNOIZ][i] += tempInoise;
inst->DIOnVar[INNOIZ][DIOTOTNOIZ] += tempInoise;
}
}
}
}
if (data->prtSummary) {
for (i=0; i < DIONSRCS; i++) { /* print a summary report */
data->outpVector[data->outNumber++] = noizDens[i];
}
}
break;
}
}
}
if (data->prtSummary) {
for (i = 0; i < DIONSRCS; i++) {
/* print a summary report */
data->outpVector[data->outNumber++] = noizDens[i];
}
}
break;
case INT_NOIZ: /* already calculated, just output */
if (job->NStpsSm != 0) {
for (i=0; i < DIONSRCS; i++) {
data->outpVector[data->outNumber++] = inst->DIOnVar[OUTNOIZ][i];
data->outpVector[data->outNumber++] = inst->DIOnVar[INNOIZ][i];
}
} /* if */
break;
} /* switch (mode) */
break;
case INT_NOIZ:
/* already calculated, just output */
if (job->NStpsSm != 0) {
for (i = 0; i < DIONSRCS; i++) {
data->outpVector[data->outNumber++] = inst->DIOnVar[OUTNOIZ][i];
data->outpVector[data->outNumber++] = inst->DIOnVar[INNOIZ][i];
}
} /* if */
break;
} /* switch (mode) */
break;
case N_CLOSE:
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return(OK);
}
case N_CLOSE:
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return (OK);
}

View File

@ -11,22 +11,21 @@ Author: 1987 Gary W. Ng
#include "ngspice/suffix.h"
/*
* JFETnoise (mode, operation, firstModel, ckt, data, OnDens)
* This routine names and evaluates all of the noise sources
* associated with JFET's. It starts with the model *firstModel and
* traverses all of its insts. It then proceeds to any other models
* on the linked list. The total output noise density generated by
* all of the JFET's is summed with the variable "OnDens".
*JFETnoise (mode, operation, firstModel, ckt, data, OnDens)
* This routine names and evaluates all of the noise sources
* associated with JFET's. It starts with the model *firstModel and
* traverses all of its insts. It then proceeds to any other models
* on the linked list. The total output noise density generated by
* all of the JFET's is summed with the variable "OnDens".
*/
int
JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *data,
double *OnDens)
JFETnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *data,
double *OnDens)
{
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
JFETmodel *firstModel = (JFETmodel *) genmodel;
JFETmodel *firstModel = (JFETmodel*) genmodel;
JFETmodel *model;
JFETinstance *inst;
double tempOnoise;
@ -38,16 +37,18 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
/* define the names of the noise sources */
static char *JFETnNames[JFETNSRCS] = { /* Note that we have to keep the order */
"_rd", /* noise due to rd */ /* consistent with thestrchr definitions */
"_rs", /* noise due to rs */ /* in JFETdefs.h */
"_id", /* noise due to id */
"_1overf", /* flicker (1/f) noise */
"" /* total transistor noise */
static char *JFETnNames[JFETNSRCS] = {
/* Note that we have to keep the order
consistent with the strchr definitions in JFETdefs.h */
"_rd", /* noise due to rd */
"_rs", /* noise due to rs */
"_id", /* noise due to id */
"_1overf", /* flicker (1/f) noise */
"" /* total transistor noise */
};
for (model=firstModel; model != NULL; model=JFETnextModel(model)) {
for (inst=JFETinstances(model); inst != NULL; inst=JFETnextInstance(inst)) {
for (model = firstModel; model != NULL; model = JFETnextModel(model)) {
for (inst = JFETinstances(model); inst != NULL; inst = JFETnextInstance(inst)) {
switch (operation) {
@ -60,13 +61,13 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
switch (mode) {
case N_DENS:
for (i=0; i < JFETNSRCS; i++) {
for (i = 0; i < JFETNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->JFETname, JFETnNames[i]);
}
break;
case INT_NOIZ:
for (i=0; i < JFETNSRCS; i++) {
for (i = 0; i < JFETNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->JFETname, JFETnNames[i]);
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->JFETname, JFETnNames[i]);
}
@ -80,80 +81,81 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
case N_DENS:
NevalSrc(&noizDens[JFETRDNOIZ],&lnNdens[JFETRDNOIZ],
ckt,THERMNOISE,inst->JFETdrainPrimeNode,inst->JFETdrainNode,
model->JFETdrainConduct * inst->JFETarea * inst->JFETm);
ckt, THERMNOISE, inst->JFETdrainPrimeNode, inst->JFETdrainNode,
model->JFETdrainConduct * inst->JFETarea * inst->JFETm);
NevalSrc(&noizDens[JFETRSNOIZ],&lnNdens[JFETRSNOIZ],
ckt,THERMNOISE,inst->JFETsourcePrimeNode,
inst->JFETsourceNode,model->JFETsourceConduct
* inst->JFETarea * inst->JFETm);
ckt, THERMNOISE, inst->JFETsourcePrimeNode,
inst->JFETsourceNode, model->JFETsourceConduct *
inst->JFETarea * inst->JFETm);
if (model->JFETnlev < 3) {
NevalSrc(&noizDens[JFETIDNOIZ],&lnNdens[JFETIDNOIZ],
ckt,THERMNOISE,inst->JFETdrainPrimeNode,
inst->JFETsourcePrimeNode,
(2.0/3.0 * inst->JFETm * fabs(*(ckt->CKTstate0 + inst->JFETgm))));
ckt, THERMNOISE, inst->JFETdrainPrimeNode,
inst->JFETsourcePrimeNode,
(2.0 / 3.0 * inst->JFETm * fabs(*(ckt->CKTstate0 + inst->JFETgm))));
} else {
vgs = *(ckt->CKTstate0 + inst->JFETvgs);
vds = vgs - *(ckt->CKTstate0 + inst->JFETvgd);
vgst = vgs - inst->JFETtThreshold;
if (vgst >= vds)
alpha = 1 - vds/vgst; /* linear region */
alpha = 1 - vds / vgst; /* linear region */
else
alpha = 0; /* saturation region */
alpha = 0; /* saturation region */
beta = inst->JFETtBeta * inst->JFETarea * inst->JFETm;
NevalSrc(&noizDens[JFETIDNOIZ],&lnNdens[JFETIDNOIZ],
ckt,THERMNOISE,inst->JFETdrainPrimeNode,
inst->JFETsourcePrimeNode,
(2.0/3.0 * beta*vgst*(1+alpha+alpha*alpha)/(1+alpha)*model->JFETgdsnoi));
ckt, THERMNOISE, inst->JFETdrainPrimeNode,
inst->JFETsourcePrimeNode,
(2.0 / 3.0*beta*vgst*(1 + alpha + alpha*alpha) / (1 + alpha) * model->JFETgdsnoi));
}
NevalSrc(&noizDens[JFETFLNOIZ], NULL, ckt,
N_GAIN,inst->JFETdrainPrimeNode,
inst->JFETsourcePrimeNode, (double)0.0);
noizDens[JFETFLNOIZ] *= inst->JFETm * model->JFETfNcoef *
exp(model->JFETfNexp *
log(MAX(fabs(*(ckt->CKTstate0 + inst->JFETcd)),N_MINLOG))) /
data->freq;
N_GAIN, inst->JFETdrainPrimeNode,
inst->JFETsourcePrimeNode, (double) 0.0);
noizDens[JFETFLNOIZ] *= inst->JFETm*model->JFETfNcoef *
exp(model->JFETfNexp *
log(MAX(fabs(*(ckt->CKTstate0 + inst->JFETcd)), N_MINLOG))) /
data->freq;
lnNdens[JFETFLNOIZ] =
log(MAX(noizDens[JFETFLNOIZ],N_MINLOG));
log(MAX(noizDens[JFETFLNOIZ], N_MINLOG));
noizDens[JFETTOTNOIZ] = noizDens[JFETRDNOIZ] +
noizDens[JFETRSNOIZ] +
noizDens[JFETIDNOIZ] +
noizDens[JFETFLNOIZ];
noizDens[JFETRSNOIZ] +
noizDens[JFETIDNOIZ] +
noizDens[JFETFLNOIZ];
lnNdens[JFETTOTNOIZ] =
log(MAX(noizDens[JFETTOTNOIZ], N_MINLOG));
log(MAX(noizDens[JFETTOTNOIZ], N_MINLOG));
*OnDens += noizDens[JFETTOTNOIZ];
*OnDens += noizDens[JFETTOTNOIZ];
if (data->delFreq == 0.0) {
/* if we haven't done any previous integration, we need to */
/* initialize our "history" variables */
for (i=0; i < JFETNSRCS; i++) {
for (i = 0; i < JFETNSRCS; i++) {
inst->JFETnVar[LNLSTDENS][i] = lnNdens[i];
}
/* clear out our integration variables if it's the first pass */
if (data->freq == job->NstartFreq) {
for (i=0; i < JFETNSRCS; i++) {
for (i = 0; i < JFETNSRCS; i++) {
inst->JFETnVar[OUTNOIZ][i] = 0.0;
inst->JFETnVar[INNOIZ][i] = 0.0;
}
}
} else { /* data->delFreq != 0.0 (we have to integrate) */
for (i=0; i < JFETNSRCS; i++) {
} else {
/* data->delFreq != 0.0 (we have to integrate) */
for (i = 0; i < JFETNSRCS; i++) {
if (i != JFETTOTNOIZ) {
tempOnoise = Nintegrate(noizDens[i], lnNdens[i],
inst->JFETnVar[LNLSTDENS][i], data);
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv ,
lnNdens[i] + data->lnGainInv,
inst->JFETnVar[LNLSTDENS][i] + data->lnGainInv,
data);
inst->JFETnVar[LNLSTDENS][i], data);
tempInoise = Nintegrate(noizDens[i] * data->GainSqInv,
lnNdens[i] + data->lnGainInv,
inst->JFETnVar[LNLSTDENS][i] + data->lnGainInv,
data);
inst->JFETnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOnoise;
data->inNoise += tempInoise;
@ -167,29 +169,31 @@ JFETnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *
}
}
if (data->prtSummary) {
for (i=0; i < JFETNSRCS; i++) { /* print a summary report */
for (i = 0; i < JFETNSRCS; i++) {
/* print a summary report */
data->outpVector[data->outNumber++] = noizDens[i];
}
}
break;
case INT_NOIZ: /* already calculated, just output */
case INT_NOIZ:
/* already calculated, just output */
if (job->NStpsSm != 0) {
for (i=0; i < JFETNSRCS; i++) {
for (i = 0; i < JFETNSRCS; i++) {
data->outpVector[data->outNumber++] = inst->JFETnVar[OUTNOIZ][i];
data->outpVector[data->outNumber++] = inst->JFETnVar[INNOIZ][i];
}
} /* if */
} /* if */
break;
} /* switch (mode) */
} /* switch (mode) */
break;
case N_CLOSE:
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return(OK);
}
return (OK);
}

View File

@ -11,28 +11,27 @@ Modified: Apr 2000 - Paolo Nenzi
#include "ngspice/noisedef.h"
/*
* RESnoise (mode, operation, firstModel, ckt, data, OnDens)
* This routine names and evaluates all of the noise sources
* associated with resistors. It starts with the model *firstModel
* and traverses all of its instances. It then proceeds to any other
* models on the linked list. The total output noise density
* generated by all the resistors is summed in the variable "OnDens".
*RESnoise (mode, operation, firstModel, ckt, data, OnDens)
* This routine names and evaluates all of the noise sources
* associated with resistors. It starts with the model *firstModel
* and traverses all of its instances. It then proceeds to any other
* models on the linked list. The total output noise density
* generated by all the resistors is summed in the variable "OnDens".
*
* Paolo Nenzi 2003:
* Added flicker noise (Kf-Af) calculation to simulate
* carbon resistors.
*Paolo Nenzi 2003:
* Added flicker noise (Kf-Af) calculation to simulate
* carbon resistors.
*
* Added "noisy" switch to simulate noiseless resistors.
* Added "noisy" switch to simulate noiseless resistors.
*/
int
RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
Ndata *data, double *OnDens)
RESnoise(int mode, int operation, GENmodel*genmodel, CKTcircuit *ckt,
Ndata *data, double *OnDens)
{
NOISEAN *job = (NOISEAN *) ckt->CKTcurJob;
NOISEAN *job = (NOISEAN*) ckt->CKTcurJob;
RESmodel *firstModel = (RESmodel *) genmodel;
RESmodel *firstModel = (RESmodel*) genmodel;
RESmodel *model;
RESinstance *inst;
double tempOutNoise;
@ -41,23 +40,21 @@ RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
double lnNdens[RESNSRCS];
int i;
/* define the names of the noise sources */
/* define the names of the noise sources */
static char *RESnNames[RESNSRCS] = {
/* Note that we have to keep the order consistent with the
* strchr definitions in RESdefs.h */
"_thermal", /* Thermal noise */
"_1overf", /* flicker (1/f) noise */
"" /* total resistor noise */
strchr definitions in RESdefs.h */
"_thermal", /* Thermal noise */
"_1overf", /* flicker (1/f) noise */
"" /* total resistor noise */
};
for (model = firstModel; model != NULL; model = RESnextModel(model)) {
for (inst = RESinstances(model); inst != NULL;
inst = RESnextInstance(inst)) {
for (inst = RESinstances(model); inst != NULL; inst = RESnextInstance(inst)) {
if (!inst->RESnoisy) continue; /* Quiet resistors are skipped */
if(!inst->RESnoisy) continue; /* Quiet resistors are skipped */
switch (operation) {
case N_OPEN:
@ -71,13 +68,13 @@ RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
switch (mode) {
case N_DENS:
for (i=0; i < RESNSRCS; i++) {
for (i = 0; i < RESNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_%s%s", inst->RESname, RESnNames[i]);
}
break;
case INT_NOIZ:
for (i=0; i < RESNSRCS; i++) {
for (i = 0; i < RESNSRCS; i++) {
NOISE_ADD_OUTVAR(ckt, data, "onoise_total_%s%s", inst->RESname, RESnNames[i]);
NOISE_ADD_OUTVAR(ckt, data, "inoise_total_%s%s", inst->RESname, RESnNames[i]);
}
@ -90,99 +87,100 @@ RESnoise (int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt,
switch (mode) {
case N_DENS:
NevalSrcInstanceTemp(&noizDens[RESTHNOIZ],&lnNdens[RESTHNOIZ],
ckt,THERMNOISE, inst->RESposNode,inst->RESnegNode,
inst->RESconduct, inst->RESdtemp);
NevalSrcInstanceTemp(&noizDens[RESFLNOIZ], NULL, ckt,
N_GAIN,inst->RESposNode, inst->RESnegNode,
(double)0.0, (double)0.0);
#if 0
printf("DC current in resistor %s: %e\n",inst->RESname, inst->REScurrent);
#endif
noizDens[RESFLNOIZ] *= inst->RESm * model->RESfNcoef *
pow(fabs(inst->REScurrent / inst->RESm), model->RESfNexp)
/ (inst->RESeffNoiseArea * pow(data->freq, model->RESef));
lnNdens[RESFLNOIZ] = log(MAX(noizDens[RESFLNOIZ],N_MINLOG));
NevalSrcInstanceTemp(&noizDens[RESTHNOIZ],&lnNdens[RESTHNOIZ],
ckt, THERMNOISE, inst->RESposNode, inst->RESnegNode,
inst->RESconduct, inst->RESdtemp);
noizDens[RESTOTNOIZ] = noizDens[RESTHNOIZ] + noizDens[RESFLNOIZ];
lnNdens[RESTOTNOIZ] = log(noizDens[RESTOTNOIZ]);
NevalSrcInstanceTemp(&noizDens[RESFLNOIZ], NULL, ckt,
N_GAIN, inst->RESposNode, inst->RESnegNode,
(double) 0.0, (double) 0.0);
*OnDens += noizDens[RESTOTNOIZ];
#if 0
printf("DC current in resistor %s: %e\n", inst->RESname, inst->REScurrent);
#endif
if (data->delFreq == 0.0) {
noizDens[RESFLNOIZ] *= inst->RESm * model->RESfNcoef *
pow(fabs(inst->REScurrent / inst->RESm), model->RESfNexp) /
(inst->RESeffNoiseArea * pow(data->freq, model->RESef));
lnNdens[RESFLNOIZ] = log(MAX(noizDens[RESFLNOIZ], N_MINLOG));
noizDens[RESTOTNOIZ] = noizDens[RESTHNOIZ] + noizDens[RESFLNOIZ];
lnNdens[RESTOTNOIZ] = log(noizDens[RESTOTNOIZ]);
*OnDens += noizDens[RESTOTNOIZ];
if (data->delFreq == 0.0) {
/* if we haven't done any previous integration, we need to */
/* initialize our "history" variables */
for (i=0; i < RESNSRCS; i++) {
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
for (i = 0; i < RESNSRCS; i++) {
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
}
/* clear out our integration variable if it's the first pass */
if (data->freq == job->NstartFreq) {
for (i=0; i < RESNSRCS; i++) {
inst->RESnVar[OUTNOIZ][i] = 0.0; /* Clear output noise */
inst->RESnVar[INNOIZ][i] = 0.0; /* Clear input noise */
for (i = 0; i < RESNSRCS; i++) {
inst->RESnVar[OUTNOIZ][i] = 0.0; /* Clear output noise */
inst->RESnVar[INNOIZ][i] = 0.0; /* Clear input noise */
}
}
} else { /* data->delFreq != 0.0 (we have to integrate) */
/* In order to get the best curve fit, we have to integrate each component separately */
} else {
/* data->delFreq != 0.0 (we have to integrate) */
for (i = 0; i < RESNSRCS; i++) {
if (i != RESTOTNOIZ) {
tempOutNoise = Nintegrate(noizDens[i], lnNdens[i],
inst->RESnVar[LNLSTDENS][i], data);
tempInNoise = Nintegrate(noizDens[i] *
data->GainSqInv ,lnNdens[i]
+ data->lnGainInv,
inst->RESnVar[LNLSTDENS][i]
+ data->lnGainInv,
data);
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOutNoise;
data->inNoise += tempInNoise;
if (job->NStpsSm != 0) {
inst->RESnVar[OUTNOIZ][i] += tempOutNoise;
inst->RESnVar[OUTNOIZ][RESTOTNOIZ] += tempOutNoise;
inst->RESnVar[INNOIZ][i] += tempInNoise;
inst->RESnVar[INNOIZ][RESTOTNOIZ] += tempInNoise;
/* In order to get the best curve fit, we have to integrate each component separately */
for (i = 0; i < RESNSRCS; i++) {
if (i != RESTOTNOIZ) {
tempOutNoise = Nintegrate(noizDens[i], lnNdens[i],
inst->RESnVar[LNLSTDENS][i], data);
tempInNoise = Nintegrate(noizDens[i] *
data->GainSqInv, lnNdens[i] +
data->lnGainInv,
inst->RESnVar[LNLSTDENS][i] +
data->lnGainInv,
data);
inst->RESnVar[LNLSTDENS][i] = lnNdens[i];
data->outNoiz += tempOutNoise;
data->inNoise += tempInNoise;
if (job->NStpsSm != 0) {
inst->RESnVar[OUTNOIZ][i] += tempOutNoise;
inst->RESnVar[OUTNOIZ][RESTOTNOIZ] += tempOutNoise;
inst->RESnVar[INNOIZ][i] += tempInNoise;
inst->RESnVar[INNOIZ][RESTOTNOIZ] += tempInNoise;
}
}
}
}
}
}
if (data->prtSummary) {
for (i=0; i < RESNSRCS; i++) { /* print a summary report */
for (i = 0; i < RESNSRCS; i++) {
/* print a summary report */
data->outpVector[data->outNumber++] = noizDens[i];
}
}
break;
case INT_NOIZ: /* already calculated, just output */
case INT_NOIZ:
/* already calculated, just output */
if (job->NStpsSm != 0) {
for (i=0; i < RESNSRCS; i++) {
for (i = 0; i < RESNSRCS; i++) {
data->outpVector[data->outNumber++] = inst->RESnVar[OUTNOIZ][i];
data->outpVector[data->outNumber++] = inst->RESnVar[INNOIZ][i];
}
} /* if */
} /* if */
break;
} /* switch (mode) */
} /* switch (mode) */
break;
case N_CLOSE:
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return(OK);
}
return (OK); /* do nothing, the main calling routine will close */
break; /* the plots */
} /* switch (operation) */
} /* for inst */
} /* for model */
return (OK);
}