Clear Filters
Clear Filters

how to convert an ecg signal to image 2D

6 views (last 30 days)
karima neffati
karima neffati on 16 Jul 2019
Answered: SUDESHNA on 20 Dec 2023
hello everyone
can someone help me to generate an image 2D from an ecg signal :
the main idea is to determine the RR intervalle in seconde ,the image that will be find contain the number of samples in raw and the times in column,
here is a pdf file explain the futur image.
please im really need your help
clc;
close all;
close all;
load 'ECG_3.mat'
N=length(ECG_3);
fs=2155;
t=[0:N-1]/fs; subplot (221);
plot(ECG_3) ;grid on
title('Original Signal')
xlabel('samples');ylabel('Amplitude(v)');
%%
%Low pass filter
b=1/32*[1 0 0 0 0 0 -2 0 0 0 0 0 1];
a=[1 -2 1];
sigL=filter(b,a,ECG_3);subplot(222);
plot(sigL);grid on
title('Low Pass Filter')
%%
% BASE LINE DERIVATION
b=[1/4 1/8 0 -1/8 -1/4];
a=[1];
sigD=filter(b,a,sigL);subplot(223)
plot(sigD);grid on
title('Derivative Base Filter')
%% Measuring Distance Between Peaks
%Find R peaks
[pks_Rwave,locs_Rwave] = findpeaks(sigD,'MinPeakHeight',0.5,'MinPeakDistance',200);
fprintf('locs_Rwave = \n');
disp (locs_Rwave)
pks_Rwave1 = pks_Rwave*100;
fprintf('pks_Rwave = \n');
disp (pks_Rwave1);subplot (224);
plot(time,sigD,time(locs_Rwave),pks_Rwave,'rv','MarkerFaceColor','r'); grid on
xlabel('Time'); ylabel('Voltage');
title('Find Prominent Peaks');
%% RR INTERVAL
i = 0; %% to make the code start from 0.
rr = 0; %% each time the code run, rr distance two peaks
hold off % for the next graph
rrinterval = zeros(3600,1); % create an array to strore 2 peaks
beat_count =0;
for k = 2 : length(sigD)-1
%the peak has to be greater than 1 and greater than the value before it and greater then the value after it.
if(sigD(k)> sigD(k-1) && sigD(k) > sigD(k+1) && sigD(k)> 1);
beat_count = beat_count +1;
if beat_count ==1;
rr =0;
else
rr = k-i;
rrinterval(k)=rr;
i=k;
end
else
rrinterval(k)= rr;
end
end
figure;
plot (rrinterval);
title('R-R intervals');
  3 Comments
karima neffati
karima neffati on 17 Jul 2019
i want to verifiy with you if the result that i had could be disable to generate image

Sign in to comment.

Answers (1)

SUDESHNA
SUDESHNA on 20 Dec 2023
  1. Time Variable time Missing: You're using time in the plot for R-peaks, but it's not defined in your provided code. Make sure to define time appropriately based on your signal.
  2. Arrays Pre-allocated Size: You've pre-allocated an array rrinterval with a fixed size (zeros(3600,1)) assuming a maximum of 3600 peaks. If the number of peaks exceeds this limit, it might cause issues. Consider dynamically resizing the array based on the actual number of peaks.
  3. Loop Starting Index k and Beat Count: You start the loop from k = 2, and beat_count is incremented before checking if it's equal to 1. If you want to start counting beats after the first R-peak, you might want to set beat_count = 0 initially.

Products


Release

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!