next up previous contents
Next: Creating the header Up: Coding a sin wave Previous: Introduction   Contents

Creating an ASCII file

Our first task is creating a program that emulates the result of an acquisition made by a polygraph. The acquisition is going to include five seconds of a sin wave sampled at 100 Hz. The frequency of the sin wave is 1 Hz and its peak-to-peak amplitude 200 $\mu$V.

In this kind of files, time is often included as the first column (defining implicitly the sampling rate), so we are going to use this approach to create our file. To avoid handling files, we will redirect the output. This is the code

class CreateSig{
    public static void main(String[] args){
	double time=0;
	double value=0;

	for (int i = 0; i<500; i++){
	    time = (double) i * 0.01;
	    value = 100 * Math.sin(2 * 3.14159 * time);

	    System.out.println(time+"  "+value);
	}
    }
}

It does not seem a very difficult task; we created an index (i) equivalent to counting the sampling rate of the A/D converter, then we obtained the time considering the sampling period (0.01 s) and finally we calculated the value. To obtain the maximum simplicity, we do not include any format command so that our output is formed by a set of lines each of them containing two values separated by spaces.

Let's see the result:

 
[j@localhost Code]$ javac CreateSig.java
[j@localhost Code]$ java CreateSig
0.0  0.0
0.01  6.279046656224248
0.02  12.533312825768572
0.03  18.73811581904769
0.04  24.868968154705794
...
4.95  -30.904197903556923
4.96  -24.871538368480227
4.97  -18.74072239995222
4.98  -12.535945486835878
4.99  -6.281695007562094
[j@localhost Code]$ java CreateSig > sig.asc
[j@localhost Code]$ ls
CreateSig.class  CreateSig.java  sig.asc

So, we have three files: the source (CreateSig.java), the executable (CreateSig.class) and the result (sig.asc). The file sig.asc is named like that to indicate that it is a signal is ASCII. This file is equivalent to the output of some neurophysiological instruments. We will use this file to create our EDF+ file.


next up previous contents
Next: Creating the header Up: Coding a sin wave Previous: Introduction   Contents
j 2003-05-28