1 package org.jgnuplot;
    2 
    3 /**
    4  * This class provides the samefunctionality as gnuplot electron.dem.
    5  *
    6  * Electronics demo
    7  *
    8  * @author Pander
    9  */
   10 public final class ElectronDem {
   11    private ElectronDem() {
   12    }
   13 
   14    public static void gnuplot() {
   15       Plot.setGnuplotExecutable("gnuplot");
   16       Plot.setPlotDirectory("/tmp");
   17 
   18       Plot aPlot = new Plot();
   19       aPlot.addExtra("# Bipolar Transistor (NPN) Mutual Characteristic");
   20       aPlot.addExtra("Ie(Vbe)=Ies*exp(Vbe/kT_q)");
   21       aPlot.addExtra("Ic(Vbe)=alpha*Ie(Vbe)+Ico");
   22       aPlot.addExtra("alpha = 0.99");
   23       aPlot.addExtra("Ies = 4e-14");
   24       aPlot.addExtra("Ico = 1e-09");
   25       aPlot.addExtra("kT_q = 0.025");
   26       aPlot.setDummy("Vbe");
   27       aPlot.setGrid();
   28       aPlot.addExtra("set offsets");
   29       aPlot.addExtra("unset log");
   30       aPlot.addExtra("unset polar");
   31       aPlot.setSamples("160");
   32       aPlot.setTitle("Mutual Characteristic of a Transistor");
   33       aPlot.setXLabel("Vbe (base emmitter voltage)");
   34       aPlot.setXRange("0", "0.75");
   35       aPlot.setYLabel("Ic (collector current)");
   36       aPlot.setYRange("0", "0.005");
   37       aPlot.setKey("box");
   38       aPlot.setKey(".2,.0045");
   39       aPlot.addExtra("set format y \"%.4f\"");
   40       aPlot.pushGraph(new Graph("Ic(Vbe)"));
   41       aPlot.setOutput(Terminal.PNG, "test/out/electron-01.png");
   42       try {
   43          aPlot.plot();
   44       }
   45       catch (Exception e) {
   46          System.err.println(e);
   47          System.exit(1);
   48       }
   49 
   50       aPlot.clear();
   51       aPlot.addExtra("set format \"%g\"");
   52       aPlot.addExtra("# Junction Field Effect Transistor (JFET) Mutual Characteristic");
   53       aPlot.addExtra("# drain current above pinch off");
   54       aPlot.addExtra("Ida(Vd)=Ido*(1-Vg/Vp)**2");
   55       aPlot.addExtra("# drain current below pinch off");
   56       aPlot.addExtra("Idb(Vd)=Ido*(2*Vd*(Vg-Vp)-Vd*Vd)/(Vp*Vp)");
   57       aPlot.addExtra("# drain current");
   58       aPlot.addExtra("Id(Vd)= (Vd>Vg-Vp) ? Ida(Vd) : Idb(Vd)");
   59       aPlot.addExtra("# drain current at zero gate voltage");
   60       aPlot.addExtra("Ido = 2.5");
   61       aPlot.addExtra("# pinch off voltage");
   62       aPlot.addExtra("Vp = -1.25");
   63       aPlot.addExtra("# gate voltage");
   64       aPlot.addExtra("Vg = 0");
   65       aPlot.setDummy("Vd");
   66       aPlot.unsetGrid();
   67       aPlot.unsetKey();
   68       aPlot.addExtra("set offsets 0, 1, 0, 0");
   69       aPlot.setTitle("JFET Mutual Characteristic");
   70       aPlot.setXLabel("Drain voltage Vd (V)");
   71       aPlot.setXRange("0", "4");
   72       aPlot.setYLabel("Drain current Id (mA)");
   73       aPlot.setYRange("0", "5");
   74       aPlot.addExtra("set label \"-0.5 Vp\" at 4.1,0.625");
   75       aPlot.addExtra("set label \"-0.25 Vp\" at 4.1,1.4");
   76       aPlot.addExtra("set label \"0\" at 4.1,2.5");
   77       aPlot.addExtra("set label \"Vg = 0.5 Vp\" at 4.1,3.9");
   78       aPlot.pushGraph(new Graph("Vg=0.5*Vp,Id(Vd)"));
   79       aPlot.pushGraph(new Graph("Vg=0.25*Vp,Id(Vd)"));
   80       aPlot.pushGraph(new Graph("Vg=0,Id(Vd)"));
   81       aPlot.pushGraph(new Graph("Vg=-0.25*Vp,Id(Vd)"));
   82       aPlot.setOutput(Terminal.PNG, "test/out/electron-02.png");
   83       try {
   84          aPlot.plot();
   85       }
   86       catch (Exception e) {
   87          System.err.println(e);
   88          System.exit(1);
   89       }
   90 
   91       aPlot.clear();
   92       aPlot.addExtra("unset label");
   93       aPlot.addExtra("# show off double axes");
   94       aPlot.addExtra("# amplitude frequency response");
   95       aPlot.addExtra("A(jw) = ({0,1}*jw/({0,1}*jw+p1)) * (1/(1+{0,1}*jw/p2))");
   96       aPlot.addExtra("p1 = 10");
   97       aPlot.addExtra("p2 = 10000");
   98       aPlot.setDummy("jw");
   99       aPlot.setGrid("x y2");
  100       aPlot.setKey("default");
  101       aPlot.setLogscale("xy");
  102       aPlot.addExtra("set log x2");
  103       aPlot.addExtra("unset log y2");
  104       aPlot.setTitle("Amplitude and Phase Frequency Response");
  105       aPlot.setXLabel("jw (radians)");
  106       aPlot.setXRange("1.1", "90000.0");
  107       aPlot.setX2Range("1.1", "90000.0");
  108       aPlot.setYLabel("Magnitude of A(jw)");
  109       aPlot.setY2Label("Phase of A(jw) (degrees)");
  110       aPlot.setYTics("nomirror");
  111       aPlot.setY2Tics();
  112       aPlot.addExtra("set tics out");
  113       aPlot.setAutoscale("y,y2");
  114       aPlot.setAutoscaleAfterRanges();
  115       aPlot.pushGraph(new Graph("abs(A(jw))"));
  116       aPlot.pushGraph(new Graph("180/pi*arg(A(jw))", Axes.X2Y2));
  117       aPlot.setOutput(Terminal.PNG, "test/out/electron-03.png");
  118       try {
  119          aPlot.plot();
  120       }
  121       catch (Exception e) {
  122          System.err.println(e);
  123          System.exit(1);
  124       }
  125    }
  126 }