Problem with edfwrite regarding the number of the signals
Show older comments
Hi there,
I would like to open an EDF file in MATLAB, modify it and save it again. I expected that I could get header from edfinfo; however, it seems that I have to create header manually (only with edfheader). Am I right? But my question is about the edfwrite function. It tells me that:
Number of columns in the signal data must be equal to the number of signals.
But I have only one channel EEG and hdr.NumSignals=1. Here is the code (you can find EDF file here EDF file example):
clc;
clear all
close all
EEG_for_HFO=edfread('Rec-06.0001-GFP.edf');
header=edfinfo('Rec-06.0001-GFP.edf');
%header=get(header);
%% Inputs
EEG=EEG_for_HFO.EEG;
EEG=cell2mat(EEG);
SR=1000; % Sampling rate
% % Artifact Removal
% Threshold=1.5; % Threshold level for Artifact Removing in mili volt
% Window=10; % Length of step for Artifact Removing in mili second
% TimeDuration=100; % Time duration for Artifact Removing in mili second - Before and After
% % Highpass Filter
% FilterLevel=5; % Level of highpass filter
% Cutoff=2;
% %% Orders ------> 1 means On
% ArtifactRemoving=1;
% Filter=1;
% %% Plot
% figure;
% Time=1:length(EEG);
% plot(Time,EEG,'b');
% title('Raw signal')
% xlabel('Time(ms)');ylabel('EEG(mV)')
% %% Artifact Removal
% if (ArtifactRemoving==1)
% Start=100;
% End=Start+Window;
% for ii=1:(round(length(EEG)/Window)-Window)-1
% [Max(ii),max_indices(ii)]=max(abs(EEG(Start:End)));
% if Max(ii)>Threshold
% Before=max_indices(ii)-TimeDuration+Start;
% After=max_indices(ii)+TimeDuration-1+Start;
% EEG(Before:After)=0;
% end
%
% Start=Start+Window;
% End=End+Window;
% end
%
% hold on
% Time=1:length(EEG);
% plot(Time,EEG,'r')
% end
%
% %% Highpass Filter
% if (Filter==1)
%
% a=[];b=[];
% [b,a]=butter(FilterLevel,Cutoff/(SR/2),'high'); % Highpass filtering 2 Hz
% EEG=filtfilt(b,a,EEG);
% end
%% preparing cell
Start=1;
End=SR;
Step=SR;
EEGCell=[];
for ii=1:(length(EEG)/SR);
EEGCell{ii,1}=[EEG(Start:End)];
Start=End;
End=End+Step;
end
%% creating header
hdr=edfheader("EDF+");
hdr.Patient="Mice";
hdr.Recording="2021";
hdr.NumDataRecords=1440;
hdr.NumSignals=1;
hdr.SignalLabels="EEG";
hdr.PhysicalDimensions="mV";
hdr.PhysicalMin=-5;
hdr.PhysicalMax=5;
hdr.DigitalMin=-32256;
hdr.DigitalMax=32256;
%% exporting edf
% EEG_for_HFO.EEG=EEGCell;
% hdr.NumSignals=2;
% edfwrite('edited-Rec-06.0001-GFP.edf',hdr,EEG_for_HFO);
edfwrite('edited-Rec-06.0001-GFP.edf',hdr,EEGCell)
6 Comments
Walter Roberson
on 22 Jul 2022
Is there a reason you do not use
EEGCell = mat2cell(EEG(:), SR*ones(numel(EEG)/SR), 1);
Sadegh Rahimi
on 22 Jul 2022
Edited: Sadegh Rahimi
on 22 Jul 2022
Walter Roberson
on 22 Jul 2022
Your for loop to build EEgCell is okay, but you can code it more directly without a loop, using the mat2cell I showed.
Also, the code I showed acts slightly differently than your code under two circumstances:
- the result of the EEG=cell2mat(EEG); turned out to be a row vector -- if so you would get the error you saw
- the result of that statement turned out to be a 2D array -- if so then exact consequences would depend on whether it had more rows than columns or more columns than rows; if it had more columns then rows then you would get the error you saw
Sadegh Rahimi
on 22 Jul 2022
Walter Roberson
on 22 Jul 2022
EEGCell = mat2cell(EEG(:), SR*ones(1,numel(EEG)/SR), 1);
Sadegh Rahimi
on 22 Jul 2022
Accepted Answer
More Answers (0)
Categories
Find more on 5G Toolbox 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!