# HRV calculation with RRI values

25 views (last 30 days)
Audrey on 7 Jun 2024
Commented: Audrey on 18 Jun 2024
Hi, I need to calculate the HRV in the frequency domain which is the smallest ratio LF/HF. I got these RRI values: RR_intervals = [RR_intervals = [0.848, 0.901, 1.032, 0.968, 0.834, 0.848, 1.069, 1.066, ...
0.898, 0.866, 0.902, 0.984, 0.899, 0.816, 0.885, 1.099, ...
1.032, 0.831, 0.819, 1.082, 1.115, 1.052, 0.95, 0.964, ...
1.034, 1.016, 0.866, 0.784, 0.848, 1.053, 0.999, 0.848, ...
0.866, 1.067, 0.984, 0.866, 0.966, 1.067, 1.049, 0.869, ...
0.833, 0.916, 1.049, 0.916, 0.817, 0.85, 1.001, 0.981, ...
0.818, 0.8, 0.901, 1.016, 0.915, 0.853, 0.932, 1.034, ...
0.882, 0.801, 0.817, 0.916, 0.836, 0.78, 0.784, 0.91] How should i proceed?
% Convertir les intervalles RR en millisecondes
RR_intervals_ms = RR_intervals * 1000;
% Calculer la transformée de Fourier des intervalles RR
N = length(RR_intervals_ms);
Y = fft(RR_intervals_ms - mean(RR_intervals_ms)); % Enlever la moyenne pour réduire le bruit DC
P2 = abs(Y/N);
P1 = P2(1:N/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Fréquences correspondantes
fs = 4;
f = fs*(0:(N/2))/N;
% Conversion des fréquences en BPM
f_bpm = f * 60;
% Plages de fréquences basses (LF) et hautes (HF)
LF_band = [0.04 0.15];
HF_band = [0.15 0.4];

Abhimenyu on 14 Jun 2024
Hi Audrey,
The calculation of HRV in the frequency domain further requires the identification of 'LF' and 'HF' frequency bands, integrating the power in the bands and then computing the ratio. The code shared in the query correctly computes the 'FFT' and the power spectral density as follows:
% Given RR intervals in seconds
RR_intervals = [0.848, 0.901, 1.032, 0.968, 0.834, 0.848, 1.069, 1.066, ...
0.898, 0.866, 0.902, 0.984, 0.899, 0.816, 0.885, 1.099, ...
1.032, 0.831, 0.819, 1.082, 1.115, 1.052, 0.95, 0.964, ...
1.034, 1.016, 0.866, 0.784, 0.848, 1.053, 0.999, 0.848, ...
0.866, 1.067, 0.984, 0.866, 0.966, 1.067, 1.049, 0.869, ...
0.833, 0.916, 1.049, 0.916, 0.817, 0.85, 1.001, 0.981, ...
0.818, 0.8, 0.901, 1.016, 0.915, 0.853, 0.932, 1.034, ...
0.882, 0.801, 0.817, 0.916, 0.836, 0.78, 0.784, 0.91];
% Convertir les intervalles RR en millisecondes
RR_intervals_ms = RR_intervals * 1000;
% Calculer la transformée de Fourier des intervalles RR
N = length(RR_intervals_ms);
Y = fft(RR_intervals_ms - mean(RR_intervals_ms)); % Enlever la moyenne pour réduire le bruit DC
P2 = abs(Y/N);
P1 = P2(1:N/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Fréquences correspondantes
fs = 4;
f = fs*(0:(N/2))/N;
% Conversion des fréquences en BPM
f_bpm = f * 60;
% Plages de fréquences basses (LF) et hautes (HF)
LF_band = [0.04 0.15];
HF_band = [0.15 0.4];
Identification of the LF and HF frequency bands.
% Find indices corresponding to LF and HF bands
LF_indices = find(f >= LF_band(1) & f <= LF_band(2));
HF_indices = find(f >= HF_band(1) & f <= HF_band(2));
Integrating the power in these bands to compute LF and HF power.
% Integrate the power in LF and HF bands
LF_power = trapz(f(LF_indices), P1(LF_indices));
HF_power = trapz(f(HF_indices), P1(HF_indices));
Computing the ratio and printing the results.
% Calculate LF/HF ratio
LF_HF_ratio = LF_power / HF_power;
% Print results
fprintf('LF Power: %.4f\n', LF_power);
LF Power: 1.6887
fprintf('HF Power: %.4f\n', HF_power);
HF Power: 3.9596
fprintf('LF/HF Ratio: %.4f\n', LF_HF_ratio);
LF/HF Ratio: 0.4265
I hope this helped to resolve your query!
Audrey on 18 Jun 2024
Thank you!