Next: XFORM(1) Up: WFDB Applications Guide Previous: WRANN(1)On This Page


wrsamp - write WFDB signal files


wrsamp [ options ... ] [ column ... ]


wrsamp reads text-format input and writes the specified columns in WFDB signal file format 16 (see signal(5) ), either to the standard output or to a disk file (see the -o option below). If no columns are specified, all columns are written (but see the -z option below).

Normally, wrsamp’s input is line- and column-oriented, with line separator characters (usually ASCII linefeeds) separating input lines, and field separator characters (usually tabs, spaces, or commas) separating columns within each line. Columns need not be of constant width; the only requirement is that one or more field separator characters appear between adjacent columns. The output of rdsamp(1) is an example of an acceptable input format, as is CSV (comma-separated value) format.

If the first input line contains any alphabetic character, it is assumed to contain signal names (column headings), and these are copied to the output header file (see the -o option below). In this case, if the second input line also contains any alphabetic character, it is assumed to contain unit names (i.e., the names of the physical units of each signal), and these are also copied to the output header file. Spaces embedded within unit names are written as underscores in the header file.

Lines are identified by line number. The first line of input not containing any alphabetic character is line 0. Similarly, columns are identified by column number, and the leftmost column is column 0. Columns may be selected in any order, and any given column may be selected more than once, or omitted. The order of column arguments determines the order of the signals in the output (data from the first column specified are written as signal 0, etc.) If an entry in a specified column is "-" (i.e., flagged as missing or invalid), or if an entry in a specified column is any other non-numeric value, wrsamp records it as an invalid sample in its output.

If line 0 appears to begin with a timestamp (a field of the form [hh:mm:ss.sss dd/mm/yyyy]), wrsamp records it as the base time (starting time) in the output header file.

Options include:

Check that each input line contains the same number of fields. (This test is normally disabled, to allow for input files containing preambles, trailers, or occasional extra fields not intended to be read as samples.)
Dither the input before converting it to integer output, by adding a random value to each sample. The random values are selected from a triangular probability density function between -1 and +1. Dithering is appropriate whenever the output has a lower resolution than the input. Note that the RNG used to generate the pseudo-random values is started with a fixed seed, so that wrsamp’s output is strictly reproducible. Change the seed in the source and recompile to obtain a different realization of dither if desired.
-f n
Start copying with line n. By default, wrsamp starts at the beginning of its standard input (line 0).
-F n
Specify the sampling frequency (in samples per second per signal) for the output signals (default: 250). This option is useful only in conjunction with -o, since it affects the output header file only. This option has no effect on the output signal file, which contains one sample per signal for each line of input. If you wish to change the sampling frequency in the signal file, see xform(1) .
-G n
Specify the gain (in A/D units per millivolt) for the output signals (default: 200). To specify different gains for each output signal, provide a quoted list of values in place of n (see the examples below). This option is useful only in conjunction with -o, since it affects the output header file only. This option has no effect on the output signal file. If you wish to rescale samples in the signal file, use -x.
Print a usage summary.
-i file
Read input from the specified file (default: standard input).
-l n
Read up to n characters in each line (default: 1024). Longer lines are truncated (with a warning message identifying the line number of the offending line).
-o record Write the signal file in the current directory
as record.dat, and create a header file in the current directory for the specified record. By default, wrsamp writes the signal file to its standard output, and does not create a header file.
-O format
Write the signal file in the specified format (default: 16). See signal(5) for descriptions and names of available formats.
-r c
Interpret c as the input line separator (default: \n, the ASCII linefeed character). This option may be useful, for example, to read Macintosh files containing carriage-return delimited lines. Note that no special treatment is required for files containing both carriage returns and linefeeds.
-s c
Interpret c as the input field separator (default: both spaces and tabs are treated as input field separators). If this option is used, c is the only character treated as a field separator.
-t n
Stop copying at line n (line n is not processed). By default, wrsamp stops when it reaches the end of file on its standard input.
-x n
Multiply all input samples by n (default: 1) before writing them to the output signal file. To specify different scaling factors for each signal, provide a quoted list of values in place of n (see the examples below).
Don’t copy column 0 unless explicitly specified.


It may be necessary to set and export the shell variable WFDB (see setwfdb(1) ).


   rdsamp -r 100s | wrsamp -o 100w -F 360 1 2

This command creates a record named ‘100w’ that is a copy of record ‘100s’ (although the signal file format is different). If the -F 360 option were omitted, the output signal file (‘100w.dat’) would be unchanged, but the header file for record ‘100w’ would indicate that the sampling frequency was (the default) 250 Hz, rather than 360 Hz as in record 100s; this is because wrsamp has no other way of determining the sampling frequency of its input. Note that columns 1 and 2 of wrsamp’s input correspond to signals 0 and 1 respectively; column 0 is the sample number, not useful to wrsamp.

   wrsamp -i in.txt -o out -G "100 100 50" -x "1 .5 -10 2" 4 1 0 3

This command creates a record named ‘out’ that contains signals derived from four columns of its input (‘in.txt’). Notice that the argument of the -G (gain) option is the quoted string "100 100 50"; the effect is that the gains of the first two output signals are set to 100, and that of the third is 50. Since no explicit gain is specified for the fourth signal, it is assigned the same gain as the previous (third) signal (i.e., 50). Similarly, the quoted argument of the -x option specifies scaling factors applied to the samples before they are written to the output signal file: output signal 0 will be unscaled (scale factor 1), signal 1 will be halved (.5), signal 2 will be scaled by 10 and inverted (-10), and signal 3 will be doubled (2) . Finally, note that the four columns selected from the input file have been rearranged, so that the leftmost column (0) will become output signal 2, etc.

See Also

rdsamp(1) , setwfdb(1) , xform(1) , signal(5)


George B. Moody (


Table of Contents

Up: WFDB Applications Guide

Please e-mail your comments and suggestions to, or post them to:

MIT Room E25-505A
77 Massachusetts Avenue
Cambridge, MA 02139 USA

Updated 8 March 2019