-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,083 additions
and
33 deletions.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.company; | ||
|
||
/** | ||
* Created by user on 21.11.16. | ||
*/ | ||
public interface CommandsListener { | ||
void onStartTraining(); | ||
void onPoseType(String name); | ||
void onCapturePose(); | ||
void onCompleteTraining(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.company.FFTTest; | ||
|
||
|
||
import org.jfree.chart.ChartFactory; | ||
import org.jfree.chart.ChartPanel; | ||
import org.jfree.chart.JFreeChart; | ||
import org.jfree.chart.axis.ValueAxis; | ||
import org.jfree.chart.plot.XYPlot; | ||
import org.jfree.data.time.Millisecond; | ||
import org.jfree.data.time.TimeSeries; | ||
import org.jfree.data.time.TimeSeriesCollection; | ||
|
||
import javax.swing.*; | ||
import java.util.Random; | ||
|
||
/** | ||
* Created by user on 22.11.16. | ||
*/ | ||
public class GraphTest { | ||
|
||
static TimeSeries ts = new TimeSeries("data", Millisecond.class); | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
gen myGen = new gen(); | ||
new Thread(myGen).start(); | ||
|
||
TimeSeriesCollection dataset = new TimeSeriesCollection(ts); | ||
JFreeChart chart = ChartFactory.createTimeSeriesChart( | ||
"GraphTest", | ||
"Time", | ||
"Value", | ||
dataset, | ||
true, | ||
true, | ||
false | ||
); | ||
final XYPlot plot = chart.getXYPlot(); | ||
ValueAxis axis = plot.getDomainAxis(); | ||
axis.setAutoRange(true); | ||
axis.setFixedAutoRange(60000.0); | ||
|
||
JFrame frame = new JFrame("GraphTest"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
ChartPanel label = new ChartPanel(chart); | ||
frame.getContentPane().add(label); | ||
//Suppose I add combo boxes and buttons here later | ||
|
||
frame.pack(); | ||
frame.setVisible(true); | ||
} | ||
|
||
static class gen implements Runnable { | ||
private Random randGen = new Random(); | ||
|
||
public void run() { | ||
while (true) { | ||
int num = randGen.nextInt(1000); | ||
System.out.println(num); | ||
ts.addOrUpdate(new Millisecond(), num); | ||
try { | ||
Thread.sleep(20); | ||
} catch (InterruptedException ex) { | ||
System.out.println(ex); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
|
||
|
||
import com.company.SignalReader; | ||
import com.company.SineExample; | ||
import org.jtransforms.fft.*; | ||
|
||
import javax.swing.JFrame; | ||
import javax.swing.SwingUtilities; | ||
|
||
import org.jfree.chart.ChartFactory; | ||
import org.jfree.chart.ChartPanel; | ||
import org.jfree.chart.JFreeChart; | ||
import org.jfree.chart.plot.PlotOrientation; | ||
import org.jfree.data.xy.DefaultXYDataset; | ||
import org.jfree.data.xy.XYDataset; | ||
|
||
public class Main { | ||
|
||
static JFreeChart chart; | ||
|
||
static int i = 0; | ||
|
||
public static void main(String[] args) { | ||
|
||
double[] sine = SineExample.getSine(); | ||
//show(sine, "Sine"); | ||
|
||
double[] sineSpectrum = sine.clone(); | ||
DoubleFFT_1D fftDo = new DoubleFFT_1D(sineSpectrum.length); | ||
fftDo.realForward(sineSpectrum); | ||
|
||
|
||
|
||
show(sineSpectrum, "Sinus Spectrum"); | ||
|
||
while (true) { | ||
|
||
i++; | ||
|
||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
double[] arr = new double[sineSpectrum.length]; | ||
|
||
for(int j = 0; j < sineSpectrum.length; j++) { | ||
arr[j] = i; | ||
} | ||
|
||
XYDataset ds = createDataset(arr, 25000); | ||
|
||
chart = ChartFactory.createXYLineChart("q", | ||
"x", "y", ds, PlotOrientation.VERTICAL, true, true, | ||
false); | ||
|
||
} | ||
|
||
} | ||
|
||
private static void show(double[] array, String Title) { | ||
|
||
SwingUtilities.invokeLater(new Runnable() { | ||
public void run() { | ||
JFrame frame = new JFrame("Charts"); | ||
|
||
frame.setSize(1000, 600); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setVisible(true); | ||
|
||
XYDataset ds = createDataset(array, 25000); | ||
chart = ChartFactory.createXYLineChart(Title, | ||
"x", "y", ds, PlotOrientation.VERTICAL, true, true, | ||
false); | ||
|
||
ChartPanel cp = new ChartPanel(chart); | ||
|
||
|
||
frame.getContentPane().add(cp); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private static XYDataset createDataset(double[] array, double SampleRate) { | ||
|
||
DefaultXYDataset ds = new DefaultXYDataset(); | ||
|
||
double[][] data = new double[2][array.length]; | ||
|
||
|
||
for (int i = 0; i < array.length; i++) { | ||
data[0][i] = ((double)i * SampleRate / 2) / (array.length); | ||
data[1][i] = array[i]; | ||
} | ||
|
||
ds.addSeries("signal", data); | ||
|
||
return ds; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.company; | ||
|
||
import java.io.*; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
/** | ||
* Created by malll on 15.04.2016. | ||
*/ | ||
public class SignalReader { | ||
|
||
private File dataFile = new File("data/2015_05_20__13_00_06.dat"); | ||
private int ChannelNumber = 13; | ||
private int[] Signal; | ||
private int signalLenth; | ||
private int sampleSize = 4; | ||
|
||
public SignalReader() { | ||
try (DataInputStream dis = new DataInputStream(new FileInputStream(dataFile))) { | ||
|
||
byte[] signal = new byte[(int) dataFile.length()]; | ||
dis.read(signal); | ||
|
||
signalLenth = signal.length / sampleSize; | ||
Signal = new int[signalLenth]; | ||
|
||
ByteBuffer byteBuffer = ByteBuffer.wrap(signal); | ||
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
for(int i = 0; i < signalLenth; i++) { | ||
int value = byteBuffer.getInt(); | ||
Signal[i] = value; | ||
} | ||
|
||
System.out.println(signalLenth); | ||
|
||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public double[] readChannel(int channelNumber) { | ||
|
||
double[] ChannelOneSignal = new double[signalLenth / ChannelNumber]; | ||
|
||
for(int i = channelNumber - 1; i < signalLenth; i+= ChannelNumber) { | ||
ChannelOneSignal[i / ChannelNumber] = Signal[i]; | ||
} | ||
for (int i = 0; i < ChannelOneSignal.length; i++) { | ||
// System.out.println(ChannelOneSignal[i]); | ||
} | ||
return ChannelOneSignal; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.company; | ||
|
||
/** | ||
* Created by malll on 18.04.2016. | ||
*/ | ||
public class SineExample { | ||
|
||
private final static int SAMPLERATE = 25000; | ||
|
||
public static double[] getSine() { | ||
int frequency = 100; // freq of our sine wave | ||
double lengthInSecs = 0.01024; | ||
int samplesNum = (int) Math.round(lengthInSecs * SAMPLERATE); | ||
|
||
System.out.println("Samplesnum: " + samplesNum); | ||
|
||
double[] audioData = new double[samplesNum]; | ||
int samplePos = 0; | ||
|
||
// http://en.wikibooks.org/wiki/Sound_Synthesis_Theory/Oscillators_and_Wavetables | ||
for (double phase = 0; samplePos < lengthInSecs * SAMPLERATE && samplePos < samplesNum; phase += (2 * Math.PI * frequency) / SAMPLERATE) { | ||
audioData[samplePos++] = Math.sin(phase); | ||
|
||
if (phase >= 2 * Math.PI) | ||
phase -= 2 * Math.PI; | ||
} | ||
|
||
return audioData; | ||
|
||
} | ||
} |
Oops, something went wrong.