rhenanbartels / hrv

A Python package for heart rate variability analysis
BSD 3-Clause "New" or "Revised" License
196 stars 58 forks source link

FrequencyDomainAnalysis class added: Plot graph and get features #29

Open PremchandGat opened 1 year ago

PremchandGat commented 1 year ago

Created a new class freq_domain. This class has three methods "getFeatures", "plot" and "getGraphDataPoints".

#Import modules:
from freqAnalysis import freq_domain
from hrv.rri import RRi
#Dummy data:
rri = RRi([1016, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168,
          1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192, 1168, 1632, 1192])
#create object:
obj = freq_domain(rri=rri, fs=4, method='welch',
                  interp_method='cubic', detrend='linear')
  1. getFeatures: This method returns the dictionary of LF, HF, Ratio between LF and HF, LFnu, HFnu, VLF, and Total power.
features = obj.getFeatures()
print(features)

output: {'lf': 0.023100473006951762, 'hf': 37404.08157812515, 'lf_hf_ratio': 6.175923063022486e-07, 'lfnu': 6.175919248822274e-05, 'hfnu': 99.99993824080751, 'total_power': 37411.41202473894, 'vlf': 7.307346140781096}

  1. plot: This method creates a chart between freq and PSD.

    #Plot chart
    obj.plot()

    Graph

  2. getGraphDataPoints: This method returns data points of the x-axis and y-axis of the chart(frequency and power spectral density[PSD] array).

    dataPoints = obj.getGraphDataPoints()
    print(dataPoints)

    Output: {'freq': array([0.00000000e+00, 9.76562500e-04, 1.95312500e-03, ..., 1.99804688e+00, 1.99902344e+00, 2.00000000e+00]), 'psd': array([3.17379998e+02, 6.31607217e+02, 6.22232520e+02, ..., 1.67977878e-01, 1.70170084e-01, 8.54533116e-02])}