next up previous contents
Next: WFDB: `rdann' Up: PhysioNet, PhysioBank, PhysioToolkit Previous: MIT-BIH Arrhythmia Database   Contents

WFDB: `rdsamp'

The first step is to learn more about a basic tool that reads signal files from the specified record and writes the samples as decimal numbers. These values will be used by Scilab.

We have to download and install the package from PhysioToolkit. In DOS/Windows systems it can be downloaded as different .exe files. In UNIX systems it can be installed from a .rpm file (the sources can be downloaded and the program can be compiled too).

To follow this section we need the next elements:

Our objective is to read the data and incorporate them to Scilab variables in such a way that we are able to manipulate them. First of all, we have to be located in the directory

 -->chdir ('/home/j/physionet')
 ans  =
 
    0.  
 
-->pwd
 ans  =
 
 /home/j/physionet   
 
-->unix_g('ls')
 ans  =
 
!100.atr   !
!          !
!100.dat   !
!          !
!100.hea   !
!          !
!100s.atr  !
!          !
!100s.dat  !
!          !
!100s.hea  !
Everything seems to work properly. We are in the directory and we have the files. Now it is a good time to begin to see the signals. We are going to begin with the shorter one (`100s'). Look at this interesting result. If we type at the prompt of Scilab


-->unix_x('rdsamp -r 100s')
a window appears that contains the next text

     0	  995	 1011
     1	  995	 1011
     2	  995	 1011
     3	  995	 1011
     4	  995	 1011
     5	  995	 1011
     6	  995	 1011
     7	  995	 1011
     8	 1000	 1008
     9	  997 ...
and many more lines. The first column shows the number of the sample and the other two columns show the samples of the signals contained in `100s'. Would it not be splendid if we were able to introduce the values into a Scilab variable?. Let's go on. We close the window and repeat the command but assigning the values to `our100s'


-->our100s = unix_g('rdsamp -r 100s');
 
-->size(our100s)                      
 ans  =
 
!   21600.    1. !
 
-->x= evstr(our100s(1:10))            
 x  =
 
!   0.    995.     1011. !
!   1.    995.     1011. !
!   2.    995.     1011. !
!   3.    995.     1011. !
!   4.    995.     1011. !
!   5.    995.     1011. !
!   6.    995.     1011. !
!   7.    995.     1011. !
!   8.    1000.    1008. !
!   9.    997.     1008. !
  
-->size(x)                
 ans  =
 
!   10.    3. !
If you notice that your computer does not do anything, don't worry. It has been a painful process. The first command reads the file and translates it into ASCII. Afterwards, Scilab assigns the result to a matrix of strings (`our100s'): a huge matrix of 21,600 rows and only one column (it is a string). We can convert some parts of this matrix into a matrix of three numeric values with `evstr'. But perhaps another method will be faster.

-->unix_g('rdsamp -r 100s > dummy')
 ans  =
 
     []
 
-->x = fscanfMat('dummy');
 
-->x(1:10,:)
 ans  =
 
!   0.    995.     1011. !
!   1.    995.     1011. !
!   2.    995.     1011. !
!   3.    995.     1011. !
!   4.    995.     1011. !
!   5.    995.     1011. !
!   6.    995.     1011. !
!   7.    995.     1011. !
!   8.    1000.    1008. !
!   9.    997.     1008. !
We have the same result by letting `fscanfMat' do the job. It reads the variables and stores the result in `x'. But what about `dummy'?. We can erase the file.


-->unix_g('ls')                    
 ans  =
 
!100.atr   !
!          !
!100.dat   !
!          !
!100.hea   !
!          !
!100s.atr  !
!          !
!100s.dat  !
!          !
!100s.hea  !
!          !
!dummy     !

-->unix_g('rm dummy')              
 ans  =
 
     []

-->unix_g('ls')                    
 ans  =
 
!100.atr   !
!          !
!100.dat   !
!          !
!100.hea   !
!          !
!100s.atr  !
!          !
!100s.dat  !
!          !
!100s.hea  !
It is a fast procedure. Now we want to know more about the creature we made

-->size(x)
 ans  =
 
!   21600.    3. !
Since we read the header, we knew that we had two signals. Now we can see that the first column contains the number of the sample and the others, the signals. After all this effort, we want to see the result. We know that the sampling rate is `1/360' and then we correct our plot with this value:

-->plot2d(x(:,1)/360,x(:,2))
And the result is shown in the figure  [*]:

Figure: Plotting of the first signal in 100s.dat
\begin{figure}
\begin{center}
\epsfbox{figures/rdsamp1.eps}
\end{center}
\end{figure}

There are several interesting facts in this plot. First of all, the figure represents one minute (60 seconds). The plot is correct since we knew the sampling period. The amplitude is expressed in some units that we do not know. We can use `2D Zoom' in Scilab window to to see each part of the signal. But `rdsamp' has several interesting options. Since we are using directly the function, we can use the options without additional effort.

First of all we try the option `-v' that prints column heading. If we type


-->unix_x("rdsamp -r 100s -v")
we get a window with the next result

samp #	MLII	V5
     0	  995	 1011
     1	  995	 1011
     2	  995	 1011...
The first line shows the origin of the signals. `MLII' means `modified lead II' and `V5' is a standard electrocardiographic position.

Now we are going to obtain the real values contained in the file. The option `-p' translates the values. We type

 
-->unix_x("rdsamp -r 100s -p")
    
  0.000	 -0.145	 -0.065
  0.003	 -0.145	 -0.065
  0.006	 -0.145	 -0.065
  0.008	 -0.145	 -0.065
  0.011	 -0.145	 -0.065
  0.014	 -0.145	 -0.065
  0.017	 -0.145	 -0.065
  0.019	 -0.145	 -0.065
  0.022	...
Now the results are expressed in physical units. But we have two signals. We can isolate any of them with the command

-->unix_x("rdsamp -r 100s -p -s 0")
with the result:


  0.000	 -0.145
  0.003	 -0.145
  0.006	 -0.145
  0.008	 -0.145
  0.011	 -0.145
  0.014	 -0.145
  0.017	 -0.145
  0.019	...
We extracted the first signal but if we want to extract the second one:


-->unix_x("rdsamp -r 100s -p -s 1")
we get the second signal (signals are numbered from`0')

  0.000	 -0.065
  0.003	 -0.065
  0.006	 -0.065
  0.008	 -0.065
  0.011	 -0.065
  0.014	 -0.065
  0.017	...
We get `only' the second signal. So we can divide easily the original matrix into columns. We can split the matrix also in rows. The options `-f' and `-t' are used to indicate the start point and the end point to `rdsamp'. Now we are going to make a difficult exercise. We are going to read 0.01 seconds of the second signal from the second 37 with physical units. Let's go on:
 
-->unix_x("rdsamp -r 100s -p -s 1 -f 0:37 -t 0:37.01")
and the result is:
  
 37.000	 -0.245
 37.003	 -0.255
 37.006	 -0.260
 37.008	 -0.265
Of course, with such amounts of values we do not need `dummies':

-->x= evstr(unix_g("rdsamp -r 100s -p -s 1 -f 0:37 -t 0:37.01"));
 
-->x 
 x  =
 
!   37.     - 0.245 !
!   37.003  - 0.255 !
!   37.006  - 0.26  !
!   37.008  - 0.265 !
 
-->size(x)
 ans  =
 
!   4.    2. !
Pay attention to the fact that x is a matrix of real values with 4 rows and 2 columns.

With these options we only need that the system aids us to remember. Then, if we type:


-->unix('rdsamp -h')
 ans  =
 
    0.
at the terminal where Scilab was initiated will appear

usage: rdsamp -r RECORD [OPTIONS ...]
where RECORD is the name of the input record, and OPTIONS may include:
 -f TIME     begin at specified time
 -h          print this usage summary
 -H          read multifrequency signals in high resolution mode
 -l INTERVAL truncate output after the specified time interval (hh:mm:ss)
 -p          print times and samples in physical units (default: raw units)
 -s SIGNAL [SIGNAL ...]  print only the specified signal(s)
 -t TIME     stop at specified time
 -v          print column headings
Once we are able to read signals, we must learn to read annotations (the other important component of the base) and we will dedicate the next chapter to do it.

.


next up previous contents
Next: WFDB: `rdann' Up: PhysioNet, PhysioBank, PhysioToolkit Previous: MIT-BIH Arrhythmia Database   Contents
j 2001-09-16