holgern / pyedflib

pyedflib is a python library to read/write EDF+/BDF+ files based on EDFlib.
http://pyedflib.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
214 stars 121 forks source link

Writing to EDF affects signal values #177

Closed mishashevelinn closed 2 years ago

mishashevelinn commented 2 years ago

I parsed an EDF file with pyedflib, modified the signal headers and saved the modified file also with pyedflib. After comparing the resulting signals with the original, saw some minor differences between the signals. Looks like digitation noise(something with binary datatypes conversion). I found a similar issue, but it talks about using mne for processing and saving from/to different formats(I'm consistent with EDF) See the attached plot. Units are millivolts Figure_1 s

skjerns commented 2 years ago

Have you tried loading and saving the data with ’digital=True’ (eg using the highlevel interface?

That should resolve the issue.

What did you change in the signal headers? Changing the digital and physical min/max will affect the resulting signal resolution, and might introduce rounding errors. That's a downside of the edf format unfortunately.

mishashevelinn commented 2 years ago

@skjerns , thank you for your answer! I do just renaming, but the plots taken after reading and immediate writing to examine this issue without any manipulations. I did what you proposed, it definitely minimizes the amplitude error, it's still there but got linear in proportion to the signal amplitude itself. Any thoughts on this? Thanks again!

image
skjerns commented 2 years ago

Can you post the code you are using? And maybe the signal headers of the affected signals?

mishashevelinn commented 2 years ago

@skjerns , you were correct, forgot to change 'analog' on writing, but changed to 'digital' on reading :) Thanks!