ISRC: update to trnoise source, same as in VSRC
This commit is contained in:
parent
aedd9d92ee
commit
0e0b276a3e
|
|
@ -201,7 +201,7 @@ ISRCaccept(CKTcircuit *ckt, GENmodel *inModel)
|
|||
/* FIXME, dont' want this here, over to aof_get or somesuch */
|
||||
if (ckt->CKTtime == 0.0) {
|
||||
if (ft_ngdebug)
|
||||
printf("VSRC: free fft tables\n");
|
||||
printf("ISRC: free fft tables\n");
|
||||
fftFree();
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ Author: 1985 Thomas L. Quarles
|
|||
#include "isrcdefs.h"
|
||||
#include "ngspice/sperror.h"
|
||||
#include "ngspice/suffix.h"
|
||||
#include "ngspice/1-f-code.h"
|
||||
|
||||
|
||||
int
|
||||
|
|
@ -15,6 +16,8 @@ ISRCdelete(GENinstance *gen_inst)
|
|||
ISRCinstance *inst = (ISRCinstance *) gen_inst;
|
||||
|
||||
FREE(inst->ISRCcoeffs);
|
||||
trnoise_state_free(inst->ISRCtrnoise_state);
|
||||
FREE(inst->ISRCtrrandom_state);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,19 +334,27 @@ INoi1 1 0 DC 0 TRNOISE(0n 0.5n 1 10n) : generate 1/f noise
|
|||
double TS = state -> TS;
|
||||
double RTSAM = state->RTSAM;
|
||||
|
||||
/* reset top (hack for repeated tran commands) */
|
||||
if (time == 0)
|
||||
state->top = 0;
|
||||
/* reset top (hack for repeated tran commands)
|
||||
when there is the jump from time=0 to time>0 */
|
||||
if (time == 0.0)
|
||||
state->timezero = TRUE;
|
||||
else
|
||||
if (state->timezero) {
|
||||
state->top = 0;
|
||||
state->timezero = FALSE;
|
||||
}
|
||||
|
||||
/* no noise */
|
||||
if(TS == 0.0) {
|
||||
/* no noise or time == 0 */
|
||||
if (TS == 0.0 || time == 0.0) {
|
||||
value = 0.0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
/* 1/f and white noise */
|
||||
size_t n1 = (size_t) floor(time / TS);
|
||||
size_t n1 = (size_t)floor(time / TS);
|
||||
|
||||
double V1 = trnoise_state_get(state, ckt, n1);
|
||||
double V2 = trnoise_state_get(state, ckt, n1+1);
|
||||
double V2 = trnoise_state_get(state, ckt, n1 + 1);
|
||||
|
||||
value = V1 + (V2 - V1) * (time / TS - (double)n1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,7 +206,9 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
|
|||
|
||||
if (here->ISRCfunctionOrder > 6 && RTSAM != 0.0)
|
||||
RTSEMT = here->ISRCcoeffs[6]; // RTS trap emission time
|
||||
|
||||
/* after an 'alter' command to the TRNOISE voltage source the state gets re-written
|
||||
with the new parameters. So free the old state first. */
|
||||
trnoise_state_free(here->ISRCtrnoise_state);
|
||||
here->ISRCtrnoise_state =
|
||||
trnoise_state_init(NA, TS, NALPHA, NAMP, RTSAM, RTSCAPT, RTSEMT);
|
||||
}
|
||||
|
|
@ -233,6 +235,9 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
|
|||
if (here->ISRCfunctionOrder > 4)
|
||||
PARAM2 = here->ISRCcoeffs[4]; // second parameter
|
||||
|
||||
/* after an 'alter' command to the TRRANDOM voltage source the state gets re-written
|
||||
with the new parameters. So free the old state first. */
|
||||
tfree(here->ISRCtrrandom_state);
|
||||
here->ISRCtrrandom_state =
|
||||
trrandom_state_init(rndtype, TS, TD, PARAM1, PARAM2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue