Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package edu.lukaszpiskadlo.ptd.lab1;
  2.  
  3. import org.knowm.xchart.QuickChart;
  4. import org.knowm.xchart.SwingWrapper;
  5. import org.knowm.xchart.XYChart;
  6.  
  7. import java.util.function.Function;
  8.  
  9. import static java.lang.Math.PI;
  10.  
  11. public class Main {
  12.  
  13.     public static void main(String[] args) {
  14.  
  15.         double f = 100;
  16.         double phi = PI;
  17.         double fs = 8000;
  18.         double t = 100;
  19.  
  20.         XYChart chart = generate(t, n -> Math.cos(2 * PI * f * (n / fs) + phi), "Zad 1", "x(n)");
  21.  
  22.         SwingWrapper<XYChart> swingWrapper = new SwingWrapper<>(chart);
  23.         swingWrapper.displayChart();
  24.     }
  25.  
  26.     static XYChart generate(double t, Function<Double, Double> function, String title, String series) {
  27.         double[] xData = new double[100];
  28.         double[] yData = new double[100];
  29.         double j = 0;
  30.  
  31.         for (int i = 0; i < xData.length; i++) {
  32.             j += t / xData.length;
  33.             xData[i] = j;
  34.             yData[i] = function.apply(j);
  35.         }
  36.  
  37.         return QuickChart.getChart(title, "T[s]", "[Hz]", series, xData, yData);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement