You need to use a Python DSP Digital Signal Processing package to apply various filters to the data stream. For example you could do a bandpass filter from say .5 to 45 hz, that would solve your DC offset and mains noise at the same time.
What you are seeing is the macOS problem, you have to fix it with the edits shown. Cyton is sending the packets at the correct 4 ms rate, they are getting buffered inside macOS.
The sample rate at the Cyton is relatively constant. It is very close to 4ms, 250hz. However, the timing with which you receive the packets at the application varies, depending on operating system latencies. You can always assume each sample (one sample per bluetooth packet), was recorded at the 250hz rate. For all the neurofeedback applications I am aware of, such OS latencies are common and not an issue.
Your first graph shows two different DC offsets for GUI and your own capture. If you apply say a .5 Hz high pass filter, or .5 to 45 bandpass, that DC offset would go away.
Your 3rd graph PSD is also showing a large low frequency "almost DC" component. Filter this out as suggested.
I understood that the raw data contains a DC offset of ADS1299 as you mentioned.
What I want to say is, the PSD of raw data from OpenBCI_GUI is as expected, even if it contains a large DC offset, while the PSD of raw data from my program is strange.
The PSDs should be similar even if I don't filter the DC offset.
So I thought I couldn't capture the raw EEG correctly.
But my program is as same as the top of cyton.py, and the captured waveforms are very similar.
Comparing the two raw data files, I see the OpenBCI raw data has widely varying DC offsets, whereas your DC offsets are all in the 50 millivolts range. Not sure if this might account for the differences. Best to pre-filter and remove DC offset before any further signal processing.
Comments
https://drive.google.com/file/d/14Sy6j2K7IoMu4DKA7pYcEXPvOm-U8lxm/view?usp=sharing
2018-08-23 21:43:18.142490 113 -3684.886239
2018-08-23 21:43:18.142929 114 -5777.881238
2018-08-23 21:43:18.143378 115 -6608.516766
2018-08-23 21:43:18.143746 116 -6344.296794
2018-08-23 21:43:18.557327 117 -4401.527870 <- here
2018-08-23 21:43:18.558110 118 -3686.070882
2018-08-23 21:43:18.558728 119 -5775.310788
2018-08-23 21:43:18.559363 120 -6606.818033
2018-08-23 21:43:18.560120 121 -6343.693297
The differences of each timestamp are about 0.3 - 0.4 ms, and sometimes ( for every 120 sample? ) jump for about 400ms as shown above.
My program is almost as same as the sample code in cyton.py, may not be wrong.
The captured EEG waveforms contain a large 50Hz noise, and it shows that this program captures EEG waveforms correctly as expected.
So adding the config parameter InBufferSize=64 does not fix in my environment.
I assume that the Cyton board captures the EEG correctly for every 4ms, but the data is buffered somewhere and my Mac read it intermittently.
I use the OpenBCI for the real-time neurofeedback, and I should calculate ERP in real-time.
I cannot allow this choppiness.
The latest version of FTDI driver is 2.4.2, so will it fix this if I reinstall it and change the Info.plist file as described?