This is a code I made for cleaning and visualizing raw ECG data from physioNet. I want to make some enhancements to the output and can't figure out how so I am asking if someone could help or give me a hint as to where to search. In the output, we have 2 figures each with 4 subplots.
I want to make the output appear similar to this:
The things I want to make:
I want to enable the grid but with specifications similar to an ECG paper: Each large square consists of 5 small squares, Each small square is 1 mm in length and represents 0.04 seconds. Each larger square is 5 mm in length and represents 0.2 seconds.
I want each signal to appear in a row without intersecting and without having to disable the grid. And to stay in one subplot
and finally, I want to disable the labels of the drawing scale of the horizontal and vertical axes.
an example of the data can be found here instead of downloading the whole data
%import data
data=("D:\Matlab\a-large-scale-12-lead-electrocardiogram-database-for-arrhythmia-study-1.0.0\a-large-scale-12-lead-electrocardiogram-database-for-arrhythmia-study-1.0.0\WFDBRecords\01\010\JS00001.mat");
x=load('JS00012.mat');
y = x.val/2000;
y = y';
fs=500;
t = (0:length(y)-1)/fs; % Time vector
% Assuming you have 12 signals stored in the variable 'y'
% Create separate variables for each signal
signal1 = y(:, 1);
signal2 = y(:, 2);
signal3 = y(:, 3);
signal4 = y(:, 4);
signal5 = y(:, 5);
signal6 = y(:, 6);
signal7 = y(:, 7);
signal8 = y(:, 8);
signal9 = y(:, 9);
signal10 = y(:, 10);
signal11 = y(:, 11);
signal12 = y(:, 12);
% Combine the signals
combined_signal1 = signal1 + signal4 + signal7 + signal10;
combined_signal2 = signal2 + signal5 + signal8 + signal11;
combined_signal3 = signal3 + signal6 + signal9 + signal12;
% Plot the combined signals
figure;
subplot(411)
plot(t(1:5*fs), combined_signal1(1:5*fs));
subplot(412)
plot(t(1:5*fs), combined_signal2(1:5*fs));
subplot(413);
plot(t(1:5*fs), combined_signal3(1:5*fs));
subplot(414);
plot(t(1:5*fs), y(1:5*fs,2));
%Filter the signal data
fcutlow = 0.5; % Lower cutoff frequency in Hz
fcuthigh = 40; % Upper cutoff frequency in Hz
[b,a] = butter(4, [fcutlow/(fs/2) fcuthigh/(fs/2)], 'bandpass');
filtered_signal = zeros(size(y));
for i = 1:size(y, 2)
filtered_signal(:,i) = filtfilt(b, a, y(:,i));
end
% Amplify the filtered signal data
amplified_signal = 2 * filtered_signal;
% Apply baseline correction to each lead of the filtered signal data
baseline_corrected_signal = zeros(size(amplified_signal));
for i = 1:size(amplified_signal, 2)
baseline_corrected_signal(:,i) = amplified_signal(:,i) - medfilt1(amplified_signal(:,i), fs/4);
end
% Apply wavelet denoising to each lead of the amplified signal data
denoised_signal = zeros(size(baseline_corrected_signal));
for i = 1:size(baseline_corrected_signal, 2)
denoised_signal(:,i) = wden(baseline_corrected_signal(:,i),'minimaxi','s','mln',8,'sym4');
end
% Create separate variables for each signal
signal_clean1 = denoised_signal(:, 1);
signal_clean2 = denoised_signal(:, 2);
signal_clean3 = denoised_signal(:, 3);
signal_clean4 = denoised_signal(:, 4);
signal_clean5 = denoised_signal(:, 5);
signal_clean6 = denoised_signal(:, 6);
signal_clean7 = denoised_signal(:, 7);
signal_clean8 = denoised_signal(:, 8);
signal_clean9 = denoised_signal(:, 9);
signal_clean10 = denoised_signal(:, 10);
signal_clean11 = denoised_signal(:, 11);
signal_clean12 = denoised_signal(:, 12);
% Combine the cleaned signals
combined_signal_clean1 = signal_clean1 + signal_clean4 + signal_clean7 + signal_clean10;
combined_signal_clean2 = signal_clean2 + signal_clean5 + signal_clean8 + signal_clean11;
combined_signal_clean3 = signal_clean3 + signal_clean6 + signal_clean9 + signal_clean12;
%Plot the cleaning signals
figure;
subplot(411)
plot(t(1:5*fs), combined_signal_clean1(1:5*fs));
title('Denoised ECG signal');
subplot(412)
plot(t(1:5*fs), combined_signal_clean2(1:5*fs));
subplot(413)
plot(t(1:5*fs), combined_signal_clean3(1:5*fs));
subplot(414)
plot(t(1:5*fs), denoised_signal(1:5*fs,2));