While creating an EDF file in matlab form a matrix, matlab return an error which doesn't make sense
%getting the name from the original file
Name = string(Infos.OriginalName(1:end-4))+ ".edf";
%Extracting the data of the signal in the proper form
sigdata = [traces(1,:)', traces(2,:)', traces(3,:)'];
%getting the sampling frequency of my recordings
fs = 1000;
% t = 0:1/fs:(size(sigdata,1)-1)/fs; I used that to plot the data
%making the header for the EDF file
hdr = edfheader("EDF+");
hdr.Recording = string(Infos.RecordingDate);
hdr.StartDate = string(datetime(string(Infos.RecordingDate(1:11)),'InputFormat','dd-MMM-yyyy', 'Format','dd.MM.yy'));
hdr.StartTime = string(datetime(string(Infos.RecordingDate(13:end)),'InputFormat', 'HH:mm:ss','Format','HH.mm.ss'));
hdr.NumDataRecords = 1;
hdr.DataRecordDuration = seconds(length(sigdata(:,1))/fs);
hdr.NumSignals = 3;
hdr.SignalLabels = ["Parietal_1" "Parietal_2" "Reference"];
hdr.PhysicalDimensions = repelem("uV",3);
%% this is where my problem is
hdr.PhysicalMin = min(sigdata);
hdr.PhysicalMax = max(sigdata);
hdr.DigitalMin = [-32768 -32768 -32768];
hdr.DigitalMax = [32767 32767 32767];
EEG_signal = edfwrite(Name,hdr,sigdata,'InputSampleType',"physical");
Everything is fine until a run the last line. Matlab give me this error:
Error using signal.internal.edf.write.validateFieldBytes (line 50)
Each value of "PhysicalMin" field must be less than or equal to 8 bytes. See edfheader documentation for more information.
Error in edfwrite/createFile (line 1667)
signal.internal.edf.write.validateFieldBytes(value, fieldIndex, ...
Error in edfwrite (line 493)
[obj, fileInfo] = createFile(obj, filename, hdr,...
I don't understand because my values in the hdr.PhysicalMin and hdr.PhysicalMax are doubles. when I run the "whos" function on the individual value they are 8 bytes each. Any idea how I could solve the problem ?

5 Kommentare

Kartheek Akurati
Kartheek Akurati am 27 Okt. 2021
Would attach Infos structure and traces signal to this question for further investigation ?
Thanks and regards,
Kartheek
Hassan Farhat
Hassan Farhat am 30 Okt. 2021
Hello,
I assume this is a bug in the code
Please use convert to int32 and it will solve your problem.
Regards
Hassan Farhat
Kartheek Akurati
Kartheek Akurati am 5 Nov. 2021
I would like know more about the usage of 32 bits for sample in EDF/EDF+ format. Currently, we are using only 2 bytes (16 bits) for storing a sample as per the data record specification in EDF+ spec.
Please, let me know about your use spec considerations you are using.
Thanks and regards,
Kartheek
Hassan Farhat
Hassan Farhat am 5 Nov. 2021
Hi Kartheek Akurati
It really depends on the amplitude range of your recorded EEG.
int16() is limited between [-32768 & 32767], anynumber outside this range will be threshold to these maximum limits
ex: int32(65000) = 32767.
So if your signal is higher in amplitude, you need to use higher bits (32) (64 bits is not working)
uint32 is limited between [0 & 65535]
Threfore, if you want to stick to 16 bits you need to rescale your inputs to be limited within the above ranges.
Best Regards
Hassan Farhat
Maxime Alessandri
Maxime Alessandri am 4 Apr. 2022
Hello,
I'm sorry I never had the oportunity to answer to you.
I found a solution:
My aquisition software record in volts so my hdr.PhysicalMin and hdr.PhysicalMax were like 0.0005 (whatever). So when I turned them in int32 it was just 0.
The way I managed was to scale the signal by 1000000 so that I was in microvolts. Then the int32 worked like a charm.
Thank you all for your help.
Maxime

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Federico Del Gallo
Federico Del Gallo am 7 Jun. 2021

0 Stimmen

I'm having the same problem. Did you find something to fix this error?

1 Kommentar

Maxime Alessandri
Maxime Alessandri am 4 Apr. 2022
Bearbeitet: Maxime Alessandri am 4 Apr. 2022
Hello,
I found the solution, please see my comment above,
Cheers, Maxime

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by