Convert Cyton Board Impedance Measurement to Python code.
Hello,
I am a beginner working with EEG devices, and I have recently started exploring their functionalities. My current goal is to use Python to measure the impedance (N status) of individual channels from the Cyton board and save the results as a CSV file. I am trying to replicate the functionality of the "Cyton Signal" feature in OpenBCI GUI v6.0.0-beta.1.
However, the impedance values I obtain using Python are significantly higher than expected. In OpenBCI GUI, channel N status typically shows values between 280–450 kΩ, but in my Python implementation, value of around 60,000–70,000 kΩ.
The equipment I use is as follows, and I used water instead of gel when comparing whether the resistance between OpenBCI and the Python code is similar, I used water instead of gel. After testing OpenBCI, I immediately ran the Python code under the same conditions, and the focus was more on whether the resistance between OpenBCI and the Python code was the same.
https://shop.openbci.com/products/all-in-one-gelfree-electrode-cap-bundle
I referred to the following resources for guidance:
https://brainflow.readthedocs.io/en/stable/Examples.html#python
https://github.com/OpenBCI/OpenBCI_GUI/blob/master/OpenBCI_GUI/W_CytonImpedance.pde
https://github.com/OpenBCI/OpenBCI_GUI/blob/master/OpenBCI_GUI/DataProcessing.pde
and it's my code:
https://github.com/ywpark4N/OpenBCI/blob/main/python_impedance_test.py
To measure the impedance for the first channel, I am sending the following command:
command = "x1000100Xz101Z"
response = board.config_board(command)
print("response:", response)response: Success: Channel set for 1$$$Success: Lead off set for 1$$$
After configuring the board, I retrieve data using:
data = board.get_board_data()
print("data", data[1:4, -10:])
Here is a sample of the printed data: channel1 O2, channel2 O1, channel3 T5
data [ [2639391.08126057 2634747.64046045 2635210.58979161 2637812.86928807 2638579.98115778 2636886.97062575 2635091.49969715 2639948.98080218 2638179.79552505 2637897.62710305],
[ 21536.44222456 18467.1230277 20969.4678747 19753.2647554 21107.57930369 18971.95952796 20380.96879494 20342.25557354 20431.46138566 19644.50116688],
[ 93956.09425975 91095.49565262 93410.6893433 92346.18751361 93563.66468235 91573.46535605 92876.39324384 92900.06374121 92935.2006835 92176.29190401] ]
Since the sampling rate is 125 Hz, I obtain approximately 125 data points per second for each channel.
I store this data into accumulated_data, initialized to zeros, using the FIFO method stack.Then, after storing the data in current_data using getdata(accumulated_data, 22 * 125) and I save the current_data into dataProcessingRawBuffer and dataProcessingFilteredBuffer for filtering.
I then process the dataProcessingFilteredBuffer using the following steps:
Apply filters:
Bandstop Filter (58–62 Hz)
Bandpass Filter (5–50 Hz)
Environmental Noise Removal (50 Hz and 60 Hz)
- Extract filtered data based on the sampling rate (125 Hz):
foo_data_filt = acc_data[-int(125):]
- Calculate the standard deviation for each channel:
data_std_uV[j] = np.std(foo_data_filt)
- Use the provided formula to calculate impedance:
for j in range(13):
impedance = (math.sqrt(2.0) * (data_std_uV[j]) * 1.0e-6) / 6.0e-9
impedance -= 2200.0
if impedance < 0.0:
impedance = 0.0
data_elec_imp_ohm[j] = impedance
- Here is an examples of the output for the first channel:
print("impedance in kΩ: ", data_elec_imp_ohm[0] / 1000)
impedance in kΩ: 63642.49124210053
Why is the impedance calculated in Python much higher than the expected range (280–450 kΩ) shown in OpenBCI GUI?
Are there any commands or processes that need to be fixed or that might be missing?
Any guidance on this matter would be greatly appreciated.
Comments
One way to proceed would be to load the GUI into the Processing IDE, then add some printout statements (to the Console Log screen) that track the impedance calculation through the various steps. Then compare this to what you are doing in your Python.
https://docs.openbci.com/Software/OpenBCISoftware/GUIDocs/#running-the-openbci-gui-from-the-processing-ide
https://docs.openbci.com/Troubleshooting/GUI_Troubleshooting/