Skip to content

Commit

Permalink
Сделана фильтрация шумов
Browse files Browse the repository at this point in the history
  • Loading branch information
3XclusiVe committed Nov 23, 2016
1 parent 04e3bef commit be2f570
Show file tree
Hide file tree
Showing 22 changed files with 1,083 additions and 33 deletions.
File renamed without changes.
Binary file added lib/JTransforms-3.1-with-dependencies.jar
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added lib/jcommon-1.0.23.jar
Binary file not shown.
Binary file added lib/jfreechart-1.0.19.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions src/com/company/CommandsListener.java
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();
}
82 changes: 77 additions & 5 deletions src/com/company/CommandsRecognizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,53 @@
import com.darkprograms.speech.recognizer.GoogleResponse;
import info.debatty.java.stringsimilarity.JaroWinkler;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;

/**
* Created by user on 21.11.16.
*/
public class CommandsRecognizer implements ResponseListener {

JaroWinkler jaroWinkler;
private enum Commands {
startTraining,
poseType,
capturePose,
completeTraining
}

private List<CommandsListener> listeners;

private EnumMap<Commands, String> commands;
private EnumMap<Commands, Double> commandsSimilarity;

private JaroWinkler jaroWinkler;

private int commandsCount = 4;

private static final String startTraining = "начать обучение";
private static final String poseType = "название новой позы";
private static final String capturePose = "фиксация";
private static final String completeTraining = "закончить обучение";



public CommandsRecognizer() {
jaroWinkler = new JaroWinkler();
commands = new EnumMap<Commands, String>(Commands.class);
commandsSimilarity = new EnumMap<Commands, Double>(Commands.class);

commands.put(Commands.startTraining, startTraining);
commands.put(Commands.capturePose, capturePose);
commands.put(Commands.poseType, poseType);
commands.put(Commands.completeTraining, completeTraining);

listeners = new ArrayList<CommandsListener>();
}

public void addListener(CommandsListener listener) {
listeners.add(listener);
}


Expand Down Expand Up @@ -54,9 +84,51 @@ public void onResponce(GoogleResponse response) {
}
}

System.out.println(startTrainingSimilarity);
System.out.println(poseTypeSimilarity);
System.out.println(capturePoseSimilarity);
System.out.println(completeTrainingSimilarity);
commandsSimilarity.put(Commands.startTraining, startTrainingSimilarity);
commandsSimilarity.put(Commands.poseType, poseTypeSimilarity);
commandsSimilarity.put(Commands.capturePose, capturePoseSimilarity);
commandsSimilarity.put(Commands.completeTraining, completeTrainingSimilarity);

RecognizedCommand recognizedCommand = new RecognizedCommand();

for (Commands command : Commands.values()) {
if(recognizedCommand.Similarity < commandsSimilarity.get(command)) {
recognizedCommand.command = command;
recognizedCommand.Similarity = commandsSimilarity.get(command);

}
System.out.println(command + " " + commandsSimilarity.get(command));
}

double tresHold = 0.7;

if(recognizedCommand.Similarity > tresHold) {
for (CommandsListener listener : listeners) {
sendCommand(listener, recognizedCommand.command);
}
}
}

private void sendCommand(CommandsListener listener, Commands command) {
switch (command) {
case startTraining:
listener.onStartTraining();
break;
case poseType:
listener.onPoseType("New name");
break;
case capturePose:
listener.onCapturePose();
break;
case completeTraining:
listener.onCompleteTraining();
break;
}
}


class RecognizedCommand {
public Commands command = null;
public double Similarity = 0;
}
}
70 changes: 70 additions & 0 deletions src/com/company/FFTTest/GraphTest.java
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);
}
}
}
}

}

104 changes: 104 additions & 0 deletions src/com/company/FFTTest/Main.java
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;
}


}
56 changes: 56 additions & 0 deletions src/com/company/FFTTest/SignalReader.java
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;
}
}
31 changes: 31 additions & 0 deletions src/com/company/FFTTest/SineExample.java
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;

}
}
Loading

0 comments on commit be2f570

Please sign in to comment.