clear all; close all;
fSize = 16;

% sourceDir = '/mit/6.555/data/ecg/';
sourceDir = '';
source = 'normal.txt';
% Interesting remark about data:
%   First 4 minutes (clean) -- student lying still
%   Last  1 minute  (dirty) -- student flexing chest/arm muscle

data = load(strcat(sourceDir,source));
T  = data(2,1)-data(1,1); % Sampling period [s]
fs = 1/T;                 % Sampling rate [Hz], not quite 250Hz 

% Full data
subplot(2,2,[1 2]);
plot(data(:,1),data(:,2))
xlabel('Time (s)','FontSize',fSize); 
ylabel('EKG (V)','FontSize',fSize);
title(source,'FontSize',fSize);
set(gca,'FontSize',fSize);

subplot(223);
tClean = [100 110];
nClean = floor(fs*tClean);
nClean = nClean(1):nClean(2);
clean  = data(nClean,:);
plot(clean(:,1),clean(:,2));
xlim(tClean);
clear tClean nClean;
xlabel('Time (s)','FontSize',fSize); 
ylabel('EKG (V)','FontSize',fSize);
title('Clean segment','FontSize',fSize);
set(gca,'FontSize',fSize);

subplot(224);
tNoisy = [250 260];
nNoisy = floor(fs*tNoisy);
nNoisy = nNoisy(1):nNoisy(2);
noisy  = data(nNoisy,:);
plot(noisy(:,1),noisy(:,2),'r');
xlim(tNoisy);
clear tNoisy nNoisy;
xlabel('Time (s)','FontSize',fSize); 
ylabel('EKG (V)','FontSize',fSize);
title('Noisy segment','FontSize',fSize);
set(gca,'FontSize',fSize);
