Commit bb6692ae authored by Michael Zbyszyński's avatar Michael Zbyszyński
Browse files

moving rapidStream into rapidLib

parent 1bfcc4f4
/*
* rapidStream.cpp
* Created by Michael Zbyszynski on 6 Feb 2017
* Copyright © 2017 Goldsmiths. All rights reserved.
*/
#include "rapidStream.h"
#include <iostream>
#include <cmath>
rapidStream::rapidStream(int window_size) {
windowSize = window_size;
windowIndex = 0;
circularWindow = new double[window_size];
for (int i = 0; i < windowSize; ++i) {
circularWindow[i] = 0;
}
}
rapidStream::rapidStream() {
windowSize = 3;
windowIndex = 0;
circularWindow = new double[windowSize];
for (int i = 0; i < windowSize; ++i) {
circularWindow[i] = 0;
}
}
rapidStream::~rapidStream() {
delete []circularWindow;
}
void rapidStream::clear() {
windowIndex = 0;
circularWindow = new double[windowSize];
for (int i = 0; i < windowSize; ++i) {
circularWindow[i] = 0;
}
}
void rapidStream::pushToWindow(double input) {
circularWindow[windowIndex] = input;
windowIndex = (windowIndex + 1) % windowSize;
}
inline double rapidStream::calcCurrentVel(int i) {
return circularWindow[(i + windowIndex) % windowSize] - circularWindow[(i + windowIndex - 1) % windowSize];
}
double rapidStream::velocity() {
return calcCurrentVel(-1);
};
double rapidStream::acceleration() {
return calcCurrentVel(-2) - calcCurrentVel(-3);
};
double rapidStream::minimum() {
double minimum = std::numeric_limits<double>::infinity();
for (int i = 0; i < windowSize; ++i) {
if (circularWindow[i] < minimum) {
minimum = circularWindow[i];
}
}
return minimum;
}
double rapidStream::maximum() {
double maximum = std::numeric_limits<double>::min();
for (int i = 0; i < windowSize; ++i) {
if (circularWindow[i] > maximum) {
maximum = circularWindow[i];
}
}
return maximum;
}
double rapidStream::sum() {
double newSum = 0;
for(int i = 0; i < windowSize; ++i)
{
newSum += circularWindow[i];
}
return newSum;
}
double rapidStream::mean() {
return sum()/windowSize;
}
double rapidStream::standardDeviation() {
double newMean = mean();
double standardDeviation = 0.;
for(int i = 0; i < windowSize; ++i) {
standardDeviation += pow(circularWindow[i] - newMean, 2);
}
return sqrt(standardDeviation / windowSize);
}
double rapidStream::minVelocity() {
double minVel = std::numeric_limits<double>::infinity();
for (int i = 0; i < windowSize; ++i) {
double currentVel = calcCurrentVel(i);
if ( currentVel < minVel) {
minVel = currentVel;
}
}
return minVel;
}
double rapidStream::maxVelocity() {
double maxVel = std::numeric_limits<double>::lowest();
for (int i = 0; i < windowSize; ++i) {
double currentVel = calcCurrentVel(i);
if (currentVel > maxVel) {
maxVel = currentVel;
}
}
return maxVel;
}
double rapidStream::minAcceleration() {
double minAccel = std::numeric_limits<double>::infinity();
double lastVel = calcCurrentVel(1);
for (int i = 2; i < windowSize; ++i) {
double currentVel = calcCurrentVel(i);
double currentAccel = currentVel - lastVel;
lastVel = currentVel;
if (currentAccel < minAccel) {
minAccel = currentAccel;
}
}
return minAccel;
}
double rapidStream::maxAcceleration() {
double maxAccel = std::numeric_limits<double>::lowest();
double lastVel = calcCurrentVel(1);
for (int i = 2; i < windowSize; ++i) {
double currentVel = calcCurrentVel(i);
double currentAccel = currentVel - lastVel;
lastVel = currentVel;
if (currentAccel > maxAccel) {
maxAccel = currentAccel;
}
}
return maxAccel;
}
\ No newline at end of file
/*
* rapidStream.h
* Created by Michael Zbyszynski on 6 Feb 2017
* Copyright © 2017 Goldsmiths. All rights reserved.
*/
#ifndef rapidStream_h
#define rapidStream_h
#include <stdint.h>
class rapidStream {
public:
/**
* Create a circular buffer with 3 elements.
*/
rapidStream();
/**
* Create a circular buffer with an arbitrary number of elements.
* @param int: number of elements to hold in the buffer
*/
rapidStream(int windowSize);
~rapidStream();
/**
* Resets all the values in the buffer to zero.
*/
void clear();
/** Add a value to a circular buffer whose size is defined at creation.
* @param double: value to be pushed into circular buffer.
*/
void pushToWindow(double input);
/** Calculate the first-order difference (aka velocity) between the last two inputs.
* @return double: difference between last two inputs.
*/
double velocity();
/** Calculate the second-order difference (aka acceleration) over the last three inputs.
* @return double: acceleration over the last three inputs.
*/
double acceleration();
/** Find the minimum value in the buffer.
* @return double: minimum.
*/
double minimum();
/** Find the maximum value in the buffer.
* @return double: maximum.
*/
double maximum();
/** Calculate the sum of all values in the buffer.
* @return double: sum.
*/
double sum();
/** Calculate the mean of all values in the buffer.
* @return double: mean.
*/
double mean();
/** Calculate the standard deviation of all values in the buffer.
* @return double: standard deviation.
*/
double standardDeviation();
/** Calculate the minimum first-order difference over consecutive inputs in the buffer.
* @return double: minimum velocity.
*/
double minVelocity();
/** Calculate the maximum first-order difference over consecutive inputs in the buffer.
* @return double: maximum velocity.
*/
double maxVelocity();
/** Calculate the minimum second-order difference over consecutive inputs in the buffer.
* @return double: minimum acceleration.
*/
double minAcceleration();
/** Calculate the maximum second-order difference over consecutive inputs in the buffer.
* @return double: maximum acceleration.
*/
double maxAcceleration();
private:
uint32_t windowSize;
uint32_t windowIndex;
double *circularWindow;
double calcCurrentVel(int i);
};
#endif
\ No newline at end of file
......@@ -41,6 +41,9 @@
311BA3211EDC7B2400244DAC /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 311BA3201EDC7B2400244DAC /* Accelerate.framework */; };
311BA3241EDC7BA800244DAC /* DnB-loop-175BPM.wav in CopyFiles */ = {isa = PBXBuildFile; fileRef = 311BA3231EDC7BA400244DAC /* DnB-loop-175BPM.wav */; };
311BA3251EDCE80B00244DAC /* jsoncpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5E081ED8450E00E9FAFA /* jsoncpp.cpp */; };
BE9286491EF015AE006847CF /* test_signalProcessing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EE31ED8480D00E9FAFA /* test_signalProcessing.cpp */; };
BE92864C1EF015E7006847CF /* rapidStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE92864A1EF015E7006847CF /* rapidStream.cpp */; };
BE92864D1EF01622006847CF /* rapidStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE92864A1EF015E7006847CF /* rapidStream.cpp */; };
BEA7B70F1EDD7B350003E84B /* machineLearning.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EBE1ED8459300E9FAFA /* machineLearning.cpp */; };
BEA7B7101EDD7B390003E84B /* trainingData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EC01ED8459300E9FAFA /* trainingData.cpp */; };
BEA7B7111EDD7B640003E84B /* svm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EED1ED849AA00E9FAFA /* svm.cpp */; };
......@@ -51,8 +54,6 @@
BEA7B7161EDD7B700003E84B /* regression.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5DF91ED8450E00E9FAFA /* regression.cpp */; };
BEA7B7171EDD7B7E0003E84B /* jsoncpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5E081ED8450E00E9FAFA /* jsoncpp.cpp */; };
BEA7B7181EDD7C0E0003E84B /* test_RapidLib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EDF1ED8480D00E9FAFA /* test_RapidLib.cpp */; };
BEA7B7191EDD95C40003E84B /* test_signalProcessing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EE31ED8480D00E9FAFA /* test_signalProcessing.cpp */; };
BEA7B71A1EDD95E90003E84B /* rapidStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EC51ED8459300E9FAFA /* rapidStream.cpp */; };
BEA7B71B1EDD96090003E84B /* maxiFFT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5A141ED8450C00E9FAFA /* maxiFFT.cpp */; };
BEA7B71C1EDD960F0003E84B /* maxiMFCC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5A191ED8450C00E9FAFA /* maxiMFCC.cpp */; };
BEA7B71D1EDD96140003E84B /* fft.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5A0E1ED8450C00E9FAFA /* fft.cpp */; };
......@@ -231,8 +232,6 @@
BE2C5EC01ED8459300E9FAFA /* trainingData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = trainingData.cpp; sourceTree = "<group>"; };
BE2C5EC11ED8459300E9FAFA /* trainingData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = trainingData.h; sourceTree = "<group>"; };
BE2C5EC21ED8459300E9FAFA /* rapidmix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rapidmix.h; sourceTree = "<group>"; };
BE2C5EC51ED8459300E9FAFA /* rapidStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rapidStream.cpp; sourceTree = "<group>"; };
BE2C5EC61ED8459300E9FAFA /* rapidStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rapidStream.h; sourceTree = "<group>"; };
BE2C5EC71ED8459300E9FAFA /* signalProcessing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = signalProcessing.h; sourceTree = "<group>"; };
BE2C5EDA1ED8471F00E9FAFA /* catch.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch.hpp; sourceTree = "<group>"; };
BE2C5EDB1ED8471F00E9FAFA /* LICENSE_1_0.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE_1_0.txt; sourceTree = "<group>"; };
......@@ -336,6 +335,8 @@
BE2C5F541EDD74FC00E9FAFA /* rta_window.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rta_window.c; sourceTree = "<group>"; };
BE2C5F551EDD74FC00E9FAFA /* rta_window.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rta_window.h; sourceTree = "<group>"; };
BE2C5F561EDD74FC00E9FAFA /* rta_configuration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rta_configuration.h; sourceTree = "<group>"; };
BE92864A1EF015E7006847CF /* rapidStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rapidStream.cpp; sourceTree = "<group>"; };
BE92864B1EF015E7006847CF /* rapidStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rapidStream.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -676,6 +677,8 @@
BE2C5DE81ED8450E00E9FAFA /* src */ = {
isa = PBXGroup;
children = (
BE92864A1EF015E7006847CF /* rapidStream.cpp */,
BE92864B1EF015E7006847CF /* rapidStream.h */,
BE2C5DE91ED8450E00E9FAFA /* baseModel.h */,
BE2C5EED1ED849AA00E9FAFA /* svm.cpp */,
BE2C5EEE1ED849AA00E9FAFA /* svm.h */,
......@@ -743,21 +746,11 @@
isa = PBXGroup;
children = (
311BA2A81EDC6ACC00244DAC /* rapidPiPoTools */,
BE2C5EC41ED8459300E9FAFA /* rapidStream */,
BE2C5EC71ED8459300E9FAFA /* signalProcessing.h */,
);
path = signalProcessing;
sourceTree = "<group>";
};
BE2C5EC41ED8459300E9FAFA /* rapidStream */ = {
isa = PBXGroup;
children = (
BE2C5EC51ED8459300E9FAFA /* rapidStream.cpp */,
BE2C5EC61ED8459300E9FAFA /* rapidStream.h */,
);
path = rapidStream;
sourceTree = "<group>";
};
BE2C5ED91ED8471F00E9FAFA /* catch */ = {
isa = PBXGroup;
children = (
......@@ -1120,6 +1113,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BE92864C1EF015E7006847CF /* rapidStream.cpp in Sources */,
0BA41BAE1EE6E10A00B74667 /* jsoncpp.cpp in Sources */,
0BE2E7381EE56F5800722712 /* GVF.cpp in Sources */,
0BE2E7371EE56F4F00722712 /* rapidGVF.cpp in Sources */,
......@@ -1175,12 +1169,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BEA7B7191EDD95C40003E84B /* test_signalProcessing.cpp in Sources */,
BEA7B71A1EDD95E90003E84B /* rapidStream.cpp in Sources */,
BEA7B71B1EDD96090003E84B /* maxiFFT.cpp in Sources */,
BEA7B71C1EDD960F0003E84B /* maxiMFCC.cpp in Sources */,
BEA7B71D1EDD96140003E84B /* fft.cpp in Sources */,
BE9286491EF015AE006847CF /* test_signalProcessing.cpp in Sources */,
BEA7B71E1EDD963E0003E84B /* maximilian.cpp in Sources */,
BE92864D1EF01622006847CF /* rapidStream.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment