Пример #1
0
    def deserialize_eeg_wifi(self, eeg: np.ndarray, ids: np.ndarray,
                             context: Dict[str, Any]) -> np.ndarray:
        """From signed 24-bits integer to signed 32-bits integer by channels.

        The `Cyton data format <https://docs.openbci.com/docs/02Cyton/CytonDataFormat>`_
        says that only can send packages of 33 bits, when a Daisy board is
        attached these same packages will be sent at double speed in favor to
        keep the desired sample rate for 16 channels.

        Parameters
        ----------
        eeg
            Numpy array in signed 24-bits integer (`8, LENGTH`)
        ids
            List of IDs for eeg data.
        context
            Information from the acquisition side useful for deserializing and
            that will be packaged back in the stream.

        Returns
        -------
        eeg_data
            EEG data in microvolts, signed 32-bits integer, (`CHANNELS, LENGTH`),
            if there is a Daisy board `CHANNELS` is 16, otherwise is 8.
        """

        eeg_data = np.array([[
            rawutil.unpack('>u', bytes(ch))[0]
            for ch in row.reshape(-1, 3).tolist()
        ] for row in eeg])
        eeg_data = eeg_data * self.scale_factor_eeg

        if context['daisy']:

            # # If offset, the pair index condition must change
            if np.array(self.offset[0]).any():
                eeg_data = np.concatenate([[self.offset[0]], eeg_data], axis=0)
                ids = np.concatenate([[self.offset[1]], ids], axis=0)
                # pair = not pair

            if ids[0] != ids[1]:
                eeg_data = np.delete(eeg_data, 0, axis=0)
                ids = np.delete(ids, 0, axis=0)

            # if not pair dataset, create an offeset
            if eeg_data.shape[0] % 2:
                self.offset = eeg_data[-1], ids[-1]
                eeg_data = np.delete(eeg_data, -1, axis=0)
                ids = np.delete(ids, -1, axis=0)
            else:
                self.offset = None, None

            return eeg_data.reshape(-1, 16)

        return eeg_data
Пример #2
0

# create a socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# bind the socket to the specified ip address and port
sock.bind((UDP_IP, UDP_PORT))
print ("F1 Telemetry ready")
print ("Listening on " + UDP_IP + ":" + str(UDP_PORT))




print("ses_t,lap_t,lap_d,ses_d,speed,steer,gear,rpm,fuel,fuel_cap,brake_temp,tyre_p_rl,tyre_p_rr,tyre_p_fl,tyre_p_fr,tyre_t_rl,tyre_t_rr,tyre_t_fl,tyre_t_fr")
while True:
    data, address = sock.recvfrom(PACKET_SIZE)
    ses_t, = rawutil.unpack('<f',data[0:4])
    lap_t, = rawutil.unpack('<f',data[4:8])
    lap_d, = rawutil.unpack('<f',data[8:12])
    ses_d, = rawutil.unpack('<f',data[0:4])
    speed, = rawutil.unpack('<f',data[28:32])
    steer, = rawutil.unpack('<f',data[120:124])
    gear, = rawutil.unpack('<f',data[132:136])
    rpm, = rawutil.unpack('<f',data[148:152])
    fuel, = rawutil.unpack('<f',data[180:184])
    fuel_cap, = rawutil.unpack('<f',data[184:188])
    brake_temp, = rawutil.unpack('<f',data[204:208])
    tyre_p_rl, = rawutil.unpack('<f',data[220:224])
    tyre_p_rr, = rawutil.unpack('<f',data[224:228])
    tyre_p_fl, = rawutil.unpack('<f',data[228:232])
    tyre_p_fr, = rawutil.unpack('<f',data[232:236])
    tyre_t_rl, = rawutil.unpack('<b',data[304:305])
Пример #3
0
wf = wave.open(r'Ses01F_impro01_F000_S1.wav', 'rb')

fp=open(r'1.wav','rb')
nframes = wf.getnframes()
framerate = wf.getframerate()
str_data = wf.readframes(nframes)
sample_width = wf.getsampwidth()
channel = wf.getnchannels()
bytesPerSample = int(len(str_data) / nframes / channel)
# chunk=fp.read(bytesPerSample*nframes)
a=[]
for i in range(nframes):
    j = i * channel
    bytess = str_data[j * bytesPerSample:j * bytesPerSample + bytesPerSample]
    # value = struct.unpack('<h',bytess)[0]
    value = rawutil.unpack('<1u', bytess)[0]
    a.append(value)
    # print(value)
a2 = np.array(a, dtype='int32')
mean = np.mean(a2)
std = np.std(a2)
a2 = (a2 - mean) / std
a2 = a2.astype(np.float16)
print(a2.dtype)
wf.close()
time = np.arange(0, nframes)*(1.0/framerate)
plt.subplot(311)
plt.plot(time, a2, c='r')
plt.show()
#
# print("channel:",channel)
Пример #4
0
    def deserialize_eeg_serial(self, eeg: np.ndarray, ids: np.ndarray,
                               context: Dict[str, Any]) -> np.ndarray:
        """From signed 24-bits integer to signed 32-bits integer by channels.

        The `Cyton data format <https://docs.openbci.com/docs/02Cyton/CytonDataFormat>`_
        says that only can send packages of 33 bits, over serial (RFduino) this
        limit is absolute, when a Daisy board is attached these same amount of
        packages will be sent, in this case, the data must be distributed and
        interpolated in order to complete the sample rate.

        Parameters
        ----------
        eeg
            Numpy array in signed 24-bits integer (`8, LENGTH`)
        ids
            List of IDs for eeg data.
        context
            Information from the acquisition side useful for deserializing and
            that will be packaged back in the stream.

        Returns
        -------
        eeg_data
            EEG data in microvolts, signed 32-bits integer, (`CHANNELS, LENGTH`),
            if there is a Daisy board `CHANNELS` is 16, otherwise is 8.
        """

        eeg_data = np.array([[
            rawutil.unpack('>u', bytes(ch))[0]
            for ch in row.reshape(-1, 3).tolist()
        ] for row in eeg])
        eeg_data = eeg_data * self.scale_factor_eeg

        if context['daisy']:

            even = not ids[0] % 2

            # If offset, the even index condition must change
            if np.array(self.offset[0]).any():
                eeg_data = np.concatenate([[self.offset[0]], eeg_data], axis=0)
                ids = np.concatenate([[self.offset[1]], ids], axis=0)
                even = not even

            # if not even dataset, create an offset
            if eeg_data.shape[0] % 2:
                self.offset = eeg_data[-1], ids[-1]
                eeg_data = np.delete(eeg_data, -1, axis=0)
                ids = np.delete(ids, -1, axis=0)

            # Data can start with a even or odd id
            if even:
                board = eeg_data[::2]
                daisy = eeg_data[1::2]
            else:
                daisy = eeg_data[::2]
                board = eeg_data[1::2]

            board = np.array([
                np.interp(np.arange(0, p.shape[0], 0.5), np.arange(p.shape[0]),
                          p) for p in board.T
            ]).T
            daisy = np.array([
                np.interp(np.arange(0, p.shape[0], 0.5), np.arange(p.shape[0]),
                          p) for p in daisy.T
            ]).T

            eeg = np.concatenate([np.stack(board), np.stack(daisy)], axis=1)

        else:
            eeg = eeg_data

        return eeg