How to plot RR interval?
Afficher commentaires plus anciens
Hello everyone!
I have an RR interval (attached) extracted from an ECG signal that was sampled at 500 Hz. The R peaks and their indices were extracted using findpeaks(), then the diff() function was used on the R indices (expressed in seconds) to calculate the RR interval. The RR interval was converted in milliseconds following the standard procedure. Below an extract from the code:
[qrspeaks, locs] = findpeaks(iwt, time, "MinPeakHeight", 0.5, ...
"MinPeakDistance", 0.42);
% RR interval
RR = diff(Rindex);
RR = RR'.*1000; % conversion in ms
Now I should plot this signal on the y-axis, while on the x-axis I should have the time (in seconds) at which the heart beat occurs.
I need the time in seconds of the RR interval also for the spline interpolation of the signal. I would like to start interpolating from the first value of the signal, so to avoid the extra values between 0 and the first value of the RRI. I attached a plot as an example to make myself more clear. Below the code for the interpolation:
x = 1:length(RR);
xq = 0:0.25:length(RR); % Instead of 0 I would like the first index value of the RRI
s = spline(x, RR, xq);
timespline = (1:length(xq))/4;
If you have different suggestions feel free to share, they're always welcome!
Thank you in advance for your reply!
1 commentaire
Bhupati kumar
le 15 Oct 2020
how do i get rr indices?
Réponses (1)
Altaïr
le 29 Mai 2025
I noticed you’ve successfully extracted the RR intervals and shared them in the RRI.mat file. Since the corresponding time array is not provided, a dummy time vector spanning 1s to 24s in 1s increments has been assumed for answering the query. The time array is constructed as follows:
t = 1:length(RR);
To perform the interpolation starting from the first valid RRI value (while avoiding near-zero values), define the query points beginning at t(1) (which is 1s in this case):
xq = t(1) : 0.25 : t(end);
Below is the full code for reference:
load('RRI.mat')
t = 1:length(RR);
% Define query points (e.g., 4 Hz resampling: step = 0.25s)
xq = t(1) : 0.25 : t(end);
% Spline interpolation
s = spline(t, RR, xq);
% Plot results
figure;
hold on;
plot(t, RR, 'o', 'DisplayName', 'Original RR');
plot(xq, s, '-', 'DisplayName', 'Spline Interpolation');
xlabel('Time (s)');
ylabel('RR Interval (ms)');
title('Interpolated RR Intervals');
legend
grid on;
hold off;

For more details on the spline function, you can check the MATLAB documentation by running:
web(fullfile(docroot, 'matlab/ref/spline.html'))
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!