L.fole
L.fole

Reputation: 807

Load MIT-BIH Arrhythmia ECG database onto MATLAB

I am working on ECG signal processing using neural network which involves pattern recognition. As I need to collect all the data from Matlab to use it as test signal, I am finding it difficult to load it on to the Matlab. I am using MIT Arrhythmia database here.

The signal needs to be indexed and stored as data structure in Matlab compatible format. Presently, the signal is in .atr and .dat format.

How can you load MIT-BIH Arrhythmia database onto Matlab?

Upvotes: 16

Views: 43047

Answers (6)

Use ATM to extract .mat as described by Kamtal (now known Rashid). However, note that to see the .info file in some cases, you need to click the arrow

enter image description here

After I pushed this forward to developers here, we got improvements in the documentation here in Section 4.

If they are all integers in the range [-2^N, 2^N-1 ] or [ 0, 2^N ], they are probably digital. Compare the values to see if they are in the expected physiological range of the signal you are analyzing. For example, if the header states that the signal is an ECG stored in milivolts, which typically has an amplitude of about 2mV, a signal of integers ranging from -32000 to 32000 probably isn't giving you the physical ECG in milivolts...

If they are not integers then they are physical. Once again you can quickly compare the values to see if they are in the expected physiological range of the signal you are analyzing.

0-9-10 wfdb - physical units

We say that signals are in 'physical units' when the values are used to represent the actual real life values as closely as possible, although obviously everything on the computer is digital and discrete rather than analogue and continuous. This includes our precious 64 bit double precision floating point values, but this is as close as we can get and already very close to the actual physical values, so we refer to them as 'physical'.

-

For example, if a 15 bit signal is collected via a capturing device, Physionet will likely store it as a 16 bit signal. Each 16 bit block stores an integer value between -2^15 and 2^15-1, and using the gain and offset stated in the header for each channel, the original physical signal can be mapped out for processing.

The default units are now physical units where base and gain should be added stated in the header for each channel, so the physical signal can be mapped out for processing.

% rawUnits
%       A 1x1 integer (default: 0). Returns tm and signal as vectors
%       according to the following values:
%               rawUnits=0 - Uses Java Native Interface to directly fetch  data, returning signal in physical units with double precision.
%               rawUnits=1 -returns tm ( millisecond precision only! ) and signal in physical units with 64 bit (double) floating point precision
%               rawUnits=2 -returns tm ( millisecond precision only! ) and signal in physical units with 32 bit (single) floating point  precision
%               rawUnits=3 -returns both tm and signal as 16 bit integers (short). Use Fs to convert tm to seconds.
%               rawUnits=4 -returns both tm and signal as 64 bit integers (long). Use Fs to convert tm to seconds.

rawUnits=1, rawUnits=2 use also physical units. rawUnits=3, rawUnits=4 use then again analog/digital units where you need to remove base and gain. If you use rawUnits=1 or rawUnits=2, you need to adjust for base and gain where base = 1024 and gain = 200

# Kamtal's method in considering base and gain
load('201m.mat');
val = (val - 1024)/200;    % you have to remove "base" and "gain"
ECGsignal = val(1,16:950); % select the lead (Lead I)

See the .info file below where you can get the base and gain. There is also the unit mV which suggests the values should be near 2 after the base-gain operations.

<0-9-9 wfdb - analog/digital units so base and gain by default; now only rawUnits=3,4 for analog units

After selection ATM, you should be able to see the list where you can select .info file after the export as described in Kamtal's answer. The .info file instructs to remove so-called base and gain from the data before use

Source: record mitdb/201  Start: [00:02:10.000]
val has 2 rows (signals) and 3600 columns (samples/signal)
Duration:     0:10
Sampling frequency: 360 Hz  Sampling interval: 0.002777777778 sec
Row     Signal  Gain    Base    Units
1       MLII    200     1024    mV
2       V1      200     1024    mV

To convert from raw units to the physical units shown
above, subtract 'base' and divide by 'gain'.

Comparing wrong answers here! [Deprecated]

Kamtal (now called Rashid) answer is about the old wfdb system which used digital units without removal of base and gain

# Kamtal's method in considering base and gain
load('201m.mat');
val = (val - 1024)/200;    % you have to remove "base" and "gain"
ECGsignal = val(1,16:950); % select the lead (Lead I)

# Method without considering base and gain
load('201m.mat');
ECGsignal2 = val(1,16:950); 

# http://www.mathworks.com/matlabcentral/fileexchange/10502-image-overlay
imshow(imoverlay(ECGsignal, ECGsignal2, uint8([255,0,0])))

and you get the difference between my method and his method

enter image description here

Upvotes: -1

Harun
Harun

Reputation: 3

just use it

A=input('Enter Variable: ','s');
load(A);
a=(val(1,:));
b=fir1(100,[0.1,0.25],'stop');
y2=filter(b,1,a);
figure;
plot(y2);

Upvotes: 0

Amit Juneja
Amit Juneja

Reputation: 380

So I read this answer 3 months ago and removed the base and gain. It turns out , i completely shifted my R-peaks in various directions, screwing up all my results. While I am not sure if doing this is necessary in matlab or not, DO NOT DO THIS if you are not preprocessing your signal in matlab. I was preprocessing my signal in python, and all I did to normalizae it was

val = val/2047  % (2047 is the max volt range of signals)

and used butterworth filters to remove artifacts (range 0.5hz-45hz)

CORRECTION

The cutoff i selected is 0.5 to 45 not 5-15 as I previously reported. This cutoff preserves the QRS for various arrhythmias without adding too much noise

# baseline correction and bandpass filter of signals 
lowpass = scipy.signal.butter(1, highfreq/(rate/2.0), 'low') 
highpass = scipy.signal.butter(1, lowfreq/(rate/2.0), 'high') 

# TODO: Could use an actual bandpass filter 
ecg_low = scipy.signal.filtfilt(*lowpass, x=ecg) 
ecg_band = scipy.signal.filtfilt(*highpass, x=ecg_low)

Upvotes: 2

Niu
Niu

Reputation: 31

There is a tutorial for using matlab to read the data. tutorial for matlab user

  1. install "The WFDB Toolbox for Matlab" from the link above. Add the folder of the toolbox to the path in matlab.

  2. Download the ECG signal. Be sure to download '.atr', '.dat' and '.hea' together for the signal you are to deal with.

  3. Command in matlab is as follows : [tm,signal,Fs]=rdsamp( filename , 1 ) ; [ann,type]=rdann( filename , 'atr' ) ; Note: for signal '101', its name is '101'. And you can check the detail information about rdsamp and rdann from the tutorial.

Upvotes: 2

Rash
Rash

Reputation: 4336

You can use physionet ATM to get .mat files which are easier to work with.

In the input part select the desired leads, length, database and sample.

In the toolbox select export as .mat:

enter image description here

Then download the '.mat' file,

enter image description here

In order to open the file in MATLAB, here is a sample code:

load ('100m.mat')          % the signal will be loaded to "val" matrix
val = (val - 1024)/200;    % you have to remove "base" and "gain"
ECGsignal = val(1,1:1000); % select the lead (Lead I)
Fs = 360;                  % sampling frequecy
t = (0:length(ECGsignal)-1)/Fs;  % time
plot(t,ECGsignal)

and you will get,

enter image description here

However, If you were to read annotation files for arrhythmia or QRS complexes that would be another problem.

Edit

The base and gain come from the info file (second picture). This file gives you various information regarding the ECG signal.

enter image description here

In the last sentence it says: To convert from raw units to the physical units shown above, subtract 'base' and divide by 'gain'.

Upvotes: 6

Sriram
Sriram

Reputation: 10558

You need the program rddata.m (MATLab script) from this website. The program can be found here. rddata.m is probably the only program you will need to read the ecg signals. I remember having used this program and database myself not too long ago.

Upvotes: 4

Related Questions