We have just now a file with a set of values. To create an EDF+ file, the first thing to do is creating the header. Here we have to take some decisions. As an example we decide that the data record duration will equal one second. So, we will have 5 data records. We will create a continuous EDF+ file but we are going to use methods that can be very easily generalized for discontinuous records.
The header of an EDF+ file is a set of fixed-length ASCII characters. We choose to store the result in a String. Although Strings in Java are formed by 16-bit characters, they can be easily converted to ASCII format. The procedure is highly repetitive and can be followed easily by reading the code.
We define a class called Support where different functions are going to be stored. Let's see its content
This is a very repetitive code. Basically, we create a String (result) and we add the different fields. Each field is adjusted to the specification of EDF by adding spaces. We defined two signals: an ordinary signal containing the values and an annotation signal whose label is EDF Annotations. Having at least an annotation signal is a must in EDF+.
Now we need a program to check the function. We create the program SupportTest.java. This is the content
We can check the result
Now we have an EDF+ file (test1.edf) that contains no data. The file contains only the header.
class Support{
public String createHeader(){
// creates a string with spaces
String spaces ="";
for(int i=0; i<80; i++){
spaces += " ";
}
String str1="";
String result="";
int numSignals = 2;
// VERSION
str1 = "0"+spaces;
result += str1.substring(0,8);
// PATIENT
str1 = "X X X X"+spaces;
result += str1.substring(0,80);
// RECORDING
str1 = "Startdate 01-JAN-2003 X X X"+spaces;
result += str1.substring(0,80);
// STARTDATE
str1 = "01.01.03"+spaces;
result += str1.substring(0,8);
// STARTTIME
str1 = "10.00.00"+spaces;
result += str1.substring(0,8);
// HEADERSIZE
int bytes_header = (numSignals+1)*256;
str1 = bytes_header+spaces;
result += str1.substring(0,8);
// RESERVED
str1 = "EDF+C"+spaces;
result += str1.substring(0,44);
// DATARECORDS
int n_datarecords = 5;
str1 = n_datarecords + spaces;
result += str1.substring(0,8);
// DURATION
str1 = "1"+spaces;
result += str1.substring(0,8);
// SIGNALS
str1 = numSignals+spaces;
result += str1.substring(0,4);
String[] signals = {"Sin wave","EDF Annotations"};
for (int i=0 ; i< numSignals; i++){
str1 = signals[i]+spaces;
result += str1.substring(0,16);
}
String[] transducers = {"",""} ;
for (int i=0 ; i< numSignals; i++){
str1 = transducers[i]+spaces;
result += str1.substring(0,80);
}
String[] dimension = {"uV",""};
for (int i=0 ; i< numSignals; i++){
str1 = dimension[i]+spaces;
result += str1.substring(0,8);
}
String[] physmin = {"-100","0"};
for (int i=0 ; i< numSignals; i++){
str1 = physmin[i]+spaces;
result += str1.substring(0,8);
}
String[] physmax = {"100","1"};
for (int i=0 ; i< numSignals; i++){
str1 = physmax[i]+spaces;
result += str1.substring(0,8);
}
String[] digmin = {"-100","-32768"};
for (int i=0 ; i< numSignals; i++){
str1 = digmin[i]+spaces;
result += str1.substring(0,8);
}
String[] digmax = {"100","32767"};
for (int i=0 ; i< numSignals; i++){
str1 = digmax[i]+spaces;
result += str1.substring(0,8);
}
String[] prefiltering = {"",""};
for (int i=0 ; i< numSignals; i++){
str1 = prefiltering[i]+spaces;
result += str1.substring(0,80);
}
int[] nsamples = {100, 50};
int bytesPerRecord = 0;
for(int i=0; i<nsamples.length; i++){
bytesPerRecord += nsamples[i];
}
for (int i=0 ; i< numSignals; i++){
str1 = nsamples[i]+spaces;
result += str1.substring(0,8);
}
String[] reserved = {"",""};
for (int i=0 ; i< numSignals; i++){
str1 = reserved[i]+spaces;
result += str1.substring(0,32);
}
return result;
}
}
public class SupportTest{
public static void main(String[] args){
Support mySupport = new Support();
System.out.println(mySupport.createHeader());
}
}
[j@localhost Code]$ javac SupportTest.java
[j@localhost Code]$ java SupportTest > test1.edf
[j@localhost Code]$
Next: Reading an ASCII file
Up: Coding a sin wave
Previous: Creating an ASCII file
Contents
j
2003-05-28