def generate_psd_plot_hamilton(data: dict, sampling_frequency: int = 128):

    rr_intervals_list = data['hamilton']['rr_intervals']

    # Processing pré-pipeline
    # This remove outliers from signal
    rr_intervals_without_outliers = remove_outliers(
        rr_intervals=rr_intervals_list, low_rri=300, high_rri=2000)

    # This replace outliers nan values with linear interpolation
    interpolated_rr_intervals = interpolate_nan_values(
        rr_intervals=rr_intervals_without_outliers,
        interpolation_method="linear")

    # This remove ectopic beats from signal
    nn_intervals_list = remove_ectopic_beats(
        rr_intervals=interpolated_rr_intervals, method="malik")
    # This replace ectopic beats nan values with linear interpolation
    interpolated_nn_intervals = interpolate_nan_values(
        rr_intervals=nn_intervals_list)

    plot_psd(interpolated_nn_intervals,
             method="lomb",
             sampling_frequency=sampling_frequency)
Exemple #2
0
print("ecg time", time)
print("ecg new points", points)

#downsampling
resampled_signal = scipy.signal.resample(ecg, points)

print("ecg resampled len", len(resampled_signal))

#r peak detector
detectors = Detectors(256)
r_peaks = detectors.engzee_detector(resampled_signal[0:34304])
rr = np.diff(r_peaks)
'''
#r peak plot
print(r_peaks)

plt.figure()
plt.plot(ecg[0:2560])
plt.plot(r_peaks, ecg[r_peaks], 'ro')
plt.title('Detected R-peaks')
plt.savefig('new_downsampled_rpeaks.png', dpi=300)   #plot for 5 seconds (2500 points)
'''

#HRV time domain parameters
time_domain_features = get_time_domain_features(r_peaks)
print(time_domain_features)

#HRV frequency domain parameters
plot_psd(rr, method="welch")
plt.show()
    fv.append(hf['Triang'])
    fv.append(hf['ULF'])
    fv.append(hf['VHF'])
    fv.append(hf['VLF'])
    return fv


#Feature Extraction
feature_array = []
sampling_rate = 300
#for i in range(len(arp)):
#    x_rpeaks=arp[i]
#    hrv_t = nk.bio_ecg.ecg_hrv(rpeaks=x_rpeaks, sampling_rate=sampling_rate, hrv_features=['time'])
#    hrv_f = nk.bio_ecg.ecg_hrv(rpeaks=x_rpeaks, sampling_rate=sampling_rate, hrv_features=['frequency'])
##    hrv_nl = nk.bio_ecg.ecg_hrv(rpeaks=x_rpeaks, sampling_rate=sampling_rate, hrv_features=['nonlinear'])
#    temp_fa=feat_array(hrv_t,hrv_f)
#    feature_array.append(temp_fa)

from hrvanalysis import get_csi_cvi_features
rr_intervals_list = arp[0]
time_domain_features = get_csi_cvi_features(rr_intervals_list)

from hrvanalysis import plot_psd, plot_distrib
# nn_intervals_list contains integer values of NN Interval
plot_psd(rr_intervals_list, method="welch")
plot_distrib(rr_intervals_list, bin_length=8)

from hrvanalysis import plot_poincare

plot_poincare(rr_intervals_list)
plot_poincare(rr_intervals_list, plot_sd_features=True)
    low, high = 0.15, 0.4
    idx_delta = np.logical_and(freq >= low, freq <= high)
    freq_res = 0.00001
    delta_power_2 = simps(psd[idx_delta],x=freq[idx_delta], dx=freq_res)
    ratio = (delta_power_1/delta_power_2)
    print('LF/HF ratio: %.3f' % ratio)

    
    # Calculate of indices between desired frequency bands
    vlf_indexes = np.logical_and(freq >= vlf_band[0], freq < vlf_band[1])
    lf_indexes = np.logical_and(freq >= lf_band[0], freq < lf_band[1])
    hf_indexes = np.logical_and(freq >= hf_band[0], freq < hf_band[1])

    frequency_band_index = [vlf_indexes, lf_indexes, hf_indexes]
    label_list = ["VLF component", "LF component", "HF component"]

    
    if method == "welch":
        plt.title("FFT Spectrum : Welch's periodogram", fontsize=20)
        for band_index, label in zip(frequency_band_index, label_list):
            plt.fill_between(freq[band_index], 0, psd[band_index] / (1000 * len(psd[band_index])), label=label)
        plt.legend(prop={"size": 15}, loc="best")
        plt.xlim(0, hf_band[1])
        plt.show()
    else:
        raise ValueError("Not a valid method. Choose between 'lomb' and 'welch'")

plot_psd(rms, method="welch",sampling_frequency = Sampling_rate)