Filter löschen
Filter löschen

Problem with edfwrite regarding the number of the signals

4 Ansichten (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 22 Jul. 2022
EEGCell = mat2cell(EEG(:), SR*ones(1,numel(EEG)/SR), 1);
Sadegh Rahimi
Sadegh Rahimi am 22 Jul. 2022
Thanks for updating the code and your kind support; now, I don't face the Input arguments, D1 through D2, should be vectors. error anymore, but the Number of columns in the signal data must be equal to the number of signals is still there!
I mean, despite we have single column EEGCell and I I added hdr.NumSignals=1, I still face this error by running edfwrite:
Error using signal.internal.edf.write.validateSignalData (line 26)
Number of columns in the signal data must be equal to the number of signals.
Error in signal.internal.edf.write.getFileCreateOpts>checkSignals (line 223)
signal.internal.edf.write.validateSignalData(sigData, ...
Error in signal.internal.edf.write.getFileCreateOpts>createHdr (line 96)
[reqhdr, sigData] = checkSignals(reqhdr, sigData, tNumSignals);
Error in signal.internal.edf.write.getFileCreateOpts>createAndValidateHeader (line 47)
[hdr, sigData, tsal] = createHdr(thdr, sigData, tsal, hdrPropertiesList, ...
Error in signal.internal.edf.write.getFileCreateOpts (line 13)
[hdr, sigData, tsal] = createAndValidateHeader(hdr, sigData, tsal, ...
Error in edfwrite/createFile (line 1602)
signal.internal.edf.write.getFileCreateOpts(hdr, signalData, ...
Error in edfwrite (line 493)
[obj, fileInfo] = createFile(obj, filename, hdr,...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Jul. 2022
The number of entries in the cell array is expected to be the same as the number of signals (and each entry must be a vector)
  3 Kommentare
Phuc Nguyen
Phuc Nguyen am 18 Aug. 2022
I have the same problem, but I found the solution as below code:
clc, clear, close
hdr = edfheader("EDF");
hdr.Patient = "001 M 2020";
hdr.Recording = "This is the original header record";
hdr.StartTime = "00.00.01";
sig = randn(10,1); % one vector for 1 channel
hdr.NumDataRecords = 5; % 5 numbers of data recording
hdr.NumSignals = 1;
hdr.PhysicalMin = min(sig);
hdr.PhysicalMax = max(sig);
hdr.DataRecordDuration = seconds(10);
hdr.DigitalMin = -32767;
hdr.DigitalMax = 32767;
edfw = edfwrite("file.edf",hdr,sig,"InputSampleType","physical");
df = edfread('file.edf') % check edf
Sadegh Rahimi
Sadegh Rahimi am 18 Aug. 2022
Thanks Phuc Nguyen for your comment.
I will test and see, whether it would solve the issue.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu AI for Signals finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by