Plotting high frequency EDF data from timetable
16 views (last 30 days)
Show older comments
Andrew Michalak
on 18 Apr 2022
Answered: Campion Loong
on 18 May 2022
Using 2022a
Since 2020b the old FEX function edfread() was incorporated into matlab in the signal processing toolbox (native edfread). The function reads the data out in a timetable which I am having trouble manipulating/plotting:
For a record sampled at 500 Hz (e.g, EEG, MEG data):
a = edfread('test.edf')
a =
9500×128 timetable
Record Time C1 C2
0.632 sec {50×1 double} {50×1 double}
0.732 sec {50×1 double} {50×1 double}
0.832 sec {50×1 double} {50×1 double}
...
If this were sampled at 1024 Hz, the filed would contain 128x1 doubles corresponding to each Record Time increment (which would be 0.125 sec).
I'm having trouble finding an intuitive way to manipulate and plot these massive files.
I've tried:
- I can write a code to "unpack" all of the 50x1 cells into a single vector, but this is very resource intensive.
- Using 'DataRecordOutputType', 'vector' does not seem to change the output (I still get a timetable)
- using table2cell(a) or table2array(a) works to get it out of timetable format, but leaves me with a header-less cell/array of cells and the "unpacking" problem still exists.
0 Comments
Accepted Answer
Star Strider
on 18 Apr 2022
I do not have your data, however using the MATLAB sample data, extracting the entire record of each variable may not be difficult
tt = edfread('example.edf')
RecTime = seconds(tt.('Record Time')); % Get Time Variable
ECGv = cat(1,tt.ECG{:}); % Concatenate The 'ECG' Variable
Ts = numel(tt.ECG{1})/mean(diff(RecTime)); % Sampling Intervals (Samples/Second)
Time = linspace(0, numel(ECGv)-1, numel(ECGv)).'/Ts; % Create Continuous Time Vector
figure % Plot Results
plot(Time, ECGv)
grid
xlabel('Time')
ylabel('Amplitude')
If I understand correctly what you want to do (and I may not), ‘unpacking’ the data is straightforward. This is somewhat facilitated by duration arrays having a regular sampling interval. It may be necessary to scale the ‘Time’ variable appropriately with your data.
.
2 Comments
More Answers (1)
Campion Loong
on 18 May 2022
edfData = edfread('example.edf');
% Unpack the ECG signals into a timetable of regularly sampled data
% (This assumes the 1280 data-points are sampled evenly between adjacent 'Record Time')
ECG = cat(1,edfData.ECG{:});
ECG2 = cat(1,edfData.ECG2{:});
tt = timetable(ECG, ECG2, 'TimeStep', seconds(10)/1280)
% Simply visualize both ECG series in one stackedplot
% (You can even scrub both series together with synchronized datatip to explore the signals further)
stackedplot(tt)
0 Comments
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!