Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.lukaszpiskadlo.ptd.lab1;
- import org.knowm.xchart.QuickChart;
- import org.knowm.xchart.SwingWrapper;
- import org.knowm.xchart.XYChart;
- import java.util.function.Function;
- import static java.lang.Math.PI;
- public class Main {
- public static void main(String[] args) {
- double f = 100;
- double phi = PI;
- double fs = 8000;
- double t = 100;
- XYChart chart = generate(t, n -> Math.cos(2 * PI * f * (n / fs) + phi), "Zad 1", "x(n)");
- SwingWrapper<XYChart> swingWrapper = new SwingWrapper<>(chart);
- swingWrapper.displayChart();
- }
- static XYChart generate(double t, Function<Double, Double> function, String title, String series) {
- double[] xData = new double[100];
- double[] yData = new double[100];
- double j = 0;
- for (int i = 0; i < xData.length; i++) {
- j += t / xData.length;
- xData[i] = j;
- yData[i] = function.apply(j);
- }
- return QuickChart.getChart(title, "T[s]", "[Hz]", series, xData, yData);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement