Browse Source

vsrc trrandom option

pre-master-46
h_vogt 15 years ago
parent
commit
c162d3273f
  1. 7
      ChangeLog
  2. 87
      examples/Monte_Carlo/OpWien.sp
  3. 175
      src/frontend/com_cdump.c
  4. 17
      src/frontend/trannoise/1-f-code.c
  5. 52
      src/include/1-f-code.h
  6. 3
      src/spicelib/devices/vsrc/vsrc.c
  7. 423
      src/spicelib/devices/vsrc/vsrcacct.c
  8. 5
      src/spicelib/devices/vsrc/vsrcdefs.h
  9. 84
      src/spicelib/devices/vsrc/vsrcload.c
  10. 198
      src/spicelib/devices/vsrc/vsrcpar.c

7
ChangeLog

@ -1,3 +1,10 @@
11-01-16 Holger Vogt
* com_cdump.c: remove compiler warnings
* 1-f-code.c, 1-f-code.h, vsrc.c, vsrcacct.c, vsrcdefs.h,
vsrcload.c, vsrcpar.c, examples/opwien.sp:
Add new random voltage generator option trrandom to vsrc
voltage source
2011-01-15 Robert Larice 2011-01-15 Robert Larice
* src/frontend/trannoise/Makefile.am , * src/frontend/trannoise/Makefile.am ,
* src/include/Makefile.am , * src/include/Makefile.am ,

87
examples/Monte_Carlo/OpWien.sp

@ -0,0 +1,87 @@
OPWIEN.CIR - OPAMP WIEN-BRIDGE OSCILLATOR
* http://www.ecircuitcenter.com/circuits/opwien/opwien.htm
* single simulation run
* 2 resistors and 2 capacitors of Wien bridge a varied statistically
* number of variations: varia
* Simulation time
.param ttime=12000m
.param varia=100
.param ttime10 = 'ttime/varia'
* nominal resistor and capacitor values
.param res = 10k
.param cn = 16NF
* CURRENT PULSE TO START OSCILLATIONS
IS 0 3 dc 0 PWL(0US 0MA 10US 0.1MA 40US 0.1MA 50US 0MA 10MS 0MA)
*
* RC TUNING
VR2 r2 0 dc 0 trrandom (2 'ttime10' 0 1) $ Gauss controlling voltage
*
*VR2 r2 0 dc 0 trrandom (1 'ttime10' 0 3) $ Uniform within -3 3
*
* If Gauss, factor 0.033 is 10% equivalent to 3 sigma
* if uniform, uniform between +/- 10%
R2 4 6 R = 'res + 0.033 * res*V(r2)' $ behavioral resistor
*R2 4 6 'res' $ constant R
VC2 c2 0 dc 0 trrandom (2 'ttime10' 0 1)
*C2 6 3'cn' $ constant C
C2 6 3 C = 'cn + 0.033 * cn*V(c2)' $ behavioral capacitor
VR1 r1 0 dc 0 trrandom (2 'ttime10' 0 1)
*VR1 r1 0 dc 0 trrandom (1 'ttime10' 0 3)
R1 3 0 R = 'res + 0.033 * res*V(r1)'
*R1 3 0 'res'
VC1 c1 0 dc 0 trrandom (2 'ttime10' 0 1)
C1 3 0 C = 'cn + 0.033 * cn*V(c2)'
*C1 3 0 'cn'
* NON-INVERTING OPAMP
R10 0 2 10K
R11 2 5 18K
XOP 3 2 4 OPAMP1
* AMPLITUDE STABILIZATION
R12 5 4 5K
D1 5 4 D1N914
D2 4 5 D1N914
*
.model D1N914 D(Is=0.1p Rs=16 CJO=2p Tt=12n Bv=100 Ibv=0.4n)
*
* OPAMP MACRO MODEL, SINGLE-POLE
* connections: non-inverting input
* | inverting input
* | | output
* | | |
.SUBCKT OPAMP1 1 2 6
* INPUT IMPEDANCE
RIN 1 2 10MEG
* DC GAIN (100K) AND POLE 1 (100HZ)
EGAIN 3 0 1 2 100K
RP1 3 4 1K
CP1 4 0 1.5915UF
* OUTPUT BUFFER AND RESISTANCE
EBUFFER 5 0 4 0 1
ROUT 5 6 10
.ENDS
*
* ANALYSIS
.TRAN 0.05MS 'ttime'
*
* VIEW RESULTS
.control
option noinit
run
plot V(4) 5*V(r1) 5*V(r2) 5*V(c1) 5*V(c2)
linearize v(4)
fft v(4)
let v4mag = mag(v(4))
plot v4mag
plot v4mag xlimit 500 1500
*wrdata histo v4mag
rusage
.endc
.END

175
src/frontend/com_cdump.c

@ -19,7 +19,7 @@ tab(int num)
int i; int i;
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
putc(' ', cp_out);
putc(' ', cp_out);
} }
@ -30,103 +30,103 @@ dodump(struct control *cc)
switch (cc->co_type) { switch (cc->co_type) {
case CO_UNFILLED: case CO_UNFILLED:
tab(indent);
fprintf(cp_out, "(unfilled)\n");
break;
tab(indent);
fprintf(cp_out, "(unfilled)\n");
break;
case CO_STATEMENT: case CO_STATEMENT:
tab(indent);
wl_print(cc->co_text, cp_out);
putc('\n', cp_out);
break;
tab(indent);
wl_print(cc->co_text, cp_out);
putc('\n', cp_out);
break;
case CO_WHILE: case CO_WHILE:
tab(indent);
fprintf(cp_out, "while ");
wl_print(cc->co_cond, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
tab(indent);
fprintf(cp_out, "while ");
wl_print(cc->co_cond, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
case CO_REPEAT: case CO_REPEAT:
tab(indent);
fprintf(cp_out, "repeat ");
if (cc->co_numtimes != -1)
fprintf(cp_out, "%d (%d left to do)\n", cc->co_numtimes, cc->co_timestodo); /* CDHW */
else
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
tab(indent);
fprintf(cp_out, "repeat ");
if (cc->co_numtimes != -1)
fprintf(cp_out, "%d (%d left to do)\n", cc->co_numtimes, cc->co_timestodo); /* CDHW */
else
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
case CO_DOWHILE: case CO_DOWHILE:
tab(indent);
fprintf(cp_out, "dowhile ");
wl_print(cc->co_cond, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
tab(indent);
fprintf(cp_out, "dowhile ");
wl_print(cc->co_cond, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
case CO_IF: case CO_IF:
tab(indent);
fprintf(cp_out, "if ");
wl_print(cc->co_cond, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
tab(indent);
fprintf(cp_out, "if ");
wl_print(cc->co_cond, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
case CO_FOREACH: case CO_FOREACH:
tab(indent);
fprintf(cp_out, "foreach %s ", cc->co_foreachvar);
wl_print(cc->co_text, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
tab(indent);
fprintf(cp_out, "foreach %s ", cc->co_foreachvar);
wl_print(cc->co_text, cp_out);
putc('\n', cp_out);
indent += TABINDENT;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
indent -= TABINDENT;
tab(indent);
fprintf(cp_out, "end\n");
break;
case CO_BREAK: case CO_BREAK:
tab(indent);
if (cc->co_numtimes != 1)
fprintf(cp_out, "break %d\n", cc->co_numtimes);
else
fprintf(cp_out, "break\n");
break;
tab(indent);
if (cc->co_numtimes != 1)
fprintf(cp_out, "break %d\n", cc->co_numtimes);
else
fprintf(cp_out, "break\n");
break;
case CO_CONTINUE: case CO_CONTINUE:
tab(indent);
if (cc->co_numtimes != 1)
fprintf(cp_out, "continue %d\n",
cc->co_numtimes);
else
fprintf(cp_out, "continue\n");
break;
tab(indent);
if (cc->co_numtimes != 1)
fprintf(cp_out, "continue %d\n",
cc->co_numtimes);
else
fprintf(cp_out, "continue\n");
break;
case CO_LABEL: case CO_LABEL:
tab(indent);
fprintf(cp_out, "label %s\n", cc->co_text->wl_word);
break;
tab(indent);
fprintf(cp_out, "label %s\n", cc->co_text->wl_word);
break;
case CO_GOTO: case CO_GOTO:
tab(indent);
fprintf(cp_out, "goto %s\n", cc->co_text->wl_word);
break;
tab(indent);
fprintf(cp_out, "goto %s\n", cc->co_text->wl_word);
break;
default: default:
tab(indent);
fprintf(cp_out, "bad type %d\n", cc->co_type);
break;
tab(indent);
fprintf(cp_out, "bad type %d\n", cc->co_type);
break;
} }
return; return;
} }
@ -136,6 +136,7 @@ void
com_cdump(wordlist *wl) com_cdump(wordlist *wl)
{ {
struct control *c; struct control *c;
NG_IGNORE(wl);
indent = 0; indent = 0;
for (c = control[stackp]; c; c = c->co_next) for (c = control[stackp]; c; c = c->co_next)

17
src/frontend/trannoise/1-f-code.c

@ -20,7 +20,6 @@
#include "fftext.h" #include "fftext.h"
#include "wallace.h" #include "wallace.h"
extern double exprand(double);
void f_alpha(int n_pts, int n_exp, float X[], float Q_d, void f_alpha(int n_pts, int n_exp, float X[], float Q_d,
float alpha) float alpha)
@ -171,3 +170,19 @@ trnoise_state_init(double NA, double TS, double NALPHA, double NAMP, double RTSA
return this; return this;
} }
struct trrandom_state *
trrandom_state_init(int rndtype, double TS, double TD, double PARAM1, double PARAM2)
{
struct trrandom_state *this = TMALLOC(struct trrandom_state, 1);
this->rndtype = rndtype;
this->TS = TS;
this->TD = TD;
this->PARAM1 = PARAM1;
this->PARAM2 = PARAM2;
this->value = 0.0;
return this;
}

52
src/include/1-f-code.h

@ -1,5 +1,8 @@
extern double drand(void);
extern double exprand(double);
extern int poisson(double);
extern double gauss0(void);
void f_alpha(int n_pts, int n_exp, float X[], float Q_d, void f_alpha(int n_pts, int n_exp, float X[], float Q_d,
float alpha); float alpha);
@ -22,8 +25,17 @@ struct trnoise_state
bool RTS; bool RTS;
}; };
struct trrandom_state
{
double value;
int rndtype;
double TS, TD, PARAM1, PARAM2;
};
struct trnoise_state *trnoise_state_init(double NA, double TS, double NALPHA, double NAMP, double RTSAM, double RTSCAPT, double RTSEMT); struct trnoise_state *trnoise_state_init(double NA, double TS, double NALPHA, double NAMP, double RTSAM, double RTSCAPT, double RTSEMT);
struct trrandom_state *trrandom_state_init(int rndtype, double TS, double TD, double PARAM1, double PARAM2);
void trnoise_state_gen(struct trnoise_state *this, CKTcircuit *ckt); void trnoise_state_gen(struct trnoise_state *this, CKTcircuit *ckt);
void trnoise_state_free(struct trnoise_state *this); void trnoise_state_free(struct trnoise_state *this);
@ -50,3 +62,41 @@ trnoise_state_get(struct trnoise_state *this, CKTcircuit *ckt, size_t index)
return this->points[index % TRNOISE_STATE_MEM_LEN]; return this->points[index % TRNOISE_STATE_MEM_LEN];
} }
static inline double
trrandom_state_get(struct trrandom_state *this)
{
double param1 = this->PARAM1;
double param2 = this->PARAM2;
switch (this->rndtype) {
case 1:
/* param1: range -param1[ ... +param1[ (default = 1)
param2: offset (default = 0)
*/
return (param1 * drand() + param2);
break;
case 2:
/* param1: standard deviation (default = 1)
param2: mean (default = 0)
*/
return param1 * gauss0() + param2;
break;
case 3:
/* param1: mean (default = 1)
param2: offset (default = 0)
*/
return exprand(param1) + param2;
break;
case 4:
/* param1: lambda (default = 1)
param2: offset (default = 0)
*/
return (double)poisson(param1) + param2;
break;
default:
return 0.0;
break;
}
}

3
src/spicelib/devices/vsrc/vsrc.c

@ -22,7 +22,8 @@ IFparm VSRCpTable[] = { /* parameters */
IOP ("sffm", VSRC_SFFM, IF_REALVEC,"Single freq. FM descripton"), IOP ("sffm", VSRC_SFFM, IF_REALVEC,"Single freq. FM descripton"),
IOP ("am", VSRC_AM, IF_REALVEC,"Amplitude modulation descripton"), IOP ("am", VSRC_AM, IF_REALVEC,"Amplitude modulation descripton"),
IOP ("trnoise", VSRC_TRNOISE, IF_REALVEC,"Transient noise descripton"), IOP ("trnoise", VSRC_TRNOISE, IF_REALVEC,"Transient noise descripton"),
IOP ("trrandom", VSRC_TRRANDOM, IF_REALVEC,"random voltage descripton"),
OPU ("pos_node",VSRC_POS_NODE, IF_INTEGER,"Positive node of source"), OPU ("pos_node",VSRC_POS_NODE, IF_INTEGER,"Positive node of source"),
OPU ("neg_node",VSRC_NEG_NODE, IF_INTEGER,"Negative node of source"), OPU ("neg_node",VSRC_NEG_NODE, IF_INTEGER,"Negative node of source"),
OPU ("function",VSRC_FCN_TYPE, IF_INTEGER,"Function of the source"), OPU ("function",VSRC_FCN_TYPE, IF_INTEGER,"Function of the source"),

423
src/spicelib/devices/vsrc/vsrcacct.c

@ -19,7 +19,7 @@ extern double exprand(double);
#define SAMETIME(a,b) (fabs((a)-(b))<= TIMETOL * PW) #define SAMETIME(a,b) (fabs((a)-(b))<= TIMETOL * PW)
#define TIMETOL 1e-7 #define TIMETOL 1e-7
int int
VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) VSRCaccept(CKTcircuit *ckt, GENmodel *inModel)
/* set up the breakpoint table. /* set up the breakpoint table.
@ -42,235 +42,254 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel)
} else { } else {
/* use the transient functions */ /* use the transient functions */
switch(here->VSRCfunctionType) { switch(here->VSRCfunctionType) {
default: { /* no function specified:DC no breakpoints */
break;
}
case PULSE: {
double TD, TR, TF, PW, PER;
double tshift;
double time = 0.;
double basetime = 0;
/* gtri - begin - wbk - add PHASE parameter */
#ifdef XSPICE
double PHASE;
double phase;
double deltat;
#endif
TD = here->VSRCfunctionOrder > 2
? here->VSRCcoeffs[2] : 0.0;
TR = here->VSRCfunctionOrder > 3
&& here->VSRCcoeffs[3] != 0.0
? here->VSRCcoeffs[3] : ckt->CKTstep;
TF = here->VSRCfunctionOrder > 4
&& here->VSRCcoeffs[4] != 0.0
? here->VSRCcoeffs[4] : ckt->CKTstep;
PW = here->VSRCfunctionOrder > 5
&& here->VSRCcoeffs[5] != 0.0
? here->VSRCcoeffs[5] : ckt->CKTfinalTime;
PER = here->VSRCfunctionOrder > 6
&& here->VSRCcoeffs[6] != 0.0
? here->VSRCcoeffs[6] : ckt->CKTfinalTime;
#ifdef XSPICE
PHASE = here->VSRCfunctionOrder > 7
? here->VSRCcoeffs[7] : 0.0;
#endif
/* offset time by delay */
time = ckt->CKTtime - TD;
tshift = TD;
#ifdef XSPICE
/* normalize phase to 0 - 360° */
/* normalize phase to cycles */
phase = PHASE / 360.0;
phase = fmod(phase, 1.0);
deltat = phase * PER;
while (deltat > 0)
deltat -= PER;
time += deltat;
tshift = TD - deltat;
#endif
/* gtri - end - wbk - add PHASE parameter */
if(time >= PER) {
/* repeating signal - figure out where we are */
/* in period */
basetime = PER * floor(time/PER);
time -= basetime;
default: { /* no function specified:DC no breakpoints */
break;
} }
if( time <= 0 || time >= TR + PW + TF) {
if(ckt->CKTbreak && SAMETIME(time,0)) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + TR + tshift);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(TR+PW+TF,time) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + PER + tshift);
if(error) return(error);
} else if (ckt->CKTbreak && (time == -tshift) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift);
if(error) return(error);
} else if (ckt->CKTbreak && SAMETIME(PER,time) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift + TR + PER);
if(error) return(error);
}
} else if ( time >= TR && time <= TR + PW) {
if(ckt->CKTbreak && SAMETIME(time,TR) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift + TR + PW);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(TR+PW,time) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift + TR + PW + TF);
if(error) return(error);
}
} else if (time > 0 && time < TR) {
if(ckt->CKTbreak && SAMETIME(time,0) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift + TR);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(time,TR)) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift + TR + PW);
if(error) return(error);
case PULSE: {
double TD, TR, TF, PW, PER;
double tshift;
double time = 0.;
double basetime = 0;
/* gtri - begin - wbk - add PHASE parameter */
#ifdef XSPICE
double PHASE;
double phase;
double deltat;
#endif
TD = here->VSRCfunctionOrder > 2
? here->VSRCcoeffs[2] : 0.0;
TR = here->VSRCfunctionOrder > 3
&& here->VSRCcoeffs[3] != 0.0
? here->VSRCcoeffs[3] : ckt->CKTstep;
TF = here->VSRCfunctionOrder > 4
&& here->VSRCcoeffs[4] != 0.0
? here->VSRCcoeffs[4] : ckt->CKTstep;
PW = here->VSRCfunctionOrder > 5
&& here->VSRCcoeffs[5] != 0.0
? here->VSRCcoeffs[5] : ckt->CKTfinalTime;
PER = here->VSRCfunctionOrder > 6
&& here->VSRCcoeffs[6] != 0.0
? here->VSRCcoeffs[6] : ckt->CKTfinalTime;
#ifdef XSPICE
PHASE = here->VSRCfunctionOrder > 7
? here->VSRCcoeffs[7] : 0.0;
#endif
/* offset time by delay */
time = ckt->CKTtime - TD;
tshift = TD;
#ifdef XSPICE
/* normalize phase to 0 - 360° */
/* normalize phase to cycles */
phase = PHASE / 360.0;
phase = fmod(phase, 1.0);
deltat = phase * PER;
while (deltat > 0)
deltat -= PER;
time += deltat;
tshift = TD - deltat;
#endif
/* gtri - end - wbk - add PHASE parameter */
if(time >= PER) {
/* repeating signal - figure out where we are */
/* in period */
basetime = PER * floor(time/PER);
time -= basetime;
} }
} else { /* time > TR + PW && < TR + PW + TF */
if(ckt->CKTbreak && SAMETIME(time,TR+PW) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift+TR + PW +TF);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(time,TR+PW+TF) ) {
/* set next breakpoint */
error = CKTsetBreak(ckt,basetime + tshift + PER);
if(error) return(error);
if( time <= 0 || time >= TR + PW + TF) {
if(ckt->CKTbreak && SAMETIME(time,0)) {
error = CKTsetBreak(ckt,basetime + TR + tshift);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(TR+PW+TF,time) ) {
error = CKTsetBreak(ckt,basetime + PER + tshift);
if(error) return(error);
} else if (ckt->CKTbreak && (time == -tshift) ) {
error = CKTsetBreak(ckt,basetime + tshift);
if(error) return(error);
} else if (ckt->CKTbreak && SAMETIME(PER,time) ) {
error = CKTsetBreak(ckt,basetime + tshift + TR + PER);
if(error) return(error);
}
} else if ( time >= TR && time <= TR + PW) {
if(ckt->CKTbreak && SAMETIME(time,TR) ) {
error = CKTsetBreak(ckt,basetime + tshift + TR + PW);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(TR+PW,time) ) {
error = CKTsetBreak(ckt,basetime + tshift + TR + PW + TF);
if(error) return(error);
}
} else if (time > 0 && time < TR) {
if(ckt->CKTbreak && SAMETIME(time,0) ) {
error = CKTsetBreak(ckt,basetime + tshift + TR);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(time,TR)) {
error = CKTsetBreak(ckt,basetime + tshift + TR + PW);
if(error) return(error);
}
} else { /* time > TR + PW && < TR + PW + TF */
if(ckt->CKTbreak && SAMETIME(time,TR+PW) ) {
error = CKTsetBreak(ckt,basetime + tshift+TR + PW +TF);
if(error) return(error);
} else if(ckt->CKTbreak && SAMETIME(time,TR+PW+TF) ) {
error = CKTsetBreak(ckt,basetime + tshift + PER);
if(error) return(error);
}
} }
} }
}
break;
case SINE: {
/* no breakpoints (yet) */
}
break;
case EXP: {
/* no breakpoints (yet) */
}
break;
case SFFM:{
/* no breakpoints (yet) */
}
break;
case AM:{
/* no breakpoints (yet) */
}
break;
case PWL: {
int i;
if(ckt->CKTtime < *(here->VSRCcoeffs)) {
if(ckt->CKTbreak) {
error = CKTsetBreak(ckt,*(here->VSRCcoeffs));
break;
}
break;
case SINE: {
/* no breakpoints (yet) */
} }
for(i=0;i<(here->VSRCfunctionOrder/2)-1;i++) {
/* if((*(here->VSRCcoeffs+2*i)==ckt->CKTtime)) {
if(ckt->CKTbreak) {*/
if ( ckt->CKTbreak && AlmostEqualUlps(*(here->VSRCcoeffs+2*i), ckt->CKTtime, 3 ) ) {
error = CKTsetBreak(ckt, *(here->VSRCcoeffs+2*i+2));
if(error) return(error);
goto bkptset;
}
break;
case EXP: {
/* no breakpoints (yet) */
} }
break; break;
}
/**** tansient noise routines:
VNoi2 2 0 DC 0 TRNOISE(10n 0.5n 0 0n) : generate gaussian distributed noise
rms value, time step, 0 0
VNoi1 1 0 DC 0 TRNOISE(0n 0.5n 1 10n) : generate 1/f noise
0, time step, exponent < 2, rms value
*/
case TRNOISE: {
struct trnoise_state *state = here -> VSRCtrnoise_state;
double TS = state -> TS;
double RTSAM = state ->RTSAM;
if ((TS == 0.0) && (RTSAM == 0.0)) // no further breakpoint if value not given
case SFFM:{
/* no breakpoints (yet) */
}
break;
case AM:{
/* no breakpoints (yet) */
}
break;
case PWL: {
int i;
if(ckt->CKTtime < *(here->VSRCcoeffs)) {
if(ckt->CKTbreak) {
error = CKTsetBreak(ckt,*(here->VSRCcoeffs));
break;
}
}
for(i=0;i<(here->VSRCfunctionOrder/2)-1;i++) {
if ( ckt->CKTbreak && AlmostEqualUlps(*(here->VSRCcoeffs+2*i), ckt->CKTtime, 3 ) ) {
error = CKTsetBreak(ckt, *(here->VSRCcoeffs+2*i+2));
if(error) return(error);
goto bkptset;
}
}
break; break;
/* FIXME, dont' want this here, over to aof_get or somesuch */
if (ckt->CKTtime == 0.0) {
printf("VSRC: free fft tables\n");
fftFree();
} }
if(ckt->CKTbreak) {
/**** tansient noise routines:
VNoi2 2 0 DC 0 TRNOISE(10n 0.5n 0 0n) : generate gaussian distributed noise
rms value, time step, 0 0
VNoi1 1 0 DC 0 TRNOISE(0n 0.5n 1 10n) : generate 1/f noise
0, time step, exponent < 2, rms value
*/
case TRNOISE: {
struct trnoise_state *state = here -> VSRCtrnoise_state;
double TS = state -> TS;
double RTSAM = state ->RTSAM;
int n = (int) floor(ckt->CKTtime / TS + 0.5);
volatile double nearest = n * TS;
if ((TS == 0.0) && (RTSAM == 0.0)) // no further breakpoint if value not given
break;
if(AlmostEqualUlps(nearest, ckt->CKTtime, 3)) {
/* carefull calculate `next'
* make sure it is really identical
* with the next calculated `nearest' value
*/
volatile double next = (n+1) * TS;
error = CKTsetBreak(ckt, next);
if(error)
return(error);
/* FIXME, dont' want this here, over to aof_get or somesuch */
if (ckt->CKTtime == 0.0) {
printf("VSRC: free fft tables\n");
fftFree();
} }
}
if (RTSAM > 0) {
double RTScapTime = state->RTScapTime;
double RTSemTime = state->RTSemTime;
double RTSCAPT = state->RTSCAPT;
double RTSEMT = state->RTSEMT;
if(ckt->CKTbreak) {
int n = (int) floor(ckt->CKTtime / TS + 0.5);
volatile double nearest = n * TS;
if (ckt->CKTtime == 0) {
if (ckt->CKTbreak) {
error = CKTsetBreak(ckt, RTScapTime);
if(AlmostEqualUlps(nearest, ckt->CKTtime, 3)) {
/* carefull calculate `next'
* make sure it is really identical
* with the next calculated `nearest' value
*/
volatile double next = (n+1) * TS;
error = CKTsetBreak(ckt, next);
if(error) if(error)
return(error); return(error);
} }
} }
if(AlmostEqualUlps(RTScapTime, ckt->CKTtime, 3)) {
if (ckt->CKTbreak) {
error = CKTsetBreak(ckt, RTSemTime);
if(error)
return(error);
}
}
if(AlmostEqualUlps(RTSemTime, ckt->CKTtime, 3)) {
/* new values */
RTScapTime = here -> VSRCtrnoise_state ->RTScapTime = ckt->CKTtime + exprand(RTSCAPT);
here -> VSRCtrnoise_state ->RTSemTime = RTScapTime + exprand(RTSEMT);
if (ckt->CKTbreak) {
error = CKTsetBreak(ckt, RTScapTime);
if(error)
return(error);
if (RTSAM > 0) {
double RTScapTime = state->RTScapTime;
double RTSemTime = state->RTSemTime;
double RTSCAPT = state->RTSCAPT;
double RTSEMT = state->RTSEMT;
if (ckt->CKTtime == 0) {
if (ckt->CKTbreak) {
error = CKTsetBreak(ckt, RTScapTime);
if(error)
return(error);
}
} }
if(AlmostEqualUlps(RTScapTime, ckt->CKTtime, 3)) {
if (ckt->CKTbreak) {
error = CKTsetBreak(ckt, RTSemTime);
if(error)
return(error);
}
}
if(AlmostEqualUlps(RTSemTime, ckt->CKTtime, 3)) {
/* new values */
RTScapTime = here -> VSRCtrnoise_state ->RTScapTime = ckt->CKTtime + exprand(RTSCAPT);
here -> VSRCtrnoise_state ->RTSemTime = RTScapTime + exprand(RTSEMT);
if (ckt->CKTbreak) {
error = CKTsetBreak(ckt, RTScapTime);
if(error)
return(error);
}
}
} }
} }
break;
case TRRANDOM: {
struct trrandom_state *state = here -> VSRCtrrandom_state;
double TS = state -> TS;
double TD = state -> TD;
double time = ckt->CKTtime - TD;
if (time < 0) break;
if(ckt->CKTbreak) {
int n = (int) floor(time / TS + 0.5);
volatile double nearest = n * TS;
if(AlmostEqualUlps(nearest, time, 3)) {
/* carefully calculate `next'
* make sure it is really identical
* with the next calculated `nearest' value
*/
volatile double next = (n+1) * TS + TD;
error = CKTsetBreak(ckt, next);
if(error)
return(error);
state->value = trrandom_state_get(state);
}
}
} }
break; break;
}
}
} //switch
} // if ... else
bkptset: ; bkptset: ;
}
}
} // for
} // for
return(OK); return(OK);
} }

5
src/spicelib/devices/vsrc/vsrcdefs.h

@ -52,7 +52,8 @@ typedef struct sVSRCinstance {
double VSRCdF2phase; /* distortion f2 phase */ double VSRCdF2phase; /* distortion f2 phase */
struct trnoise_state *VSRCtrnoise_state; /* transient noise */ struct trnoise_state *VSRCtrnoise_state; /* transient noise */
struct trrandom_state *VSRCtrrandom_state; /* transient random source */
double VSRCr; /* pwl repeat */ double VSRCr; /* pwl repeat */
double VSRCrdelay; /* pwl delay period */ double VSRCrdelay; /* pwl delay period */
double *VSRCposIbrptr; /* pointer to sparse matrix element at double *VSRCposIbrptr; /* pointer to sparse matrix element at
@ -98,6 +99,7 @@ typedef struct sVSRCmodel {
#define PWL 5 #define PWL 5
#define AM 6 #define AM 6
#define TRNOISE 7 #define TRNOISE 7
#define TRRANDOM 8
#endif /*PULSE*/ #endif /*PULSE*/
/* device parameters */ /* device parameters */
@ -127,6 +129,7 @@ typedef struct sVSRCmodel {
#define VSRC_R 23 #define VSRC_R 23
#define VSRC_TD 24 #define VSRC_TD 24
#define VSRC_TRNOISE 25 #define VSRC_TRNOISE 25
#define VSRC_TRRANDOM 26
/* model parameters */ /* model parameters */

84
src/spicelib/devices/vsrc/vsrcload.c

@ -64,7 +64,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
} }
case PULSE: { case PULSE: {
double V1, V2, TD, TR, TF, PW, PER;
double V1, V2, TD, TR, TF, PW, PER;
double basetime = 0; double basetime = 0;
#ifdef XSPICE #ifdef XSPICE
double PHASE; double PHASE;
@ -96,7 +96,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
PHASE = here->VSRCfunctionOrder > 7 PHASE = here->VSRCfunctionOrder > 7
? here->VSRCcoeffs[7] : 0.0; ? here->VSRCcoeffs[7] : 0.0;
/* normalize phase to cycles */
/* normalize phase to cycles */
phase = PHASE / 360.0; phase = PHASE / 360.0;
phase = fmod(phase, 1.0); phase = fmod(phase, 1.0);
deltat = phase * PER; deltat = phase * PER;
@ -105,7 +105,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
/* shift time by pase (neg. for pos. phase value) */ /* shift time by pase (neg. for pos. phase value) */
time += deltat; time += deltat;
/* gtri - end - wbk - add PHASE parameter */ /* gtri - end - wbk - add PHASE parameter */
#endif
#endif
if(time > PER) { if(time > PER) {
/* repeating signal - figure out where we are */ /* repeating signal - figure out where we are */
/* in period */ /* in period */
@ -126,7 +126,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
break; break;
case SINE: { case SINE: {
double VO, VA, FREQ, TD, THETA; double VO, VA, FREQ, TD, THETA;
/* gtri - begin - wbk - add PHASE parameter */ /* gtri - begin - wbk - add PHASE parameter */
#ifdef XSPICE #ifdef XSPICE
@ -135,20 +135,20 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
PHASE = here->VSRCfunctionOrder > 5 PHASE = here->VSRCfunctionOrder > 5
? here->VSRCcoeffs[5] : 0.0; ? here->VSRCcoeffs[5] : 0.0;
/* compute phase in radians */
/* compute phase in radians */
phase = PHASE * M_PI / 180.0; phase = PHASE * M_PI / 180.0;
#endif #endif
VO = here->VSRCcoeffs[0]; VO = here->VSRCcoeffs[0];
VA = here->VSRCcoeffs[1]; VA = here->VSRCcoeffs[1];
FREQ = here->VSRCfunctionOrder > 2 FREQ = here->VSRCfunctionOrder > 2
&& here->VSRCcoeffs[2] != 0.0
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
TD = here->VSRCfunctionOrder > 3
? here->VSRCcoeffs[3] : 0.0;
&& here->VSRCcoeffs[2] != 0.0
? here->VSRCcoeffs[2] : (1/ckt->CKTfinalTime);
TD = here->VSRCfunctionOrder > 3
? here->VSRCcoeffs[3] : 0.0;
THETA = here->VSRCfunctionOrder > 4 THETA = here->VSRCfunctionOrder > 4
? here->VSRCcoeffs[4] : 0.0;
? here->VSRCcoeffs[4] : 0.0;
time -= TD; time -= TD;
if (time <= 0) { if (time <= 0) {
#ifdef XSPICE #ifdef XSPICE
@ -157,13 +157,13 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
value = VO + VA * sin(FREQ*time * 2.0 * M_PI + phase) * value = VO + VA * sin(FREQ*time * 2.0 * M_PI + phase) *
exp(-time*THETA); exp(-time*THETA);
#else
#else
value = VO; value = VO;
} else { } else {
value = VO + VA * sin(FREQ * time * 2.0 * M_PI) * value = VO + VA * sin(FREQ * time * 2.0 * M_PI) *
exp(-(time*THETA)); exp(-(time*THETA));
#endif #endif
/* gtri - end - wbk - add PHASE parameter */
/* gtri - end - wbk - add PHASE parameter */
} }
} }
break; break;
@ -185,7 +185,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
TAU2 = here->VSRCfunctionOrder > 5 TAU2 = here->VSRCfunctionOrder > 5
&& here->VSRCcoeffs[5] && here->VSRCcoeffs[5]
? here->VSRCcoeffs[5] : ckt->CKTstep; ? here->VSRCcoeffs[5] : ckt->CKTstep;
if(time <= TD1) { if(time <= TD1) {
value = V1; value = V1;
} else if (time <= TD2) { } else if (time <= TD2) {
@ -198,7 +198,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
break; break;
case SFFM:{ case SFFM:{
double VO, VA, FC, MDI, FS; double VO, VA, FC, MDI, FS;
/* gtri - begin - wbk - add PHASE parameters */ /* gtri - begin - wbk - add PHASE parameters */
#ifdef XSPICE #ifdef XSPICE
@ -206,16 +206,16 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
double PHASEC, PHASES; double PHASEC, PHASES;
double phasec; double phasec;
double phases; double phases;
PHASEC = here->VSRCfunctionOrder > 5 PHASEC = here->VSRCfunctionOrder > 5
? here->VSRCcoeffs[5] : 0.0;
? here->VSRCcoeffs[5] : 0.0;
PHASES = here->VSRCfunctionOrder > 6 PHASES = here->VSRCfunctionOrder > 6
? here->VSRCcoeffs[6] : 0.0;
? here->VSRCcoeffs[6] : 0.0;
/* compute phases in radians */ /* compute phases in radians */
phasec = PHASEC * M_PI / 180.0; phasec = PHASEC * M_PI / 180.0;
phases = PHASES * M_PI / 180.0; phases = PHASES * M_PI / 180.0;
#endif
#endif
VO = here->VSRCcoeffs[0]; VO = here->VSRCcoeffs[0];
VA = here->VSRCcoeffs[1]; VA = here->VSRCcoeffs[1];
FC = here->VSRCfunctionOrder > 2 FC = here->VSRCfunctionOrder > 2
@ -231,7 +231,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
value = VO + VA * value = VO + VA *
sin((2 * M_PI * FC * time + phasec) + sin((2 * M_PI * FC * time + phasec) +
MDI * sin(2.0 * M_PI * FS * time + phases)); MDI * sin(2.0 * M_PI * FS * time + phases));
#else /* XSPICE */
#else /* XSPICE */
value = VO + VA * value = VO + VA *
sin((2.0 * M_PI * FC * time) + sin((2.0 * M_PI * FC * time) +
MDI * sin(2 * M_PI * FS * time)); MDI * sin(2 * M_PI * FS * time));
@ -240,24 +240,24 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
} }
break; break;
case AM:{ case AM:{
double VA, FC, MF, VO, TD; double VA, FC, MF, VO, TD;
/* gtri - begin - wbk - add PHASE parameters */ /* gtri - begin - wbk - add PHASE parameters */
#ifdef XSPICE #ifdef XSPICE
double PHASEC, PHASES; double PHASEC, PHASES;
double phasec; double phasec;
double phases; double phases;
PHASEC = here->VSRCfunctionOrder > 5 PHASEC = here->VSRCfunctionOrder > 5
? here->VSRCcoeffs[5] : 0.0;
? here->VSRCcoeffs[5] : 0.0;
PHASES = here->VSRCfunctionOrder > 6 PHASES = here->VSRCfunctionOrder > 6
? here->VSRCcoeffs[6] : 0.0;
? here->VSRCcoeffs[6] : 0.0;
/* compute phases in radians */ /* compute phases in radians */
phasec = PHASEC * M_PI / 180.0; phasec = PHASEC * M_PI / 180.0;
phases = PHASES * M_PI / 180.0; phases = PHASES * M_PI / 180.0;
#endif
#endif
VA = here->VSRCcoeffs[0]; VA = here->VSRCcoeffs[0];
VO = here->VSRCcoeffs[1]; VO = here->VSRCcoeffs[1];
MF = here->VSRCfunctionOrder > 2 MF = here->VSRCfunctionOrder > 2
@ -278,12 +278,12 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
value = VA * (VO + sin(2.0 * M_PI * MF * time + phases )) * value = VA * (VO + sin(2.0 * M_PI * MF * time + phases )) *
sin(2 * M_PI * FC * time + phases); sin(2 * M_PI * FC * time + phases);
#else /* XSPICE */
#else /* XSPICE */
value = VA * (VO + sin(2.0 * M_PI * MF * time)) * value = VA * (VO + sin(2.0 * M_PI * MF * time)) *
sin(2 * M_PI * FC * time); sin(2 * M_PI * FC * time);
#endif
#endif
} }
/* gtri - end - wbk - add PHASE parameters */ /* gtri - end - wbk - add PHASE parameters */
} }
break; break;
@ -307,10 +307,10 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
value = foo; value = foo;
goto loadDone; goto loadDone;
} else if ( (*(here->VSRCcoeffs+2*i)+repeat_time < time) } else if ( (*(here->VSRCcoeffs+2*i)+repeat_time < time)
&& (*(here->VSRCcoeffs+2*(i+1))+repeat_time > time) ) {
&& (*(here->VSRCcoeffs+2*(i+1))+repeat_time > time) ) {
foo = *(here->VSRCcoeffs+2*i+1) + (((time-(*(here->VSRCcoeffs+2*i)+repeat_time))/ foo = *(here->VSRCcoeffs+2*i+1) + (((time-(*(here->VSRCcoeffs+2*i)+repeat_time))/
(*(here->VSRCcoeffs+2*(i+1)) - *(here->VSRCcoeffs+2*i))) *
(*(here->VSRCcoeffs+2*i+3) - *(here->VSRCcoeffs+2*i+1)));
(*(here->VSRCcoeffs+2*(i+1)) - *(here->VSRCcoeffs+2*i))) *
(*(here->VSRCcoeffs+2*i+3) - *(here->VSRCcoeffs+2*i+1)));
value = foo; value = foo;
goto loadDone; goto loadDone;
} }
@ -319,7 +319,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt)
value = foo; value = foo;
if ( !here->VSRCrGiven ) goto loadDone; if ( !here->VSRCrGiven ) goto loadDone;
end_time = *(here->VSRCcoeffs + here->VSRCfunctionOrder-2); end_time = *(here->VSRCcoeffs + here->VSRCfunctionOrder-2);
breakpt_time = *(here->VSRCcoeffs + here->VSRCrBreakpt); breakpt_time = *(here->VSRCcoeffs + here->VSRCrBreakpt);
repeat_time = end_time + (end_time - breakpt_time)*num_repeat++ - breakpt_time; repeat_time = end_time + (end_time - breakpt_time)*num_repeat++ - breakpt_time;
@ -368,7 +368,17 @@ VNoi3 3 0 DC 0 TRNOISE(0 0 0 0 15m 22u 50u) : generate RTS noise
if(here -> VSRCdcGiven) if(here -> VSRCdcGiven)
value += here->VSRCdcValue; value += here->VSRCdcValue;
} // case } // case
break;
break;
case TRRANDOM: {
struct trrandom_state *state = here -> VSRCtrrandom_state;
value = state -> value;
/* DC value */
if(here -> VSRCdcGiven)
value += here->VSRCdcValue;
}
break;
} // switch } // switch
} }
loadDone: loadDone:
@ -379,7 +389,7 @@ loadDone:
#else #else
if (ckt->CKTmode & MODETRANOP) value *= ckt->CKTsrcFact; if (ckt->CKTmode & MODETRANOP) value *= ckt->CKTsrcFact;
/* load the new voltage value into the matrix */ /* load the new voltage value into the matrix */
*(ckt->CKTrhs + (here->VSRCbranch)) += value;
*(ckt->CKTrhs + (here->VSRCbranch)) += value;
#endif #endif
/* gtri - end - wbk - modify to process srcFact, etc. for all sources */ /* gtri - end - wbk - modify to process srcFact, etc. for all sources */
} // for loop instances } // for loop instances

198
src/spicelib/devices/vsrc/vsrcpar.c

@ -97,22 +97,22 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
double end_time; double end_time;
here->VSRCr = value->rValue; here->VSRCr = value->rValue;
here->VSRCrGiven = TRUE; here->VSRCrGiven = TRUE;
for ( i = 0; i < here->VSRCfunctionOrder; i += 2 ) {
here->VSRCrBreakpt = i;
if ( here->VSRCr == *(here->VSRCcoeffs+i) ) break;
}
end_time = *(here->VSRCcoeffs + here->VSRCfunctionOrder-2);
if ( here->VSRCr > end_time ) {
fprintf(stderr, "ERROR: repeat start time value %g for pwl voltage source must be smaller than final time point given!\n", here->VSRCr );
return ( E_PARMVAL );
}
if ( here->VSRCr != *(here->VSRCcoeffs+here->VSRCrBreakpt) ) {
fprintf(stderr, "ERROR: repeat start time value %g for pwl voltage source does not match any time point given!\n", here->VSRCr );
return ( E_PARMVAL );
}
for ( i = 0; i < here->VSRCfunctionOrder; i += 2 ) {
here->VSRCrBreakpt = i;
if ( here->VSRCr == *(here->VSRCcoeffs+i) ) break;
}
end_time = *(here->VSRCcoeffs + here->VSRCfunctionOrder-2);
if ( here->VSRCr > end_time ) {
fprintf(stderr, "ERROR: repeat start time value %g for pwl voltage source must be smaller than final time point given!\n", here->VSRCr );
return ( E_PARMVAL );
}
if ( here->VSRCr != *(here->VSRCcoeffs+here->VSRCrBreakpt) ) {
fprintf(stderr, "ERROR: repeat start time value %g for pwl voltage source does not match any time point given!\n", here->VSRCr );
return ( E_PARMVAL );
}
break; } break; }
case VSRC_SFFM: case VSRC_SFFM:
@ -122,90 +122,118 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->VSRCfunctionOrder = value->v.numValue; here->VSRCfunctionOrder = value->v.numValue;
here->VSRCcoeffsGiven = TRUE; here->VSRCcoeffsGiven = TRUE;
break; break;
case VSRC_AM:
if(value->v.numValue <2) return(E_BADPARM);
case VSRC_AM:
if(value->v.numValue <2) return(E_BADPARM);
here->VSRCfunctionType = AM; here->VSRCfunctionType = AM;
here->VSRCfuncTGiven = TRUE; here->VSRCfuncTGiven = TRUE;
here->VSRCcoeffs = value->v.vec.rVec; here->VSRCcoeffs = value->v.vec.rVec;
here->VSRCfunctionOrder = value->v.numValue; here->VSRCfunctionOrder = value->v.numValue;
here->VSRCcoeffsGiven = TRUE;
break;
case VSRC_D_F1:
here->VSRCdF1given = TRUE;
here->VSRCdGiven = TRUE;
switch(value->v.numValue) {
case 2:
here->VSRCdF1phase = *(value->v.vec.rVec+1);
here->VSRCdF1mag = *(value->v.vec.rVec);
break;
case 1:
here->VSRCdF1mag = *(value->v.vec.rVec);
here->VSRCdF1phase = 0.0;
break;
case 0:
here->VSRCdF1mag = 1.0;
here->VSRCdF1phase = 0.0;
break;
default:
return(E_BADPARM);
break;
}
case VSRC_D_F2:
here->VSRCdF2given = TRUE;
here->VSRCdGiven = TRUE;
switch(value->v.numValue) {
case 2:
here->VSRCdF2phase = *(value->v.vec.rVec+1);
here->VSRCdF2mag = *(value->v.vec.rVec);
break;
case 1:
here->VSRCdF2mag = *(value->v.vec.rVec);
here->VSRCdF2phase = 0.0;
break;
case 0:
here->VSRCdF2mag = 1.0;
here->VSRCdF2phase = 0.0;
break;
default:
return(E_BADPARM);
}
break;
case VSRC_TRNOISE: {
double NA, TS;
double NALPHA = 0.0;
double NAMP = 0.0;
double RTSAM = 0.0;
double RTSCAPT = 0.0;
double RTSEMT = 0.0;
here->VSRCfunctionType = TRNOISE;
here->VSRCcoeffsGiven = TRUE;
break;
case VSRC_D_F1:
here->VSRCdF1given = TRUE;
here->VSRCdGiven = TRUE;
switch(value->v.numValue) {
case 2:
here->VSRCdF1phase = *(value->v.vec.rVec+1);
here->VSRCdF1mag = *(value->v.vec.rVec);
break;
case 1:
here->VSRCdF1mag = *(value->v.vec.rVec);
here->VSRCdF1phase = 0.0;
break;
case 0:
here->VSRCdF1mag = 1.0;
here->VSRCdF1phase = 0.0;
break;
default:
return(E_BADPARM);
break;
}
case VSRC_D_F2:
here->VSRCdF2given = TRUE;
here->VSRCdGiven = TRUE;
switch(value->v.numValue) {
case 2:
here->VSRCdF2phase = *(value->v.vec.rVec+1);
here->VSRCdF2mag = *(value->v.vec.rVec);
break;
case 1:
here->VSRCdF2mag = *(value->v.vec.rVec);
here->VSRCdF2phase = 0.0;
break;
case 0:
here->VSRCdF2mag = 1.0;
here->VSRCdF2phase = 0.0;
break;
default:
return(E_BADPARM);
}
break;
case VSRC_TRNOISE: {
double NA, TS;
double NALPHA = 0.0;
double NAMP = 0.0;
double RTSAM = 0.0;
double RTSCAPT = 0.0;
double RTSEMT = 0.0;
here->VSRCfunctionType = TRNOISE;
here->VSRCfuncTGiven = TRUE;
here->VSRCcoeffs = value->v.vec.rVec;
here->VSRCfunctionOrder = value->v.numValue;
here->VSRCcoeffsGiven = TRUE;
NA = here->VSRCcoeffs[0]; // input is rms value
TS = here->VSRCcoeffs[1]; // time step
if (here->VSRCfunctionOrder > 2)
NALPHA = here->VSRCcoeffs[2]; // 1/f exponent
if (here->VSRCfunctionOrder > 3 && NALPHA != 0.0)
NAMP = here->VSRCcoeffs[3]; // 1/f amplitude
if (here->VSRCfunctionOrder > 4)
RTSAM = here->VSRCcoeffs[4]; // RTS amplitude
if (here->VSRCfunctionOrder > 5 && RTSAM != 0.0)
RTSCAPT = here->VSRCcoeffs[5]; // RTS trap capture time
if (here->VSRCfunctionOrder > 6 && RTSAM != 0.0)
RTSEMT = here->VSRCcoeffs[6]; // RTS trap emission time
here->VSRCtrnoise_state =
trnoise_state_init(NA, TS, NALPHA, NAMP, RTSAM, RTSCAPT, RTSEMT);
}
break;
case VSRC_TRRANDOM: {
double TD = 0.0, TS;
int rndtype = 1;
double PARAM1 = 1.0;
double PARAM2 = 0.0;
here->VSRCfunctionType = TRRANDOM;
here->VSRCfuncTGiven = TRUE; here->VSRCfuncTGiven = TRUE;
here->VSRCcoeffs = value->v.vec.rVec; here->VSRCcoeffs = value->v.vec.rVec;
here->VSRCfunctionOrder = value->v.numValue; here->VSRCfunctionOrder = value->v.numValue;
here->VSRCcoeffsGiven = TRUE; here->VSRCcoeffsGiven = TRUE;
NA = here->VSRCcoeffs[0]; // input is rms value
rndtype = (int)here->VSRCcoeffs[0]; // type of random function
TS = here->VSRCcoeffs[1]; // time step TS = here->VSRCcoeffs[1]; // time step
if (here->VSRCfunctionOrder > 2) if (here->VSRCfunctionOrder > 2)
NALPHA = here->VSRCcoeffs[2]; // 1/f exponent
if (here->VSRCfunctionOrder > 3 && NALPHA != 0.0)
NAMP = here->VSRCcoeffs[3]; // 1/f amplitude
TD = here->VSRCcoeffs[2]; // delay
if (here->VSRCfunctionOrder > 3)
PARAM1 = here->VSRCcoeffs[3]; // first parameter
if (here->VSRCfunctionOrder > 4) if (here->VSRCfunctionOrder > 4)
RTSAM = here->VSRCcoeffs[4]; // RTS amplitude
if (here->VSRCfunctionOrder > 5 && RTSAM != 0.0)
RTSCAPT = here->VSRCcoeffs[5]; // RTS trap capture time
if (here->VSRCfunctionOrder > 6 && RTSAM != 0.0)
RTSEMT = here->VSRCcoeffs[6]; // RTS trap emission time
PARAM2 = here->VSRCcoeffs[4]; // second parameter
here->VSRCtrnoise_state =
trnoise_state_init(NA, TS, NALPHA, NAMP, RTSAM, RTSCAPT, RTSEMT);
here->VSRCtrrandom_state =
trrandom_state_init(rndtype, TS, TD, PARAM1, PARAM2);
} }
break;
break;
default: default:
return(E_BADPARM); return(E_BADPARM);
} }

Loading…
Cancel
Save