MindRove / MindRoveSDK

Apache License 2.0
5 stars 4 forks source link

8 Channel EMG A/D conversion of Mindrove sdk #7

Open adhera79 opened 1 year ago

adhera79 commented 1 year ago

I am a new Mindrove user and I am trying to retrieve EMG data by following a general code from here (https://docs.mindrove.com/GettingStarted.html). I tried to convert the EMG data by multiplying it with the LSB (0.045 uV (gain: 12x)) as the user manual pdf instructed. However, the value is still too high compared to the obtained EMG data from the Mindrove application.

Here is the code (python):


import keyboard
import time
start = time.time()

#initialize the Mindrove WiFi Board
from mindrove.board_shim import BoardShim, MindRoveInputParams, BoardIds

BoardShim.enable_board_logger()
params = MindRoveInputParams()
board_id = BoardIds.MINDROVE_WIFI_BOARD
board_shim = BoardShim(board_id, params)

board_shim.prepare_session() #prepare the connection
board_shim.start_stream()

emg_channels = BoardShim.get_emg_channels(board_id)
sampling_rate= 1 

time_stamp = BoardShim.get_timestamp_channel(board_id)

window_size = 1 #second
num_points = window_size * sampling_rate
board_shim.get_board_data(num_points)

conv_gain = 0.045 #LSB

while True:
    data = board_shim.get_board_data(num_points) #option to obtain data and delete it from the source buffer

    #specifically save the desired sensor data using indices
    emg_data = data[emg_channels] #indices of emg_channels
    time_data= data[time_stamp] #indices of emg_channels
    Ch1 = ("".join(str(emg_data[0])[1:-2]))
    Ch2 = ("".join(str(emg_data[1])[1:-2]))
    Ch3 = ("".join(str(emg_data[2])[1:-2]))
    Ch4 = ("".join(str(emg_data[3])[1:-2]))
    Ch5 = ("".join(str(emg_data[4])[1:-2]))
    Ch6 = ("".join(str(emg_data[5])[1:-2]))
    Ch7 = ("".join(str(emg_data[6])[1:-2]))
    Ch8 = ("".join(str(emg_data[7])[1:-2]))

    if len(time_data != 0):
        Ch1 = round(float(Ch1) * conv_gain,3)
        Ch2 = round(float(Ch2) * conv_gain,3)
        Ch3 = round(float(Ch3) * conv_gain,3)
        Ch4 = round(float(Ch4) * conv_gain,3)
        Ch5 = round(float(Ch5) * conv_gain,3)
        Ch6 = round(float(Ch6) * conv_gain,3)
        Ch7 = round(float(Ch7) * conv_gain,3)
        Ch8 = round(float(Ch8) * conv_gain,3)

        print(Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8)

    if keyboard.is_pressed("q"):
        board_shim.stop_stream()
        board_shim.release_all_sessions()
        print("duration = " + str(time.time()-start))

Python output (each channel separated by comma): 87258.24, 152524.215, 847.53, 38383.245, 45225.585, 77026.59, 74496.645, 70507.44 87256.71, 152524.845, 847.08, 38381.355, 45217.62, 77015.925, 74484.225, 70505.01

App output: <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

CH1 | CH2 | CH3 | CH4 | CH5 | CH6 | CH7 | CH8 -- | -- | -- | -- | -- | -- | -- | -- 4.276569 | 59.98839 | 75.23183 | 119.097 | 153.4249 | 126.8074 | 188.6178 | 288.7419 1.82205 | 101.1675 | 58.68967 | 101.2067 | 175.587 | 144.8782 | 323.3315 | 213.8937 -6.86391 | 161.019 | 72.55855 | 65.20289 | 91.98467 | -10.2786 | 246.9481 | 72.37443 -128.759 | -27.3326 | -99.151 | -144.565 | -251.1 | -379.714 | -249.393 | -229.146 -155.495 | -341.237 | -254.567 | -321.961 | -466.644 | -465.912 | -617.512 | -375.476 141.9189 | -159.534 | 30.30079 | 7.071984 | -16.5902 | 120.0019 | -288.513 | -29.1701 332.5676 | 360.7204 | 349.5538 | 389.6021 | 459.8242 | 569.2501 | 194.32 | 261.7723

My questions are:

  1. is there anything that should be set to obtain the actual voltage of EMG data (such as binary conversion)?
  2. since the form of the value is in float, what is the voltage unit output by the app (mV or uV)? I believe that the voltage unit obtained from SDK is still uV after multiplying it with LSB.