forked from amborsa10/lfpRatiometer-Basic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrtxi-lfpRatiometer.cpp
More file actions
159 lines (134 loc) · 4.5 KB
/
rtxi-lfpRatiometer.cpp
File metadata and controls
159 lines (134 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <rtxi-lfpRatiometer.h>
using namespace std;
extern "C" Plugin::Object *createRTXIPlugin(void){
return new rtxilfpRatiometer();
}
static DefaultGUIModel::variable_t vars[] = {
{
"Time Window (s)", "Time Window (s)",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE
},
{
"Sampling Rate (Hz)", "Sampling Rate (Hz)",
DefaultGUIModel::STATE | DefaultGUIModel::DOUBLE,
},
{
"LF Lower Bound", "LF Lower Bound",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"LF Upper Bound", "LF Upper Bound",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"HF Lower Bound", "HF Lower Bound",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"HF Upper Bound", "HF Upper Bound",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"input_LFP", "Input LFP",
DefaultGUIModel::INPUT | DefaultGUIModel::DOUBLE,
},
{
"ratio", "Output LFP Power Ratio",
DefaultGUIModel::OUTPUT | DefaultGUIModel::DOUBLE,
},
{
"LF Power", "Power in LF Band",
DefaultGUIModel::OUTPUT | DefaultGUIModel::DOUBLE,
},
{
"HF Power", "Power in HF Band",
DefaultGUIModel::OUTPUT | DefaultGUIModel::DOUBLE,
}
};
static size_t num_vars = sizeof(vars) / sizeof(DefaultGUIModel::variable_t);
// defining what's in the object's constructor
// sampling set by RT period
rtxilfpRatiometer::rtxilfpRatiometer(void) :
DefaultGUIModel("lfpRatiometer with Custom GUI", ::vars, ::num_vars),
period(((double)RT::System::getInstance()->getPeriod())*1e-9), // grabbing RT period
sampling(1.0/period), // calculating RT sampling rate
lfpratiometer(N, sampling) // constructing lfpRatiometer object
{
setWhatsThis("<p><b>lfpRatiometer:</b><br>Given an input, this module calculates the LF/HF ratio over a specified causal time window.</p>");
DefaultGUIModel::createGUI(vars, num_vars);
customizeGUI();
update(INIT);
refresh();
QTimer::singleShot(0, this, SLOT(resizeMe()));
}
// defining what's in the object's destructor
rtxilfpRatiometer::~rtxilfpRatiometer(void) { }
// real-time RTXI function
void rtxilfpRatiometer::execute(void) {
// push new time series reading to lfpRatiometer
lfpratiometer.pushTimeSample(input(0));
// calculate LF/HF ratio
lfpratiometer.calcRatio();
// put the LF/HF ratio into the output
output(0) = lfpratiometer.getRatio();
output(1) = lfpratiometer.getLFpower();
output(2) = lfpratiometer.getHFpower();
}
// update function (not running in real time)
void rtxilfpRatiometer::update(DefaultGUIModel::update_flags_t flag)
{
switch (flag) {
case INIT:
setParameter("Time Window (s)", sampling/N);
setState("Sampling Rate (Hz)", sampling);
// get bounds from lfpratiometer object
setParameter("LF Lower Bound", lfpratiometer.getFreqBounds()[0]);
setParameter("LF Upper Bound", lfpratiometer.getFreqBounds()[1]);
setParameter("HF Lower Bound", lfpratiometer.getFreqBounds()[2]);
setParameter("HF Upper Bound", lfpratiometer.getFreqBounds()[3]);
break;
case MODIFY:
// defining parameters needed for constructor
period = ((double)RT::System::getInstance()->getPeriod())*1e-9;
sampling = 1.0/period;
setState("Sampling Rate (Hz)", sampling); // updating GUI
N = (int) (getParameter("Time Window (s)").toDouble() * sampling);
// making new FFT plan
lfpratiometer.changeFFTPlan(N, sampling);
// setting frequency bounds based on user input
lfpratiometer.setRatioParams(getParameter("LF Lower Bound").toDouble(),
getParameter("LF Upper Bound").toDouble(),
getParameter("HF Lower Bound").toDouble(),
getParameter("HF Upper Bound").toDouble());
// setting DFT windowing function choice
if (windowShape->currentIndex() == 0) {
lfpratiometer.window_rect();
}
else if (windowShape->currentIndex() == 1) {
lfpratiometer.window_hamming();
}
// clearing time series
lfpratiometer.clrTimeSeries();
break;
case UNPAUSE:
break;
case PAUSE:
lfpratiometer.clrTimeSeries();
break;
case PERIOD:
break;
default:
break;
}
}
// RTXI's customizeGUI function
void rtxilfpRatiometer::customizeGUI(void)
{
QGridLayout* customlayout = DefaultGUIModel::getLayout();
// adding dropdown menu for choosing FFT window shape
windowShape = new QComboBox;
windowShape->insertItem(1, "Rectangular");
windowShape->insertItem(2, "Hamming");
customlayout->addWidget(windowShape, 2, 0);
setLayout(customlayout);
}