Skip to content
Snippets Groups Projects
Commit fa6a7e7b authored by Stuart Layton's avatar Stuart Layton
Browse files

updated the SignalGenerator to generate spikes of varying amplitudes and at a...

updated the SignalGenerator to generate spikes of varying amplitudes and at a lower rate. Minor incremental changes were made to other files
parent dd3654b5
No related branches found
No related tags found
No related merge requests found
...@@ -37,10 +37,10 @@ SignalGeneratorEditor::SignalGeneratorEditor (GenericProcessor* parentNode) ...@@ -37,10 +37,10 @@ SignalGeneratorEditor::SignalGeneratorEditor (GenericProcessor* parentNode)
int buttonWidth = 31; int buttonWidth = 31;
int buttonHeight = 19; int buttonHeight = 19;
for (int i = 0; i < 6; i++) for (int i = 0; i < 5; i++)
{ {
WaveformSelector* ws = new WaveformSelector(i); WaveformSelector* ws = new WaveformSelector(i);
ws->setBounds(15 + (buttonWidth)*i, 30, buttonWidth, buttonHeight); ws->setBounds(8 + (buttonWidth)*i, 30, buttonWidth, buttonHeight);
ws->addListener(this); ws->addListener(this);
waveformSelectors.add(ws); waveformSelectors.add(ws);
addAndMakeVisible(ws); addAndMakeVisible(ws);
...@@ -252,16 +252,16 @@ WaveformSelector::WaveformSelector(int type) : Button("Waveform") ...@@ -252,16 +252,16 @@ WaveformSelector::WaveformSelector(int type) : Button("Waveform")
neutralOver = ImageCache::getFromMemory (BinaryData::RadioButtons05_png, neutralOver = ImageCache::getFromMemory (BinaryData::RadioButtons05_png,
BinaryData::RadioButtons05_pngSize); BinaryData::RadioButtons05_pngSize);
} }
else if (type == 5) { // else if (type == 5) {
selected = ImageCache::getFromMemory (BinaryData::RadioButtons_selected05_png, // selected = ImageCache::getFromMemory (BinaryData::RadioButtons_selected05_png,
BinaryData::RadioButtons_selected05_pngSize); // BinaryData::RadioButtons_selected05_pngSize);
selectedOver= ImageCache::getFromMemory (BinaryData::RadioButtons_selected_over05_png, // selectedOver= ImageCache::getFromMemory (BinaryData::RadioButtons_selected_over05_png,
BinaryData::RadioButtons_selected_over05_pngSize); // BinaryData::RadioButtons_selected_over05_pngSize);
neutral = ImageCache::getFromMemory (BinaryData::RadioButtons_neutral05_png, // neutral = ImageCache::getFromMemory (BinaryData::RadioButtons_neutral05_png,
BinaryData::RadioButtons_neutral05_pngSize); // BinaryData::RadioButtons_neutral05_pngSize);
neutralOver = ImageCache::getFromMemory (BinaryData::RadioButtons05_png, // neutralOver = ImageCache::getFromMemory (BinaryData::RadioButtons05_png,
BinaryData::RadioButtons05_pngSize); // BinaryData::RadioButtons05_pngSize);
} // }
} }
......
...@@ -25,13 +25,14 @@ ...@@ -25,13 +25,14 @@
#include "SignalGenerator.h" #include "SignalGenerator.h"
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include "Visualization/SpikeObject.h"
SignalGenerator::SignalGenerator() SignalGenerator::SignalGenerator()
: GenericProcessor("Signal Generator"), : GenericProcessor("Signal Generator"),
defaultFrequency(10.0), defaultFrequency(10.0),
defaultAmplitude (100.0f), defaultAmplitude (100.0f),
nOut(5) nOut(5), previousPhase(1000), spikeDelay(-1)
{ {
...@@ -183,8 +184,8 @@ void SignalGenerator::process(AudioSampleBuffer &buffer, ...@@ -183,8 +184,8 @@ void SignalGenerator::process(AudioSampleBuffer &buffer,
sample = amplitude[j] * ((currentPhase[j] + phase[j]) / double_Pi - 1); sample = amplitude[j] * ((currentPhase[j] + phase[j]) / double_Pi - 1);
break; break;
case NOISE: case NOISE:
sample = amplitude[j] * (float(rand()) / float(RAND_MAX)-0.5f); // sample = amplitude[j] * (float(rand()) / float(RAND_MAX)-0.5f);
break; // break;
case SPIKE: case SPIKE:
sample = generateSpikeSample(amplitude[j], currentPhase[j], phase[j]); sample = generateSpikeSample(amplitude[j], currentPhase[j], phase[j]);
break; break;
...@@ -270,34 +271,36 @@ void SignalGenerator::process(AudioSampleBuffer &buffer, ...@@ -270,34 +271,36 @@ void SignalGenerator::process(AudioSampleBuffer &buffer,
} }
float SignalGenerator::generateSpikeSample(double amp, double phase, double noise){ float SignalGenerator::generateSpikeSample(double amp, double phase, double noise){
const int N_SAMP = 80;
double waveform[80] =
{ 1.0000, 1.0002, 1.0003, 1.0006, 1.0009, 1.0016, 1.0026, 1.0041, 1.0065, 1.0101, 1.0152, 1.0225, 1.0324, 1.0455, 1.0623, 1.0831, 1.1079,
1.1363, 1.1675, 1.2001, 1.2324, 1.2623, 1.2876, 1.3061, 1.3161, 1.3163, 1.3062, 1.2863, 1.2575, 1.2216, 1.1808, 1.1375, 1.0941, 1.0527,
1.0151, 0.9827, 0.9562, 0.9360, 0.9220, 0.9137, 0.9105, 0.9117, 0.9162, 0.9231, 0.9317, 0.9410, 0.9505, 0.9595, 0.9678, 0.9750, 0.9811,
0.9861, 0.9900, 0.9931, 0.9953, 0.9969, 0.9980, 0.9987, 0.9992, 0.9995, 0.9997, 0.9999, 0.9999, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000};
// We don't want to shift the waveform but scale it, and we don't want to scale
// the baseline, just the peak of the waveform
double scale[80] =
{ 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0001, 1.0004, 1.0009, 1.0020, 1.0044, 1.0091, 1.0175, 1.0317, 1.0540, 1.0863, 1.1295, 1.1827, 1.2420, 1.3011, 1.3521, 1.3867, 1.3990, 1.3867, 1.3521, 1.3011, 1.2420, 1.1827, 1.1295, 1.0863, 1.0540, 1.0317, 1.0175, 1.0091, 1.0044, 1.0020, 1.0009, 1.0004, 1.0001, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000};
// if the current phase is less than the previous phase we've probably wrapped and its time to select a new spike
int shift = -4500;//1000 + 32768; if (phase < previousPhase){
int sampIdx = 0; spikeIdx = rand()%5;
int gain = 3000;
spikeDelay = rand()%100;
}
previousPhase = phase;
int shift = -9500;//1000 + 32768;
int gain = 8000;
double r = ((rand() % 201) - 100) / 1000.0; // Generate random number between -.1 and .1 double r = ((rand() % 201) - 100) / 1000.0; // Generate random number between -.1 and .1
noise = r * noise / (double_Pi * 2); // Shrink the range of r based upon the value of noise noise = r * noise / (double_Pi * 2); // Shrink the range of r based upon the value of noise
sampIdx = (int) (phase / (2 * double_Pi) * (N_SAMP-1)); // bind between 0 and N_SAMP-1, too tired to figure out the proper math int sampIdx = (int) (phase / (2 * double_Pi) * (N_WAVEFORM_SAMPLES-1)); // bind between 0 and N_SAMP-1, too tired to figure out the proper math
//sampIdx = sampIdx + 8; //sampIdx = sampIdx + 8;
float sample = shift + gain * ( ( waveform[sampIdx] + noise ) * pow( scale[sampIdx], amp / 250.0 ) ) ; // Right now only sample from the 3rd waveform. I need to figure out a way to only sample from a single spike until the phase wraps
float baseline = shift + gain * SPIKE_WAVEFORMS[spikeIdx][1] ;
return sample;
float sample = shift + gain * ( SPIKE_WAVEFORMS[spikeIdx][sampIdx] + noise );// * pow( WAVEFORM_SCALE[sampIdx], amp / 200.0 ) ) ;
float dV = sample - baseline;
dV = dV * (1 + amp / 250);
sample = baseline + dV;
if (spikeDelay==0)
return sample;
else
return baseline;
} }
...@@ -88,6 +88,10 @@ private: ...@@ -88,6 +88,10 @@ private:
Array<double> phasePerSample; Array<double> phasePerSample;
Array<double> currentPhase; Array<double> currentPhase;
double previousPhase;
int spikeIdx;
int spikeDelay;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SignalGenerator); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SignalGenerator);
}; };
......
...@@ -87,5 +87,73 @@ void generateEmptySpike(SpikeObject *s, int nChannels); ...@@ -87,5 +87,73 @@ void generateEmptySpike(SpikeObject *s, int nChannels);
void printSpike(SpikeObject *s); void printSpike(SpikeObject *s);
static const int N_WAVEFORM_SAMPLES = 120;
static const double SPIKE_WAVEFORMS[5][N_WAVEFORM_SAMPLES] =
{
{ 1.0000, 1.0008, 1.0016, 1.0023, 1.0030, 1.0030, 1.0031, 1.0031, 1.0032, 1.0035, 1.0038, 1.0041,
1.0053, 1.0074, 1.0095, 1.0116, 1.0167, 1.0235, 1.0303, 1.0370, 1.0478, 1.0596, 1.0713, 1.0831,
1.1006, 1.1183, 1.1361, 1.1544, 1.1768, 1.1992, 1.2217, 1.2415, 1.2550, 1.2685, 1.2820, 1.2881,
1.2853, 1.2826, 1.2798, 1.2708, 1.2579, 1.2451, 1.2322, 1.2174, 1.2019, 1.1865, 1.1710, 1.1569,
1.1428, 1.1288, 1.1149, 1.1031, 1.0912, 1.0793, 1.0681, 1.0589, 1.0496, 1.0404, 1.0318, 1.0240,
1.0163, 1.0085, 1.0015, 0.9950, 0.9886, 0.9821, 0.9761, 0.9702, 0.9643, 0.9585, 0.9534, 0.9484,
0.9434, 0.9385, 0.9348, 0.9311, 0.9273, 0.9239, 0.9215, 0.9191, 0.9166, 0.9142, 0.9118, 0.9094,
0.9070, 0.9048, 0.9028, 0.9008, 0.8987, 0.8968, 0.8948, 0.8928, 0.8908, 0.8893, 0.8878, 0.8862,
0.8847, 0.8829, 0.8811, 0.8794, 0.8777, 0.8764, 0.8751, 0.8738, 0.8727, 0.8719, 0.8710, 0.8701,
0.8699, 0.8704, 0.8708, 0.8713, 0.8720, 0.8729, 0.8738, 0.8747, 0.8755, 0.8763, 0.8772, 0.8780},
{ 1.0000, 0.9998, 0.9996, 0.9995, 0.9993, 0.9996, 0.9999, 1.0002, 1.0007, 1.0014, 1.0021, 1.0028,
1.0041, 1.0062, 1.0083, 1.0103, 1.0154, 1.0220, 1.0286, 1.0353, 1.0470, 1.0599, 1.0729, 1.0858,
1.1072, 1.1288, 1.1505, 1.1724, 1.1963, 1.2201, 1.2439, 1.2634, 1.2724, 1.2813, 1.2903, 1.2911,
1.2822, 1.2733, 1.2643, 1.2506, 1.2339, 1.2172, 1.2006, 1.1841, 1.1678, 1.1514, 1.1351, 1.1222,
1.1096, 1.0970, 1.0846, 1.0743, 1.0639, 1.0536, 1.0437, 1.0355, 1.0272, 1.0190, 1.0113, 1.0044,
0.9975, 0.9906, 0.9847, 0.9794, 0.9742, 0.9689, 0.9645, 0.9603, 0.9561, 0.9520, 0.9485, 0.9451,
0.9417, 0.9384, 0.9356, 0.9327, 0.9299, 0.9272, 0.9253, 0.9233, 0.9213, 0.9191, 0.9163, 0.9136,
0.9109, 0.9086, 0.9067, 0.9047, 0.9028, 0.9009, 0.8991, 0.8972, 0.8954, 0.8940, 0.8927, 0.8913,
0.8900, 0.8889, 0.8878, 0.8867, 0.8857, 0.8851, 0.8846, 0.8840, 0.8835, 0.8830, 0.8825, 0.8821,
0.8823, 0.8830, 0.8838, 0.8846, 0.8858, 0.8872, 0.8885, 0.8899, 0.8918, 0.8937, 0.8957, 0.8977},
{ 1.0000, 1.0001, 1.0003, 1.0004, 1.0005, 1.0003, 1.0002, 1.0000, 0.9997, 0.9992, 0.9988, 0.9983,
0.9982, 0.9987, 0.9991, 0.9995, 1.0025, 1.0069, 1.0114, 1.0158, 1.0252, 1.0356, 1.0461, 1.0566,
1.0732, 1.0900, 1.1068, 1.1239, 1.1425, 1.1612, 1.1799, 1.1957, 1.2043, 1.2129, 1.2215, 1.2241,
1.2194, 1.2147, 1.2100, 1.2006, 1.1881, 1.1757, 1.1632, 1.1502, 1.1370, 1.1237, 1.1105, 1.0990,
1.0876, 1.0761, 1.0650, 1.0558, 1.0467, 1.0376, 1.0290, 1.0218, 1.0146, 1.0075, 1.0009, 0.9953,
0.9896, 0.9839, 0.9787, 0.9739, 0.9690, 0.9642, 0.9599, 0.9559, 0.9518, 0.9478, 0.9442, 0.9408,
0.9373, 0.9339, 0.9308, 0.9277, 0.9246, 0.9215, 0.9188, 0.9160, 0.9132, 0.9107, 0.9087, 0.9066,
0.9045, 0.9026, 0.9009, 0.8991, 0.8973, 0.8959, 0.8945, 0.8932, 0.8919, 0.8907, 0.8895, 0.8883,
0.8872, 0.8861, 0.8850, 0.8839, 0.8829, 0.8824, 0.8820, 0.8815, 0.8813, 0.8818, 0.8822, 0.8827,
0.8834, 0.8844, 0.8853, 0.8863, 0.8872, 0.8881, 0.8890, 0.8899, 0.8910, 0.8921, 0.8932, 0.8943},
{ 1.0000, 1.0000, 1.0001, 1.0001, 1.0002, 1.0002, 1.0002, 1.0002, 1.0001, 1.0000, 0.9999, 0.9997,
1.0000, 1.0008, 1.0016, 1.0024, 1.0053, 1.0095, 1.0137, 1.0179, 1.0261, 1.0353, 1.0444, 1.0536,
1.0685, 1.0836, 1.0987, 1.1139, 1.1295, 1.1452, 1.1609, 1.1740, 1.1805, 1.1870, 1.1936, 1.1952,
1.1909, 1.1866, 1.1823, 1.1745, 1.1645, 1.1545, 1.1445, 1.1335, 1.1221, 1.1108, 1.0995, 1.0894,
1.0794, 1.0694, 1.0596, 1.0514, 1.0433, 1.0351, 1.0274, 1.0208, 1.0142, 1.0077, 1.0016, 0.9963,
0.9910, 0.9858, 0.9812, 0.9771, 0.9731, 0.9690, 0.9657, 0.9627, 0.9597, 0.9567, 0.9541, 0.9515,
0.9489, 0.9464, 0.9440, 0.9417, 0.9393, 0.9371, 0.9352, 0.9333, 0.9314, 0.9297, 0.9282, 0.9267,
0.9253, 0.9238, 0.9224, 0.9210, 0.9196, 0.9184, 0.9171, 0.9159, 0.9146, 0.9139, 0.9131, 0.9124,
0.9117, 0.9111, 0.9105, 0.9100, 0.9094, 0.9091, 0.9087, 0.9084, 0.9082, 0.9081, 0.9080, 0.9080,
0.9080, 0.9082, 0.9083, 0.9085, 0.9089, 0.9095, 0.9100, 0.9106, 0.9116, 0.9127, 0.9138, 0.9148},
{ 1.0000, 0.9997, 0.9994, 0.9990, 0.9987, 0.9982, 0.9977, 0.9972, 0.9969, 0.9972, 0.9975, 0.9978,
0.9987, 1.0002, 1.0017, 1.0032, 1.0063, 1.0103, 1.0144, 1.0184, 1.0251, 1.0325, 1.0400, 1.0474,
1.0574, 1.0676, 1.0777, 1.0880, 1.0996, 1.1111, 1.1227, 1.1332, 1.1410, 1.1489, 1.1567, 1.1612,
1.1617, 1.1622, 1.1627, 1.1586, 1.1516, 1.1446, 1.1375, 1.1282, 1.1182, 1.1082, 1.0981, 1.0885,
1.0789, 1.0693, 1.0598, 1.0520, 1.0442, 1.0364, 1.0290, 1.0227, 1.0165, 1.0103, 1.0046, 0.9998,
0.9950, 0.9901, 0.9859, 0.9821, 0.9784, 0.9746, 0.9715, 0.9686, 0.9658, 0.9629, 0.9603, 0.9578,
0.9553, 0.9528, 0.9505, 0.9481, 0.9458, 0.9435, 0.9412, 0.9390, 0.9367, 0.9347, 0.9331, 0.9314,
0.9298, 0.9285, 0.9275, 0.9265, 0.9255, 0.9247, 0.9239, 0.9232, 0.9224, 0.9218, 0.9212, 0.9206,
0.9200, 0.9197, 0.9194, 0.9190, 0.9187, 0.9184, 0.9181, 0.9179, 0.9177, 0.9178, 0.9179, 0.9180,
0.9184, 0.9189, 0.9194, 0.9199, 0.9207, 0.9215, 0.9224, 0.9233, 0.9240, 0.9247, 0.9254, 0.9261}
};
static const double WAVEFORM_SCALE[N_WAVEFORM_SAMPLES] =
{
1.0027, 1.0035, 1.0045, 1.0057, 1.0073, 1.0093, 1.0117, 1.0146, 1.0181, 1.0223, 1.0273, 1.0331,
1.0398, 1.0474, 1.0559, 1.0652, 1.0754, 1.0862, 1.0976, 1.1092, 1.1208, 1.1321, 1.1429, 1.1526,
1.1612, 1.1681, 1.1733, 1.1764, 1.1774, 1.1763, 1.1730, 1.1678, 1.1607, 1.1520, 1.1420, 1.1310,
1.1194, 1.1075, 1.0956, 1.0840, 1.0729, 1.0625, 1.0529, 1.0442, 1.0365, 1.0298, 1.0240, 1.0190,
1.0149, 1.0115, 1.0087, 1.0065, 1.0046, 1.0031, 1.0019, 1.0008, 0.9998, 0.9988, 0.9978, 0.9966,
0.9953, 0.9937, 0.9919, 0.9897, 0.9872, 0.9842, 0.9808, 0.9769, 0.9726, 0.9679, 0.9629, 0.9575,
0.9519, 0.9462, 0.9406, 0.9351, 0.9300, 0.9253, 0.9213, 0.9180, 0.9155, 0.9140, 0.9135, 0.9140,
0.9155, 0.9180, 0.9213, 0.9253, 0.9300, 0.9351, 0.9406, 0.9462, 0.9519, 0.9574, 0.9628, 0.9678,
0.9725, 0.9768, 0.9806, 0.9840, 0.9869, 0.9894, 0.9915, 0.9933, 0.9948, 0.9959, 0.9969, 0.9976,
0.9982, 0.9987, 0.9990, 0.9993, 0.9995, 0.9996, 0.9997, 0.9998, 0.9999, 0.9999, 0.9999, 1.0000,
};
#endif //SPIKEOBJECT_H_ #endif //SPIKEOBJECT_H_
\ No newline at end of file
...@@ -171,7 +171,7 @@ void SpikePlot::setPosition(int x, int y, double w, double h){ ...@@ -171,7 +171,7 @@ void SpikePlot::setPosition(int x, int y, double w, double h){
void SpikePlot::initLimits(){ void SpikePlot::initLimits(){
for (int i=0; i<nChannels; i++) for (int i=0; i<nChannels; i++)
{ {
limits[i][0] = 2209;//-1*pow(2,11); limits[i][0] = 1209;//-1*pow(2,11);
limits[i][1] = 11059;//pow(2,14)*1.6; limits[i][1] = 11059;//pow(2,14)*1.6;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment