%% Load .mat file containing ECG signals
%  10 seconds duration, 360Hz sample rate
%  "ecg_clean" - clean ECG signal
%  "ecg_noisy" - ECG signal corrupted by noise
load 'ecg_signals.mat'
fs = 360;

N = length(ecg_clean);
t = (0:(N-1)) * (1/fs);

%% Time domain plot of clean and noisy signals
figure;
subplot(2,1,1);
plot(t, ecg_clean);
xlabel('seconds');
grid on
set(gca,'FontSize',20)
subplot(2,1,2);
plot(t, ecg_noisy);
xlabel('seconds');
grid on
set(gca,'FontSize',20)

%% Calculate spectrum of clean and noisy signals
ECG_clean = fftshift(fft(ecg_clean));
ECG_noisy = fftshift(fft(ecg_noisy));
omega = [-N/2:(N/2-1)] * (2*pi/N);  % discrete frequency in radians
f = omega*fs/(2*pi); % continuous frequency in Hz

%% Spectrum plot of clean and noisy signals
figure;
subplot(2,1,1);
plot(f, 20*log10(abs(ECG_clean)));
xlabel('frequency (Hz)');
ylabel('Magnitude (dB)');
grid on
set(gca,'FontSize',20)
subplot(2,1,2);
plot(f, 20*log10(abs(ECG_noisy)));
xlabel('frequency (Hz)');
ylabel('Magnitude (dB)');
grid on
set(gca,'FontSize',20)
