ikarosilva / wfdb-app-toolbox

The WFDB Toolbox for MATLAB/Octave is a collection of functions for reading, writing, and processing physiologic signals in the formats used by PhysioNet (see README for details).
http://physionet.org/physiotools/matlab/wfdb-app-matlab/
GNU General Public License v3.0
92 stars 45 forks source link

Updates the ADC res in the mat2wfdb.m #184

Closed lamawmouk closed 1 year ago

lamawmouk commented 1 year ago

This PR updates the ADC resolution (bits) field to match the input bit resolution. The format of the signal specification lines in the header can be found here :https://archive.physionet.org/physiotools/wag/header-5.htm

bemoody commented 1 year ago

Thanks, Lama!

Tested using the example from the mat2wfdb documentation:

N=1024;
Fs=48000;
tm=[0:1/Fs:(N-1)/Fs]';
adu='V/mV/V';
info='Example 1';
sig1=double(int16(linspace(-2^15,2^15,N)'));
sig2=double(int8(sin(2*pi*tm*1000).*(2^7)))./(2^7);
sig3=(rand(N,1) > 0.97)*2 -1 + 2^16;
sig=[sig1 sig2 sig3];
mat2wfdb(sig,'Ex1',Fs,[],adu,info)

The master version gives these wfdbcheck errors:

$ ~/wfdbcheck/wfdbcheck Ex1
(WW) Ex1: signal 0: signal description missing
(WW) Ex1: signal 1: signal description missing
(WW) Ex1: signal 2: signal description missing
(WW) Ex1: signal 0: adcres = 0
(WW) Ex1: signal 1: adcres = 0
(WW) Ex1: signal 2: adcres = 0
(EE) Ex1: signal 0: sample 0 (-32767) is outside ADC range (0, 0)
(EE) Ex1: signal 1: sample 0 (128) is outside ADC range (0, 0)
(EE) Ex1: signal 2: sample 0 (-32767) is outside ADC range (0, 0)

With this change, the adcres errors are fixed:

$ ~/wfdbcheck/wfdbcheck Ex1
(WW) Ex1: signal 0: signal description missing
(WW) Ex1: signal 1: signal description missing
(WW) Ex1: signal 2: signal description missing