|
@@ -12,6 +12,7 @@ class NeuracleDataClient:
|
|
|
def __init__(self, n_channel=9, samplerate=1000, host='localhost', port=8712, buffer_len=1):
|
|
|
self.n_channel = n_channel
|
|
|
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
|
|
|
+ self.chunk_size = int(self.UPDATE_INTERVAL * samplerate * self.BYTES_PER_NUM * n_channel)
|
|
|
self.buffer = []
|
|
|
self.max_buffer_length = int(buffer_len * samplerate)
|
|
|
self._host = host
|
|
@@ -47,7 +48,7 @@ class NeuracleDataClient:
|
|
|
continue
|
|
|
|
|
|
# unpack data
|
|
|
- data = self._unpack_data()
|
|
|
+ data = self._unpack_data(data)
|
|
|
|
|
|
# do highpass (exclude stim channel)
|
|
|
data[:, :-1] = self.filter.filter_incoming(data[:, :-1])
|
|
@@ -62,8 +63,7 @@ class NeuracleDataClient:
|
|
|
self.lock.release()
|
|
|
|
|
|
def _unpack_data(self, bytes_data):
|
|
|
- total_data = b''.join(bytes_data)
|
|
|
- byte_data = bytearray(total_data)
|
|
|
+ byte_data = bytearray(bytes_data)
|
|
|
if len(byte_data) % 4 != 0:
|
|
|
raise ValueError
|
|
|
data = np.frombuffer(byte_data, dtype='<f')
|
|
@@ -98,7 +98,7 @@ class NeuracleDataClient:
|
|
|
|
|
|
class OnlineHPFilter:
|
|
|
def __init__(self, freq=1, fs=1000):
|
|
|
- self.sos = signal.butter(4, freq, btype='hp', fs=fs, output='sos')
|
|
|
+ self.sos = signal.butter(2, freq, btype='hp', fs=fs, output='sos')
|
|
|
self._z = None
|
|
|
|
|
|
def filter_incoming(self, data):
|