This commit is contained in:
h_vogt 2010-09-15 22:00:04 +00:00
parent 590bf0a677
commit ed625c5509
2 changed files with 42 additions and 26 deletions

View File

@ -1,5 +1,6 @@
2010-09-15 Holger Vogt
* com_measure2.c: prevent seg fault in meas ac, if real input
* examples/control_structs/MonteCarlo.sp: update, add measure
2010-09-12 Robert Larice
* src/main.c :

View File

@ -1,4 +1,4 @@
Perform Monte Carlo simulation in ngspice
* Effecting a Monte Carlo calculation in ngspice
V1 N001 0 AC 1 DC 0
R1 N002 N001 141
*
@ -10,40 +10,55 @@ L3 N003 N002 40e-06
C3 OUT N003 250e-12
*
R2 0 OUT 141
*
.control
let mc_runs = 100
let run = 1
set curplot = new $ create a new plot
set scratch = $curplot $ store its name to 'scratch'
let mc_runs = 5
let run = 0
set curplot=new $ create a new plot
set scratch=$curplot $ store its name to 'scratch'
setplot $scratch $ make 'scratch' the active plot
let bwh=unitvec(mc_runs) $ create a vector in plot 'scratch' to store bandwidth data
*
dowhile run < mc_runs $ loop starts here
*
* alter c1 = unif(1e-09, 0.1)
* alter c1 = aunif(1e-09, 100e-12)
* alter c1 = gauss(1e-09, 0.1, 3)
* alter c1 = agauss(1e-09, 100e-12, 3)
*
* define distributions for random numbers:
* unif: uniform distribution, deviation relativ to nominal value
* aunif: uniform distribution, deviation absolut
* gauss: Gaussian distribution, deviation relativ to nominal value
* agauss: Gaussian distribution, deviation absolut
define unif(nom, var) (nom + (nom*var) * sunif(0))
define aunif(nom, avar) (nom + avar * sunif(0))
define gauss(nom, var, sig) (nom + (nom*var)/sig * sgauss(0))
define agauss(nom, avar, sig) (nom + avar/sig * sgauss(0))
*
dowhile run <= mc_runs
* alter c1 = unif(1e-09, 0.1)
* alter l1 = aunif(10e-06, 2e-06)
* alter c2 = aunif(1e-09, 100e-12)
* alter l2 = unif(10e-06, 0.2)
* alter l3 = aunif(40e-06, 8e-06)
* alter c3 = unif(250e-12, 0.15)
alter c1 = gauss(1e-09, 0.1, 3)
alter l1 = agauss(10e-06, 2e-06, 3)
alter c2 = agauss(1e-09, 100e-12, 3)
alter l2 = gauss(10e-06, 0.2, 3)
alter l3 = agauss(40e-06, 8e-06, 3)
alter c3 = gauss(250e-12, 0.15, 3)
alter c1 = unif(1e-09, 0.1)
alter l1 = unif(10e-06, 0.1)
alter c2 = unif(1e-09, 0.1)
alter l2 = unif(10e-06, 0.1)
alter l3 = unif(40e-06, 0.1)
alter c3 = unif(250e-12, 0.1)
*
ac oct 100 250K 10Meg
set run ="$&run" $ create a variable from the vector
set dt = $curplot $ store the current plot to dt
setplot $scratch $ make 'scratch' the active plot
*
* measure bandwidth at -10 dB
meas ac bw trig vdb(out) val=-10 rise=1 targ vdb(out) val=-10 fall=1
*
set run ="$&run" $ create a variable from the vector
set dt = $curplot $ store the current plot to dt
setplot $scratch $ make 'scratch' the active plot
let vout{$run}={$dt}.v(out) $ store the output vector to plot 'scratch'
setplot $dt $ go back to the previous plot
let run = run + 1
end
plot db({$scratch}.all)
let bwh[run]={$dt}.bw $ store bw to vector bwh in plot 'scratch'
setplot $dt $ go back to the previous plot
let run = run + 1
end $ loop ends here
*
plot db({$scratch}.allv)
echo
print {$scratch}.bwh
.endc
.end