-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathECGDataSet.java
238 lines (211 loc) · 5.37 KB
/
ECGDataSet.java
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
/**
* class ECGDataSet - describes a set of data gathered from a single channel
*
* @author Dakota Williams
*/
public class ECGDataSet implements Undoable {
private List<double[]> set;
private boolean bad;
/**
* Constructor - initializes an ECGDataSet
*/
public ECGDataSet() {
set = new ArrayList<double[]>();
}
/**
* isBad - is the bad lead flag set?
*
* @return true if the bad lead flag is set, false otherwise
*/
public boolean isBad() {return bad;}
/**
* setBad - sets the bad lead flag
*
* @param b which value to set the bad lead flag to
*/
public void setBad(boolean b) {bad = b;}
/**
* addTuple - adds an entry to the end of the dataset
*
* @param x the time at which the sample occurs
* @param y the value of the sample
*/
public void addTuple(double x, double y) {
set.add(new double[] {x, y});
}
/**
* getAt - gets the nth sample
*
* @return a 2-element array containing: [0] - the time
* [1] - the value
*/
public double[] getAt(int index) {
return set.get(index);
}
/**
* size - gets the number of samples in the set
*
* @return the number of samples in the set
*/
public int size() {
return set.size();
}
/**
* clone - deep copy of the dataset
*
* @return the new dataset
*/
public Object clone() {
ECGDataSet eds = new ECGDataSet();
eds.set = new ArrayList<double[]>();
for(int i = 0; i < this.set.size(); i++) {
eds.set.add(new double[] {(double)this.set.get(i)[0],
(double)this.set.get(i)[1]});
}
eds.bad = this.bad;
return eds;
}
/**
* copyFrom - make this a shallow copy of e
*
* @param e the thing to copy
*/
public void copyFrom(ECGDataSet e) {
this.set = new ArrayList<double[]>(e.set);
this.bad = e.bad;
}
/**
* toArray - creates an array representation of the dataset
*
* @return a 2xN matrix where the array of arrays is the x and y values
*/
public double[][] toArray() {
double[][] ret = new double[2][set.size()];
for(int j = 0; j < set.size(); j++) {
//do a transpose
ret[0][j] = set.get(j)[0];
ret[1][j] = set.get(j)[1];
}
return ret;
}
/**
* subset - gets a subset of this dataset
*
* @param start the time before the first element in the subset
* @param end the time after the last element in the subset
* @return the new dataset that contains the subset
*/
public ECGDataSet subset(double start, double end) {
ECGDataSet newSet = new ECGDataSet();
for(int i = 0; i < this.set.size(); i++) {
if(this.set.get(i)[0] >= start && this.set.get(i)[0] < end) {
newSet.set.add(this.set.get(i));
}
}
return newSet;
}
/**
* indexBefore - gets the index before a certain time
*
* @param time the time to find
* @return the index of an element directly before that time
*/
public int indexBefore(double time) {
int min = 0;
int max = set.size() - 1;
while(max >= min) {
int mid = (max + min)/2;
if((set.get(mid)[0] <= time) &&
(set.get(mid+1)[0] == time)) {
return mid+1;
}
else if(set.get(mid)[0] < time) {
min = mid+1;
}
else {
max = mid-1;
}
}
return set.size() - 1;
}
/**
* detrend - applies a polynomial fit detrending on the dataset
*
* @param detrendPolynomial the degree of the fitting polynomial
*/
public void detrend(int detrendPolynomial) {
Filters.detrend(set, detrendPolynomial);
}
/**
* sgolayfilt - applies a savitzky-golay filter to the dataset
*
* @param left number of elements to the left to sample
* @param right number of elements to the right to sample
* @param degree the degree of the polynomial to use
*/
public void sgolayfilt(int left, int right, int degree) {
Filters.sgolayfilt(set, left, right, degree);
}
/**
* lowpassfilt - applies a low pass filter to the dataset
*
* @param freq the frequency threshold
*/
public void lowpassfilt(double freq) {
Filters.lowpassfilt(set, freq);
}
/**
* highpassfilt - applies a high pass filter to the dataset
*
* @param freq the frequency threshold
*/
public void highpassfilt(double freq) {
Filters.highpassfilt(set, freq);
}
/**
* highpassfftfilt - applies a fft filter to the dataset
*
* @param lowfreq the low frequency cut off
* @param highfreq the high frequency cut off
*/
public void highpassfftfilt(double lowfreq, double highfreq) {
Filters.highpassfftfilt(set, lowfreq, highfreq);
}
/**
* waveletfilt - applies a wavelet filter to the dataset
*
* @param threshold the threshold value to cut off
*/
public void waveletfilt(double threshold, int wavelet, int level) {
Filters.waveletfilt(set, threshold, wavelet, level);
}
/**
* constofffilt - applies a constant offset to the dataset
*
* @param offset the offset value
*/
public void constofffilt(double offset) {
Filters.constofffilt(set, offset);
}
/**
* butterworthfilt - applies a butterworth filter to the dataset
*
* @param mode lpf, hpf, bpf
* @param rate the sample rate
* @param freq the cutoff frequency
* @param gain the signal gain
* @param order the order of the butterworth filter
*/
public void butterworthfilt(int mode, double rate, double freq, int order) {
Filters.butterworthfilt(set, mode, rate, freq, order);
}
public void harmonicDetrend() {
Filters.harmonicDetrend(set);
}
public void medianDetrend() {
Filters.medianDetrend(set);
}
}