Advertisement
hocikto19

TTL Signal deformation

Mar 3rd, 2015
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package ttldeformation;
  2. import sk.uniba.fmph.pocprak.simplegraphics.*;
  3.  
  4. public class TTLDeformation {
  5.     static GrGraphics gr = SimpleGraphics.CreateGrEnvironment();
  6.  
  7.     public static void main(String[] args) {
  8.         double time = 0;
  9.         double dt = 0.001;
  10.         double period = 1;
  11.         double outputVoltage = 0;
  12.         double dU = 0;
  13.         double RC = 0.1;
  14.         prepareGraph();
  15.         for(; time<3; time=time+dt){
  16.             dU=(1/RC)*(inputVoltage(time, period)-outputVoltage)*dt;
  17.             outputVoltage = outputVoltage + dU;
  18.             paintGraph(time, outputVoltage, dU, dt);
  19.             //System.out.println("time elapsed: "+time+" Voltage Shift: "+dU+" output Voltage: "+outputVoltage);
  20.         }
  21.     }
  22.    
  23.     /**
  24.      * Generates TTL over time
  25.      * @param t - time elapsed
  26.      * @return int value of voltage
  27.      */
  28.     static int inputVoltage(double t, double period){
  29.         if(Math.sin(t*(2*Math.PI/period))>0)
  30.             return 5;
  31.         return 0;
  32.     }
  33.    
  34.     /**
  35.      *
  36.      * @param t - time elapsed
  37.      * @param voltage
  38.      */
  39.     static void paintGraph(double t, double voltage, double dU, double dt){
  40.         gr.drawLine2D(t, voltage-dU, t+dt, voltage);
  41.         gr.repaint();
  42.     }
  43.    
  44.     /**
  45.      * draws axis & scale & stuff
  46.      */
  47.     static void prepareGraph(){
  48.         gr.margin=50;
  49.         gr.setBasePoint(gr.LL);
  50.         gr.setUserFrameSize(0.,0.,3.5,5.5);
  51.         GrAxisX xaxis = new GrAxisX(0.,3.5,0.);
  52.         xaxis.setLTicks(0.0,0.5);
  53.         xaxis.draw(gr);
  54.         GrAxisY yaxis = new GrAxisY(0.,5.5,0.);
  55.         yaxis.setLTicks(0.0,0.5);
  56.         yaxis.draw(gr);
  57.         gr.repaint();
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement