protected static JFrame showGraph(double[] array, String title) { FunctionGraph graph = new FunctionGraph(400, 200, 0, 1, array); JFrame frame = graph.showInJFrame(title, 500, 300, true, false); return frame; } }
public void initialise(int width, int height, double newX0, double newXStep, double[] data) { setPreferredSize(new Dimension(width, height)); setOpaque(true); this.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { updateData(newX0, newXStep, data);
protected void updateGraph(FunctionGraph someGraph, String title) { if (someGraph.getParent() == null) { JFrame jf = someGraph.showInJFrame(title, 400, 250, false, false); setDependentWindowLocation(jf); } else { JFrame jf = (JFrame) SwingUtilities.getWindowAncestor(someGraph); jf.setTitle(title); jf.setVisible(true); // just to be sure someGraph.repaint(); } } }
FunctionGraph clusterGraph = new FunctionGraph(0, 1, new double[1]); clusterGraph.setYMinMax(0, 5); clusterGraph.setPrimaryDataSeriesStyle(Color.BLUE, FunctionGraph.DRAW_DOTS, FunctionGraph.DOT_FULLCIRCLE); JFrame jf = clusterGraph.showInJFrame("", false, true); for (int i = 0; i < clusters.length; i++) { double[] meanValues = clusters[i].getMeanPolynomial().generatePolynomialValues(100, 0, 1); clusterGraph.updateData(0, 1. / meanValues.length, meanValues); clusterGraph.addDataSeries(pred, Color.GRAY, FunctionGraph.DRAW_LINE, -1); jf.repaint();
public boolean compute() throws IOException, UnsupportedAudioFileException { logger.info("F0 polynomial feature file writer started."); f0Graph = new FunctionGraph(0, 1, new double[1]); f0Graph.setYMinMax(50, 550); f0Graph.setPrimaryDataSeriesStyle(Color.BLUE, FunctionGraph.DRAW_DOTS, FunctionGraph.DOT_FULLCIRCLE); jf = f0Graph.showInJFrame("Sentence", false, true); String outPutFile = db.getProp(db.ROOTDIR) + File.separator + getProp(ONEWORD) + getProp(PARTBASENAME) + getProp(F0POLYFILE); featurePW = new PrintWriter(new FileWriter(new File(outPutFile))); for (int i = 0; i < bnlVocalizations.getLength(); i++) { percent = 100 * i / bnlVocalizations.getLength(); displaySentences(bnlVocalizations.getName(i)); } featurePW.flush(); featurePW.close(); System.out.println("Total Cost : " + costMeasure / (double) bnlVocalizations.getLength()); // String fileName = "/home/sathish/phd/voices/en-GB-listener/vocal-polynomials/SpiVocalizationF0PolyFeatureFile.txt"; int kValue = (new Integer(getProp(KCLUSTERS))).intValue(); KMeansClusterer kmc = new KMeansClusterer(); kmc.loadF0Polynomials(outPutFile); kmc.trainer(kValue); // System.exit(0); return true; }
public void update(double x) { if (Double.isNaN(x)) return; int centerIndex = (int) (x * samplingRate); assert centerIndex >= 0 && centerIndex < signal.length; int windowLength = 1024; int leftIndex = centerIndex - windowLength / 2; if (leftIndex < 0) leftIndex = 0; double[] signalExcerpt = new HammingWindow(windowLength).apply(signal, leftIndex); double[] spectrum = FFT.computeLogPowerSpectrum(signalExcerpt); if (graph == null) { graph = new FunctionGraph(300, 200, 0, samplingRate / windowLength, spectrum); } else { graph.updateData(0, samplingRate / windowLength, spectrum); } super.updateGraph(graph, "Spectrum at " + new PrintfFormat("%.3f").sprintf(x) + " s"); }
public JFrame showInJFrame(String title, boolean allowZoom, boolean showControls, boolean exitOnClose) { return showInJFrame(title, DEFAULT_WIDTH, DEFAULT_HEIGHT + 50, allowZoom, showControls, exitOnClose); }
protected void update(double[] signal, int samplingRate) { super.updateData(0, 1. / samplingRate, signal); updateSound(signal, samplingRate); }
f0Array = SignalProcUtils.medianFilter(f0Array, 5); f0Graph.updateData(0, tsSentenceDuration / (double) audioSampleRate / f0Array.length, f0Array); jf.repaint(); f0Graph.addDataSeries(interpol, Color.GREEN, FunctionGraph.DRAW_DOTS, FunctionGraph.DOT_EMPTYCIRCLE); jf.repaint(); f0Graph.addDataSeries(sylPred, Color.RED, FunctionGraph.DRAW_LINE, -1); double eqDistance = DistanceComputer.getEuclideanDistance(sylPred, f0AndInterpolate); System.out.println(baseName + " - EqDist: " + eqDistance / (double) sylPred.length);
protected String getLabel(double x, double y) { // be about one order of magnitude less precise than there are pixels int pixelPrecisionX = 2; if (graphImage != null) { pixelPrecisionX = (int) (Math.log(graphImage.getWidth() / getXRange()) / Math.log(10)); } int precisionX = -(int) (Math.log(getXRange()) / Math.log(10)) + pixelPrecisionX; if (precisionX < 0) precisionX = 0; // ignore imageY int precisionY = -(int) (Math.log(getYRange()) / Math.log(10)) + 2; if (precisionY < 0) precisionY = 0; int indexX = X2indexX(x); double[] data = dataseries.get(0); return "f(" + new PrintfFormat("%." + precisionX + "f").sprintf(x) + ")=" + new PrintfFormat("%." + precisionY + "f").sprintf(data[indexX]); }
glass.setVisible(true); glass.addCursorSource(this); this.addCursorListener(glass); if (allowZoom) { JPanel zoomPanel = new JPanel(); zoomPanel.add(zoomOut); if (showControls) { JPanel controls = getControls(); if (controls != null) { zoomPanel.add(Box.createVerticalGlue()); this.requestFocus(); return main;
FunctionGraph g2 = (FunctionGraph) it2.next(); if (g2 != g) { g.addCursorListener(g2); g.addCursorListener(glass);
FunctionGraph clusterGraph = new FunctionGraph(0, 1, new double[1]); clusterGraph.setYMinMax(0, 5); clusterGraph.setPrimaryDataSeriesStyle(Color.BLUE, FunctionGraph.DRAW_DOTS, FunctionGraph.DOT_FULLCIRCLE); JFrame jf = clusterGraph.showInJFrame("", false, true); for (int i = 0; i < clusters.length; i++) { double[] meanValues = clusters[i].getMeanPolynomial().generatePolynomialValues(100, 0, 1); clusterGraph.updateData(0, 1. / meanValues.length, meanValues); clusterGraph.addDataSeries(pred, Color.GRAY, FunctionGraph.DRAW_LINE, -1); jf.repaint();
public void update(double x) { if (Double.isNaN(x)) return; int centerIndex = (int) (x * samplingRate); assert centerIndex >= 0 && centerIndex < signal.length; int windowLength = 1024; int leftIndex = centerIndex - windowLength / 2; if (leftIndex < 0) leftIndex = 0; double[] signalExcerpt = new HammingWindow(windowLength).apply(signal, leftIndex); double[] spectrum = FFT.computeLogPowerSpectrum(signalExcerpt); if (graph == null) { graph = new FunctionGraph(300, 200, 0, samplingRate / windowLength, spectrum); } else { graph.updateData(0, samplingRate / windowLength, spectrum); } super.updateGraph(graph, "Spectrum at " + new PrintfFormat("%.3f").sprintf(x) + " s"); }
public JFrame showInJFrame(String title, boolean allowZoom, boolean exitOnClose) { return showInJFrame(title, DEFAULT_WIDTH, DEFAULT_HEIGHT + 50, allowZoom, true, exitOnClose); }
protected void updateGraph(FunctionGraph someGraph, String title) { if (someGraph.getParent() == null) { JFrame jf = someGraph.showInJFrame(title, 400, 250, false, false); setDependentWindowLocation(jf); } else { JFrame jf = (JFrame) SwingUtilities.getWindowAncestor(someGraph); jf.setTitle(title); jf.setVisible(true); // just to be sure someGraph.repaint(); } } }
protected void update(double[] signal, int samplingRate) { super.updateData(0, 1. / samplingRate, signal); updateSound(signal, samplingRate); }
protected String getLabel(double x, double y) { // be about one order of magnitude less precise than there are pixels int pixelPrecisionX = 2; if (graphImage != null) { pixelPrecisionX = (int) (Math.log(graphImage.getWidth() / getXRange()) / Math.log(10)); } int precisionX = -(int) (Math.log(getXRange()) / Math.log(10)) + pixelPrecisionX; if (precisionX < 0) precisionX = 0; // ignore imageY int precisionY = -(int) (Math.log(getYRange()) / Math.log(10)) + 2; if (precisionY < 0) precisionY = 0; int indexX = X2indexX(x); double[] data = dataseries.get(0); return "f(" + new PrintfFormat("%." + precisionX + "f").sprintf(x) + ")=" + new PrintfFormat("%." + precisionY + "f").sprintf(data[indexX]); }