Skip to content

Commit

Permalink
Revert "ASIC First Commit"
Browse files Browse the repository at this point in the history
This reverts commit 8343404.
  • Loading branch information
ethanbb committed Nov 10, 2021
1 parent 8343404 commit b81fe51
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 208 deletions.
171 changes: 171 additions & 0 deletions ASICPhaseCalculator/Source/ARModeler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
Previously called mempar()
Originally in FORTRAN, hence the array offsets of 1, Yuk.
Original code from Kay, 1988, appendix 8D.
Perform Burg's Maximum Entropy AR parameter estimation
outputting (or not) successive models en passant. Sourced from Alex Sergejew
Two small changes made by NH in November 1998:
tstarz.h no longer included, just say "typedef double REAL" instead
Declare ar by "REAL **ar" instead of "REAL ar[MAXA][MAXA]
Further "cleaning" by Paul Bourke.....for personal style only.
Converted to zero-based arrays by Paul Sanders, June 2007
Simplified and 'g' removed, plus class wrapper added by Ethan Blackwood, 2018
*/

#ifndef AR_MODELER_H_INCLUDED
#define AR_MODELER_H_INCLUDED

#include <BasicJuceHeader.h>

namespace PhaseCalculator
{
class ARModeler {
public:
ARModeler(int order = 1, int length = 2, int strideIn = 1, bool* success = nullptr)
{
bool s = setParams(order, length, strideIn);
if (success != nullptr)
{
*success = s;
}
}

~ARModeler() { }

void reset()
{
hasBeenUsed = false;
}

bool hasBeenFit()
{
return hasBeenUsed;
}

// returns true if successful.
bool setParams(int order, int length, int strideIn)
{
int newStridedLength = calcStridedLength(length, strideIn);
if (order < 1 || newStridedLength < order + 1)
{
jassertfalse;
return false;
}
arOrder = order;
inputLength = length;
stride = strideIn;
stridedLength = newStridedLength;
reallocateStorage();
return true;
}

void getModel(Array<double, CriticalSection>& modelOut)
{
jassert(hasBeenUsed);

// copies using internal mutex
modelOut = coefficients;
}

void fitModel(const Array<double>& j_inputseries_reverse)
{
jassert(j_inputseries_reverse.size() >= inputLength);
double t1, t2;
int n;

// get raw pointers to improve performance
const double* inputseries_last = j_inputseries_reverse.begin() + inputLength - 1;
double* coef = j_coef_temp.begin();
double* per = j_per.begin();
double* pef = j_pef.begin();
double* h = j_h.begin();

// reset per and pef
resetPredictionError();

for (n = 1; n <= arOrder; n++)
{
double sn = 0.0;
double sd = 0.0;
int j;
int jj = stridedLength - n;

for (j = 0; j < jj; j++)
{
t1 = inputseries_last[-stride * (j + n)] + pef[j];
t2 = inputseries_last[-stride * j] + per[j];
sn -= 2.0 * t1 * t2;
sd += (t1 * t1) + (t2 * t2);
}

t1 = sn / sd;
coef[n - 1] = t1;
if (n != 1)
{
for (j = 1; j < n; j++)
h[j - 1] = coef[j - 1] + t1 * coef[n - j - 1];
for (j = 1; j < n; j++)
coef[j - 1] = h[j - 1];
jj--;
}

for (j = 0; j < jj; j++)
{
per[j] = per[j] + t1 * pef[j] + t1 * inputseries_last[-stride * (j + n)];
pef[j] = pef[j + 1] + t1 * per[j + 1] + t1 * inputseries_last[-stride * (j + 1)];
}
}

// save (using built-in mutex)
coefficients.swapWith(j_coef_temp);

hasBeenUsed = true;
}

private:

void reallocateStorage()
{
j_h.resize(arOrder - 1);
j_per.resize(stridedLength);
j_pef.resize(stridedLength);
j_coef_temp.resize(arOrder);
coefficients.resize(arOrder);
resetPredictionError();
}

void resetPredictionError()
{
FloatVectorOperations::clear(j_per.begin(), stridedLength);
FloatVectorOperations::clear(j_pef.begin(), stridedLength);
}

static int calcStridedLength(int inputLength, int stride)
{
jassert(stride > 0);
return (inputLength + (stride - 1)) / stride;
}

int arOrder;
int inputLength;
int stridedLength;
int stride;
Array<double> j_per;
Array<double> j_pef;
Array<double> j_h;

Array<double, CriticalSection> j_coef_temp;
Array<double, CriticalSection> coefficients;

bool hasBeenUsed = false;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ARModeler);
};
}

#endif // AR_MODELER_H_INCLUDED
7 changes: 3 additions & 4 deletions ASICPhaseCalculator/Source/HTransformers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "HTransformers.h"

namespace ASICPhaseCalculator
namespace PhaseCalculator
{
namespace
{
Expand Down Expand Up @@ -52,8 +52,8 @@ namespace ASICPhaseCalculator
HilbertInfo()
{
// Added by sumedh and modified
int del = 15;
Array<double> htcoeff = Array<double>({ -0.433593750000000,0.0,-0.136718750000000,0.0,-0.216796875000000,0.0,-0.638671875000000,0.0,0.638671875000000,0.0,0.216796875000000,0.0,0.136718750000000,0.0,0.433593750000000 });
int del = 7;
Array<double> htcoeff = Array<double>({ -0.433593750000000,0.0,-0.136718750000000,0.0,-0.216796875000000,0.0,-0.638671875000000 });

/*delta band*/
validBand[DELTA] = Array<float>({ 1, 4 });
Expand Down Expand Up @@ -173,7 +173,6 @@ namespace ASICPhaseCalculator
transformer[RIPPLE] = Array<double>({
0.00195312500000000,-0.00195312500000000,0.00195312500000000,0.0195312500000000,0.00976562500000000,-0.0390625000000000,-0.0527343750000000,0.0234375000000000,0.0800781250000000,0.0195312500000000,-0.0234375000000000,0.0292968750000000,-0.0410156250000000,-0.251953125000000,-0.121093750000000,0.449218750000000,0.580078125000000,-0.269531250000000,-0.998046875000000,-0.335937500000000,0.921875000000000,0.921875000000000,-0.335937500000000,-0.998046875000000,-0.269531250000000,0.580078125000000,0.449218750000000,-0.121093750000000,-0.251953125000000,-0.0410156250000000,0.0292968750000000,-0.0234375000000000,0.0195312500000000,0.0800781250000000,0.0234375000000000,-0.0527343750000000,-0.0390625000000000,0.00976562500000000,0.0195312500000000,0.00195312500000000,-0.00195312500000000,0.00195312500000000 });


}
};

Expand Down
2 changes: 1 addition & 1 deletion ASICPhaseCalculator/Source/HTransformers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Defines the Hilbert transformers appropriate to use for each frequency band.
again, negated and in reverse order.
*/

namespace ASICPhaseCalculator
namespace PhaseCalculator
{
enum Band
{
Expand Down
4 changes: 2 additions & 2 deletions ASICPhaseCalculator/Source/OpenEphysLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <PluginInfo.h>
#include "ASICPhaseCalculator.h"
#include "PhaseCalculator.h"
#include <string>
#ifdef WIN32
#include <Windows.h>
Expand Down Expand Up @@ -50,7 +50,7 @@ extern "C" EXPORT int getPluginInfo(int index, Plugin::PluginInfo* info)
info->type = Plugin::PLUGIN_TYPE_PROCESSOR;
info->processor.name = "ASIC";
info->processor.type = Plugin::FilterProcessor;
info->processor.creator = &(Plugin::createProcessor<ASICPhaseCalculator::Node>);
info->processor.creator = &(Plugin::createProcessor<PhaseCalculator::Node>);
break;

default:
Expand Down
Loading

0 comments on commit b81fe51

Please sign in to comment.