Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ttldeformation;
- import sk.uniba.fmph.pocprak.simplegraphics.*;
- public class TTLDeformation {
- static GrGraphics gr = SimpleGraphics.CreateGrEnvironment();
- public static void main(String[] args) {
- double time = 0;
- double dt = 0.001;
- double period = 1;
- double outputVoltage = 0;
- double dU = 0;
- double RC = 0.1;
- prepareGraph();
- for(; time<3; time=time+dt){
- dU=(1/RC)*(inputVoltage(time, period)-outputVoltage)*dt;
- outputVoltage = outputVoltage + dU;
- paintGraph(time, outputVoltage, dU, dt);
- //System.out.println("time elapsed: "+time+" Voltage Shift: "+dU+" output Voltage: "+outputVoltage);
- }
- }
- /**
- * Generates TTL over time
- * @param t - time elapsed
- * @return int value of voltage
- */
- static int inputVoltage(double t, double period){
- if(Math.sin(t*(2*Math.PI/period))>0)
- return 5;
- return 0;
- }
- /**
- *
- * @param t - time elapsed
- * @param voltage
- */
- static void paintGraph(double t, double voltage, double dU, double dt){
- gr.drawLine2D(t, voltage-dU, t+dt, voltage);
- gr.repaint();
- }
- /**
- * draws axis & scale & stuff
- */
- static void prepareGraph(){
- gr.margin=50;
- gr.setBasePoint(gr.LL);
- gr.setUserFrameSize(0.,0.,3.5,5.5);
- GrAxisX xaxis = new GrAxisX(0.,3.5,0.);
- xaxis.setLTicks(0.0,0.5);
- xaxis.draw(gr);
- GrAxisY yaxis = new GrAxisY(0.,5.5,0.);
- yaxis.setLTicks(0.0,0.5);
- yaxis.draw(gr);
- gr.repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement