If I have a 5 minutes long signal stored in an EDF file that I'm reading from using the function readSignal(), imagine that I'm interested only in the first second of that 5 minutes, and I want to store that portion of the signal in a separate edf file. How can I do this? The following code reads the first 1 second, where the sampling rate is 1kHz, and I'm simply visualizing it.
import pyedflib
import numpy as np
import matplotlib.pyplot as plt
file_name = "17335.0001_0001.edf"
f = pyedflib.EdfReader(file_name)
signal_labels = f.getSignalLabels()
fig=plt.figure()
ax=plt.axes()
ax.plot(f.readSignal(0,0,1000))
With EDF format, you have to adjust the metadata to the modifications you applied to the signal, in your case - number of channels and duration. I'd recommend using pyedflib's high level functions for IO.
pyedflib.highlevel.read_edfprovides the metadata, along with the signal data for you to modify easily. The downside of it, it reads the whole channel, instead of only the first second, what may harm the performance. If your signal is not very large - I'd go with high level convenience functions.