Skip to content

Commit df31480

Browse files
author
jonnew
committed
Added Trode, Time, EphysInput. Does not work.
1 parent 6c9b142 commit df31480

6 files changed

Lines changed: 409 additions & 147 deletions

File tree

examples/src/DecoderTypes.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include "react/Event.h"
5+
6+
namespace decoder {
7+
namespace types {
8+
9+
using namespace react;
10+
11+
// Primatives
12+
using VoltageT = float;
13+
using LocationT = float;
14+
using SampleIndexT = uint64_t;
15+
using TimeT = double;
16+
17+
// Voltage
18+
template <typename D>
19+
using VoltageSource = EventSource<D, VoltageT>;
20+
21+
template <typename D, size_t N>
22+
using VoltateSourceVec = std::array<VoltageSource<D>, N>;
23+
24+
template <typename D>
25+
using Voltages = Events<D, VoltageT>;
26+
27+
//template <typename D, typename... Args>
28+
//using VoltagePack = std::tuple<Args...>;
29+
//
30+
//template <typename D, typename... Args>
31+
//using VoltagePacks = Events<D, std::tuple<Args...>>;
32+
33+
// LFP
34+
template <size_t N>
35+
using LFP = std::array<VoltageT, N>;
36+
37+
template <typename D, size_t N>
38+
using LFPs = Events<D, LFP<N>>;
39+
40+
// Spikes
41+
template <size_t L, size_t N>
42+
using SpikeWaveform = std::array<LFP<N>, L>;
43+
44+
template <typename D, size_t L, size_t N>
45+
using Spikes = Events<D, SpikeWaveform<L, N>>;
46+
47+
// Amplitudes
48+
template <size_t N>
49+
using Amplitude = std::array<VoltageT, N>;
50+
51+
template <typename D, size_t N>
52+
using Amplitudes = Signal<D, Amplitude<N>>;
53+
54+
// Position
55+
using Position = std::tuple<LocationT, LocationT, LocationT>;
56+
57+
template <typename D>
58+
using Positions = Events<D, Position>;
59+
60+
} // namespace types
61+
} // namespace decoder

examples/src/EphysInput.hpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#pragma once
2+
3+
#include "DecoderTypes.h"
4+
#include "react/Domain.h"
5+
6+
namespace decoder {
7+
8+
using namespace react;
9+
using namespace decoder::types;
10+
11+
namespace detail {
12+
13+
template <size_t N>
14+
struct VoltageTuple {
15+
typedef std::tuple<VoltageT> type;
16+
};
17+
18+
template <>
19+
struct VoltageTuple<1> {
20+
typedef std::tuple<VoltageT> type;
21+
};
22+
23+
template <>
24+
struct VoltageTuple<2> {
25+
typedef std::tuple<VoltageT, VoltageT> type;
26+
};
27+
28+
template <>
29+
struct VoltageTuple<4> {
30+
typedef std::tuple<VoltageT, VoltageT, VoltageT, VoltageT> type;
31+
};
32+
33+
template <>
34+
struct VoltageTuple<8> {
35+
typedef std::tuple<VoltageT,
36+
VoltageT,
37+
VoltageT,
38+
VoltageT,
39+
VoltageT,
40+
VoltageT,
41+
VoltageT,
42+
VoltageT> type;
43+
};
44+
45+
template <size_t N>
46+
using VTuple = typename VoltageTuple<N>::type;
47+
}
48+
49+
// Voltage Event streams to LFPs
50+
template <typename D, typename... Vs>
51+
class EphysInput {
52+
53+
static constexpr size_t N {sizeof...(Vs)};
54+
public:
55+
USING_REACTIVE_DOMAIN(D)
56+
57+
Events<D, detail::VTuple<N>> voltages; // Input
58+
LFPs<D,N> lfp = Transform(voltages, [](detail::VTuple<N> v, LFP<N> l) {
59+
60+
for (size_t i = 0; i < N; i++)
61+
l[i] = std::get<0>(v);
62+
63+
return l;
64+
65+
}); // Output
66+
67+
EphysInput(Time<D>& t, Vs& ...sources)
68+
: time(time)
69+
{
70+
voltages = Join(sources...);
71+
}
72+
73+
private:
74+
Time<D> &time;
75+
};
76+
77+
78+
template <typename D>
79+
using EphysInput1 = EphysInput<D, VoltageSource<D>>;
80+
81+
template <typename D>
82+
using EphysInput2 = EphysInput<D, VoltageSource<D>, VoltageSource<D>>;
83+
84+
template <typename D>
85+
using EphysInput4 = EphysInput<D,
86+
VoltageSource<D>,
87+
VoltageSource<D>,
88+
VoltageSource<D>,
89+
VoltageSource<D>>;
90+
91+
template <typename D>
92+
using EphysInput8 = EphysInput<D,
93+
VoltageSource<D>,
94+
VoltageSource<D>,
95+
VoltageSource<D>,
96+
VoltageSource<D>>;
97+
} // namespace decoder
98+

examples/src/SpikeDetect.cpp

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
#include "SpikeDetect.h"
1+
#include "Time.hpp"
2+
#include "Trode.hpp"
3+
#include "EphysInput.hpp"
4+
5+
#define MakeVoltSource(D)
6+
7+
using namespace decoder;
28

39
int main()
410
{
5-
REACTIVE_DOMAIN(D, sequential)
611

7-
const size_t N = 256;
12+
REACTIVE_DOMAIN(D, sequential)
813

9-
using raw_size_t = std::array<EventSource<D, double>, N>::size_type;
14+
const size_t M = 8;
1015

1116
// Time
1217
Time<D> time(30.0e3);
13-
std::cout << "Sample period: " << time.Ts << std::endl;
14-
15-
// 256 electrodes
16-
//std::vector<Electrode<D>> electrodes {256, time};
17-
18-
// 256 raw data sources, bandpass filters
19-
std::array<EventSource<D, double>, N> raw;
20-
21-
for (raw_size_t i = 0; i < N; i++)
22-
raw[i] = MakeEventSource<D, double>();
23-
24-
//BandPassFilter<D> filter(time, raw[0]);
25-
std::vector<BandPassFilter<D>> filters;
26-
for (auto &r :raw)
27-
filters.emplace_back(time, r);
28-
29-
//std::cout << "Filter N: " << filters.size() << std::endl;
30-
31-
// Are merged into 1 TT
32-
using Tetrode = NTrode<D,
33-
Events<D, double>,
34-
Events<D, double>,
35-
Events<D, double>,
36-
Events<D, double>>;
3718

38-
//Tetrode tt(time,
19+
std::vector<VoltageSource<D>> e;
20+
for (int i = 0; i < M; i++)
21+
e.emplace_back(MakeEventSource<D, VoltageT>());
22+
23+
EphysInput4<D> lfp(time, e[0], e[1], e[2], e[3]);
24+
25+
26+
27+
// //BandPassFilter<D> filter(time, raw[0]);
28+
// std::vector<BandPassFilter<D>> filters;
29+
// for (auto &r :raw)
30+
// filters.emplace_back(time, r);
31+
//
32+
// std::cout << "Sample period: " << time.Ts << std::endl;
33+
// //std::cout << "Filter N: " << filters.size() << std::endl;
34+
//
35+
// // Are merged into 1 TT
36+
// using Tetrode = NTrode<D,
37+
// Events<D, double>,
38+
// Events<D, double>,
39+
// Events<D, double>,
40+
// Events<D, double>>;
41+
//
42+
// Tetrode tt(time,
3943
// 0.01,
4044
// filters[0].Out,
4145
// filters[1].Out,
@@ -56,29 +60,26 @@ int main()
5660
// std::cout << "Current value: " << out << std::endl;
5761
//});
5862

59-
// /////////////////////
63+
///////////////////////
6064
// HARDWARE SIMULATION
61-
// This is simulating 100 transactions hardware
62-
for (int i = 0; i < 100; i++) {
63-
64-
std::random_device rd;
65-
std::mt19937 gen(rd());
66-
std::normal_distribution<> d(0, 1);
67-
68-
// Make a sample block coming from 4 contacts
69-
for (int j = 0; j < BLOCKSIZE; j++) {
70-
71-
// Graph update step
72-
DoTransaction<D>([&] {
73-
74-
// Increment sample counter
75-
time.NewSample();
76-
77-
// Make noise on all electrodes
78-
for (auto &r : raw)
79-
r << d(gen);
80-
});
81-
}
65+
//////////////////////
66+
std::random_device rd;
67+
std::mt19937 gen(rd());
68+
std::normal_distribution<> d(0, 1);
69+
70+
// Make a sample block coming from 4 contacts
71+
for (int j = 0; j < 1000; j++) {
72+
73+
// Graph update step
74+
DoTransaction<D>([&] {
75+
76+
// Increment sample counter
77+
time.NewSample();
78+
79+
// Make noise on all electrodes
80+
for (auto &electrode : e)
81+
electrode << d(gen);
82+
});
8283
}
8384

8485
return 0;

0 commit comments

Comments
 (0)