demo_real_ECG: ECG signal denoising with the SASS algorithm

Real ECG data

Ivan Selesnick
selesi@nyu.edu
2013, 2016

Contents

Load ECG data

clear

load('data/108m_2_3.mat');      % load 'val'

N = 1000;                       % length of signal to extract
dat = val(1, 2360+(1:N));       % extract signal
dat = dat(:);                   % convert to column vector
y = dat - mean(dat);            % remove mean

ax = [0 N  -125 125];
n = 1:N;

figure(1)
clf
subplot(2,1,1)
plot(n, y)
box off
title('Real ECG');
axis(ax)

Define low-pass filter

% d: filter is of order 2d
% fc : cut-off frequency (0 < fc < 0.5) (cycles/sample)
% K : order of sparse derivative

d = 2;
fc = 0.02;
K = 2;

% Banded filter matrices:
[A, B] = ABfilt(d, fc, N, K);

H = @(x) A\(B*x);   % H : high-pass filter
L = @(x) x - H(x);  % L : low-pass filter

txt_filt = sprintf('d = %d, fc = %.3f', d, fc);

Low-pass filter

x_lpf = L(y);           % Apply low-pass filter to ECG signal

txt_LPF = sprintf('Low-pass filtering (%s)', txt_filt);

figure(1)
clf
subplot(2, 1, 1)
plot(n, y)
title('Real ECG');
axis(ax)

subplot(2, 1, 2)
plot(n, x_lpf)
title('Low-pass filter')
axis(ax)

print -dpdf figures/demo_real_ECG_lowpass_filter

SASS - run SASS denoising algorithm

lam = 200;

[x, u] = sass_L1(y, d, fc, K, lam);       % SASS algorithm
% x : denoised signal
% u : sparse order-K derivative

txt = sprintf('SASS (L1, K = %d, lam = %.2f, %s)', K, lam, txt_filt);
0 incorrectly locked zeros detected.

Plot denoised signal

figure(1)
clf
subplot(2, 1, 1)
plot(n, y)
title('Real ECG');
axis(ax)

subplot(2, 1, 2)
plot(n, x)
title(txt)
axis(ax)

print -dpdf figures/demo_real_ECG_SASS

SASS - sparse signal component

figure(1)
clf
subplot(2, 1, 1)
plot(u)
xlim([0 N])
title('Sparse signal (determined via SASS)')

Compared SASS and low-pass filtering

GRAY = [1 1 1]*0.7;

figure(1)
clf
subplot(2, 1, 1)
plot(n, y, 'color', GRAY);
line(n, x_lpf );
legend('Real ECG', 'Low-pass filter')
title('Low-pass filtering')
axis(ax)

subplot(2, 1, 2)
plot(n, y, 'color', GRAY);
line(n, x );
legend('Real ECG', 'SASS')
title('SASS')
axis(ax)

print -dpdf figures/demo_real_ECG_compare