Plotting high frequency EDF data from timetable

15 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2022-4-18
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')
tt = 6×2 timetable
Record Time ECG ECG2 ___________ _______________ _______________ 0 sec {1280×1 double} {1280×1 double} 10 sec {1280×1 double} {1280×1 double} 20 sec {1280×1 double} {1280×1 double} 30 sec {1280×1 double} {1280×1 double} 40 sec {1280×1 double} {1280×1 double} 50 sec {1280×1 double} {1280×1 double}
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 个评论
Andrew Michalak
Andrew Michalak 2022-4-21
Thank you! This is what I was looking for. It still poses an additional step but seems to work very quickly!

请先登录,再进行评论。

更多回答(1 个)

Campion Loong
Campion Loong 2022-5-18
The stackedplot visualization for timetable is built for exactly this kind of use cases
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)
tt = 7680×2 timetable
Time ECG ECG2 _____________ ________ __________ 0 sec -0.11262 -0.006995 0.0078125 sec -0.0915 -0.006995 0.015625 sec -0.07742 -0.006995 0.023438 sec -0.04222 -5.005e-06 0.03125 sec -0.00702 -5.005e-06 0.039062 sec -0.00702 -0.006995 0.046875 sec 0.03522 -5.005e-06 0.054688 sec 0.07042 0.006985 0.0625 sec 0.0845 -5.005e-06 0.070312 sec 0.1197 -0.006995 0.078125 sec 0.13378 -0.006995 0.085938 sec 0.1197 -5.005e-06 0.09375 sec 0.07042 0.013975 0.10156 sec 0.0493 -0.013985 0.10938 sec -0.03518 0.006985 0.11719 sec -0.07038 0.020965
% 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)

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by