@@ -1500,20 +1500,28 @@ def edf2mit(record_name, pn_dir=None, delete_file=True, record_only=False):
15001500
15011501def wav2mit (record_name , pn_dir = None , delete_file = True , record_only = False ):
15021502 """
1503- Convert WAV formatted files to MIT format. See here for more details about
1504- the formatting of a WAV file: http://soundfile.sapp.org/doc/WaveFormat/.
1503+ Convert .wav (format 16, multiplexed signals, with embedded header
1504+ information) formatted files to MIT format. See here for more details about
1505+ the formatting of a .wav file: http://soundfile.sapp.org/doc/WaveFormat/.
1506+
1507+ This process may not work with some .wav files that are encoded using
1508+ variants of the original .wav format that are not WFDB-compatible. In
1509+ principle, this program should be able to recognize such files by their
1510+ format codes, and it will produce an error message in such cases. If
1511+ the format code is incorrect, however, `wav2mit` may not recognize that
1512+ an error has occurred.
15051513
15061514 Parameters
15071515 ----------
15081516 record_name : str
1509- The name of the input WAV record to be read.
1517+ The name of the input .wav record to be read.
15101518 pn_dir : str, optional
15111519 Option used to stream data from Physionet. The Physionet
15121520 database directory from which to find the required record files.
15131521 eg. For record '100' in 'http://physionet.org/content/mitdb'
15141522 pn_dir='mitdb'.
15151523 delete_file : bool, optional
1516- Whether to delete the saved WAV file (False) or not (True)
1524+ Whether to delete the saved .wav file (False) or not (True)
15171525 after being imported.
15181526 record_only : bool, optional
15191527 Whether to only return the record information (True) or not (False).
@@ -1527,6 +1535,44 @@ def wav2mit(record_name, pn_dir=None, delete_file=True, record_only=False):
15271535 corresponding .dat and .hea files. This record file will not match the
15281536 `rdrecord` output since it will only give us the digital signal for now.
15291537
1538+ Notes
1539+ -----
1540+ Files that can be processed successfully using `wav2mit` always have exactly
1541+ three chunks (a header chunk, a format chunk, and a data chunk). In .wav
1542+ files, binary data are always written in little-endian format (least
1543+ significant byte first). The format of `wav2mit`'s input files is as follows:
1544+
1545+ [Header chunk]
1546+ Bytes 0 - 3: "RIFF" [4 ASCII characters]
1547+ Bytes 4 - 7: L-8 (number of bytes to follow in the file, excluding bytes 0-7)
1548+ Bytes 8 - 11: "WAVE" [4 ASCII characters]
1549+
1550+ [Format chunk]
1551+ Bytes 12 - 15: "fmt " [4 ASCII characters, note trailing space]
1552+ Bytes 16 - 19: 16 (format chunk length in bytes, excluding bytes 12-19)
1553+ Bytes 20 - 35: format specification, consisting of:
1554+ Bytes 20 - 21: 1 (format tag, indicating no compression is used)
1555+ Bytes 22 - 23: number of signals (1 - 65535)
1556+ Bytes 24 - 27: sampling frequency in Hz (per signal)
1557+ Note that the sampling frequency in a .wav file must be an
1558+ integer multiple of 1 Hz, a restriction that is not imposed
1559+ by MIT (WFDB) format.
1560+ Bytes 28 - 31: bytes per second (sampling frequency * frame size in bytes)
1561+ Bytes 32 - 33: frame size in bytes
1562+ Bytes 34 - 35: bits per sample (ADC resolution in bits)
1563+ Note that the actual ADC resolution (e.g., 12) is written in
1564+ this field, although each output sample is right-padded to fill
1565+ a full (16-bit) word. (.wav format allows for 8, 16, 24, and
1566+ 32 bits per sample)
1567+
1568+ [Data chunk]
1569+ Bytes 36 - 39: "data" [4 ASCII characters]
1570+ Bytes 40 - 43: L-44 (number of bytes to follow in the data chunk)
1571+ Bytes 44 - L-1: sample data, consisting of:
1572+ Bytes 44 - 45: sample 0, channel 0
1573+ Bytes 46 - 47: sample 0, channel 1
1574+ ... etc. (same order as in a multiplexed WFDB signal file)
1575+
15301576 Examples
15311577 --------
15321578 >>> wav_record = wfdb.wav2mit('sample-data/SC4001E0-PSG.wav', record_only=True)
0 commit comments