From 7d92eae124bd6673224d67441503528fd66cae46 Mon Sep 17 00:00:00 2001 From: rlar Date: Mon, 23 Mar 2015 19:32:33 +0100 Subject: [PATCH] noisean, introduce a .control variable "sqrnoise" to deliver noise data in squared representation use "set srqrnoise" (and "unset sqrnoise") to control this. --- src/frontend/typesdef.c | 4 +++ src/include/ngspice/noisedef.h | 1 + src/include/ngspice/sim.h | 4 +++ src/spicelib/analysis/cktnoise.c | 18 ++++++------ src/spicelib/analysis/noisean.c | 49 ++++++++++++++++++++++---------- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/frontend/typesdef.c b/src/frontend/typesdef.c index 401556d5a..71584e719 100644 --- a/src/frontend/typesdef.c +++ b/src/frontend/typesdef.c @@ -39,6 +39,10 @@ static struct type types[NUMTYPES] = { { "current", "A" } , { "voltage-density", "V/sqrt(Hz)" } , { "current-density", "A/sqrt(Hz)" } , + { "voltage^2-density", "(V^2)/Hz" } , + { "current^2-density", "(A^2)/Hz" } , + { "voltage^2", "(V^2)" } , + { "current^2", "(A^2)" } , { "pole", NULL } , { "zero", NULL } , { "s-param", NULL } , diff --git a/src/include/ngspice/noisedef.h b/src/include/ngspice/noisedef.h index 61ffbbbe9..182786073 100644 --- a/src/include/ngspice/noisedef.h +++ b/src/include/ngspice/noisedef.h @@ -52,6 +52,7 @@ typedef struct { char *squared_value; runDesc *NplotPtr; /* the plot pointer */ IFuid *namelist; /* list of plot names */ + unsigned squared : 1; } Ndata; diff --git a/src/include/ngspice/sim.h b/src/include/ngspice/sim.h index 3f65f76d0..e02919701 100644 --- a/src/include/ngspice/sim.h +++ b/src/include/ngspice/sim.h @@ -9,6 +9,10 @@ enum simulation_types { SV_CURRENT, SV_VOLTAGE_DENSITY, SV_CURRENT_DENSITY, + SV_SQR_VOLTAGE_DENSITY, + SV_SQR_CURRENT_DENSITY, + SV_SQR_VOLTAGE, + SV_SQR_CURRENT, SV_POLE, SV_ZERO, SV_SPARAM, diff --git a/src/spicelib/analysis/cktnoise.c b/src/spicelib/analysis/cktnoise.c index ff161af34..690ccd6d5 100644 --- a/src/spicelib/analysis/cktnoise.c +++ b/src/spicelib/analysis/cktnoise.c @@ -68,7 +68,7 @@ CKTnoise (CKTcircuit *ckt, int mode, int operation, Ndata *data) data->outpVector = TMALLOC(double, data->numPlots); data->squared_value = - TMALLOC(char, data->numPlots); + data->squared ? NULL : TMALLOC(char, data->numPlots); break; case INT_NOIZ: @@ -85,7 +85,7 @@ CKTnoise (CKTcircuit *ckt, int mode, int operation, Ndata *data) data->outpVector = TMALLOC(double, data->numPlots); data->squared_value = - TMALLOC(char, data->numPlots); + data->squared ? NULL : TMALLOC(char, data->numPlots); break; default: @@ -107,9 +107,10 @@ CKTnoise (CKTcircuit *ckt, int mode, int operation, Ndata *data) (outNdens * data->GainSqInv); refVal.rValue = data->freq; /* the reference is the freq */ - for (i = 0; i < data->outNumber; i++) - if (data->squared_value[i]) - data->outpVector[i] = sqrt(data->outpVector[i]); + if (!data->squared) + for (i = 0; i < data->outNumber; i++) + if (data->squared_value[i]) + data->outpVector[i] = sqrt(data->outpVector[i]); outData.v.numValue = data->outNumber; /* vector number */ outData.v.vec.rVec = data->outpVector; /* vector of outputs */ SPfrontEnd->OUTpData (data->NplotPtr, &refVal, &outData); @@ -119,9 +120,10 @@ CKTnoise (CKTcircuit *ckt, int mode, int operation, Ndata *data) case INT_NOIZ: data->outpVector[data->outNumber++] = data->outNoiz; data->outpVector[data->outNumber++] = data->inNoise; - for (i = 0; i < data->outNumber; i++) - if (data->squared_value[i]) - data->outpVector[i] = sqrt(data->outpVector[i]); + if (!data->squared) + for (i = 0; i < data->outNumber; i++) + if (data->squared_value[i]) + data->outpVector[i] = sqrt(data->outpVector[i]); outData.v.vec.rVec = data->outpVector; /* vector of outputs */ outData.v.numValue = data->outNumber; /* vector number */ SPfrontEnd->OUTpData (data->NplotPtr, &refVal, &outData); diff --git a/src/spicelib/analysis/noisean.c b/src/spicelib/analysis/noisean.c index 2be3f2467..cce09b792 100644 --- a/src/spicelib/analysis/noisean.c +++ b/src/spicelib/analysis/noisean.c @@ -14,6 +14,7 @@ Modified: 2001 AlansFixes #include "ngspice/acdefs.h" #include "ngspice/cktdefs.h" #include "ngspice/iferrmsg.h" +#include "ngspice/cpextern.h" #include "ngspice/noisedef.h" #include "ngspice/sperror.h" #include "ngspice/sim.h" @@ -122,6 +123,7 @@ NOISEan (CKTcircuit *ckt, int restart) data->freq = job->NstartFreq; data->outNoiz = 0.0; data->inNoise = 0.0; + data->squared = cp_getvar("sqrnoise", CP_BOOL, NULL) ? 1 : 0; /* the current front-end needs the namelist to be fully declared before an OUTpBeginplot */ @@ -138,19 +140,26 @@ NOISEan (CKTcircuit *ckt, int restart) */ if (src_type == SV_VOLTAGE) - fixme_inoise_type = SV_VOLTAGE_DENSITY; + fixme_inoise_type = + data->squared ? SV_SQR_VOLTAGE_DENSITY : SV_VOLTAGE_DENSITY; else - fixme_inoise_type = SV_CURRENT_DENSITY; + fixme_inoise_type = + data->squared ? SV_SQR_CURRENT_DENSITY : SV_CURRENT_DENSITY; - fixme_onoise_type = SV_VOLTAGE_DENSITY; + fixme_onoise_type = + data->squared ? SV_SQR_VOLTAGE_DENSITY : SV_VOLTAGE_DENSITY; - for (i = 0; i < data->numPlots; i++) - data->squared_value[i] = - ciprefix("inoise", data->namelist[i]) || - ciprefix("onoise", data->namelist[i]); + if (!data->squared) + for (i = 0; i < data->numPlots; i++) + data->squared_value[i] = + ciprefix("inoise", data->namelist[i]) || + ciprefix("onoise", data->namelist[i]); error = SPfrontEnd->OUTpBeginPlot (ckt, ckt->CKTcurJob, - "Noise Spectral Density Curves", + data->squared + ? "Noise Spectral Density Curves - (V^2 or A^2)/Hz" + + : "Noise Spectral Density Curves", freqUid, IF_REAL, data->numPlots, data->namelist, IF_REAL, &(data->NplotPtr)); @@ -296,16 +305,26 @@ NOISEan (CKTcircuit *ckt, int restart) if (error) return(error); - fixme_inoise_type = src_type; - fixme_onoise_type = SV_VOLTAGE; + if (src_type == SV_VOLTAGE) + fixme_inoise_type = + data->squared ? SV_SQR_VOLTAGE : SV_VOLTAGE; + else + fixme_inoise_type = + data->squared ? SV_SQR_CURRENT : SV_CURRENT; - for (i = 0; i < data->numPlots; i++) - data->squared_value[i] = - ciprefix("inoise", data->namelist[i]) || - ciprefix("onoise", data->namelist[i]); + fixme_onoise_type = + data->squared ? SV_SQR_VOLTAGE : SV_VOLTAGE; + + if (!data->squared) + for (i = 0; i < data->numPlots; i++) + data->squared_value[i] = + ciprefix("inoise", data->namelist[i]) || + ciprefix("onoise", data->namelist[i]); SPfrontEnd->OUTpBeginPlot (ckt, ckt->CKTcurJob, - "Integrated Noise", + data->squared + ? "Integrated Noise - V^2 or A^2" + : "Integrated Noise", NULL, 0, data->numPlots, data->namelist, IF_REAL, &(data->NplotPtr));