From ed625c5509ef2eb8c2608d75509229ef4641f94b Mon Sep 17 00:00:00 2001 From: h_vogt Date: Wed, 15 Sep 2010 22:00:04 +0000 Subject: [PATCH] update --- ChangeLog | 1 + examples/control_structs/MonteCarlo.sp | 67 ++++++++++++++++---------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b919f1b5..345684fe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 : diff --git a/examples/control_structs/MonteCarlo.sp b/examples/control_structs/MonteCarlo.sp index 37665f810..e37152cde 100644 --- a/examples/control_structs/MonteCarlo.sp +++ b/examples/control_structs/MonteCarlo.sp @@ -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