def _computeSignal(self, signal): obj = {} parsCount = 0 HZ = len(signal) / 120 HZstep = 1000 / HZ stats = time_domain(signal).stats peaks = getPeaks(signal) peaks_diff = tools.nni_diff(peaks) peaks_diff_ms = peaks_diff * HZstep M = np.mean(peaks_diff_ms) sdnn_ms = np.std(peaks_diff_ms) cv = (sdnn_ms / M) * 100 n, bins, _ = plt.hist(peaks_diff_ms) M0 = bins[np.argmax(n)] AM0 = (sum(n) / 100) * max(n) vr = np.var(bins) IN = AM0 / (2 * M0 * vr) parsCount += abs(self._firstParam(M)) parsCount += abs(self._secoundParam(sdnn_ms, vr / M, cv)) parsCount += abs(self._thirdParam(vr, AM0, IN)) parsCount += abs(self._fourthParam(cv)) parsCount += abs( self._fifthParam(stats['VLF'], stats['LF'], stats['HF'])) return parsCount
def nnXX(nni=None, rpeaks=None, threshold=None): """Find number of NN interval differences greater than a specified threshold and ratio between number of intervals > threshold and total number of NN interval differences. References: [Electrophysiology1996], [Ewing1984] Docs: https://pyhrv.readthedocs.io/en/latest/_pages/api/time.html#nnxx-nnxx Parameters ---------- nni : array NN intervals in [ms] or [s]. rpeaks : array R-peak times in [ms] or [s]. threshold : int Threshold for nnXX values in [ms]. Returns (biosppy.utils.ReturnTuple Object) ------------------------------------------ [key : format] Description. nnXX: int Number of NN interval differences greater than the specified threshold [-]. pnnXX : float Ratio between nnXX and total number of NN interval differences [-]. Notes ----- .. Only one type of input data is required .. If both 'nni' and 'rpeaks' are provided, 'nni' will be chosen over the 'rpeaks' .. NN and R-peak series provided in [s] format will be converted to [ms] format .. The ``XX`` in the ``nnXX`` and the ``pnnXX`` keys are substituted by the specified threshold (``threshold``). For instance, ``nnXX(nni, threshold=30)`` returns the custom ``nn30`` and ``pnn30`` parameters. Using a ``threshold=30`` as ``nnXX(nni, threshold=35`` returns the custom ``nn35`` and ``pnn35`` parameters. """ # Check input nn = tools.check_input(nni, rpeaks) # Check threshold if threshold is None: raise TypeError( "No threshold specified. Please specify a [ms] threshold.") if threshold <= 0: raise ValueError( "Invalid value for 'threshold'. Value must not be <= 0.") # Count NN20 nnd = tools.nni_diff(nn) nnxx = sum(i > threshold for i in nnd) pnnxx = nnxx / len(nnd) * 100 # Output args = (nnxx, pnnxx) names = ('nn%i' % threshold, 'pnn%i' % threshold) return utils.ReturnTuple(args, names)
def nni_differences_parameters(nni=None, rpeaks=None): """Computes basic statistical parameters from a series of successive NN interval differences (mean, min, max, standard deviation). Parameters ---------- nni : array NN intervals in [ms] or [s]. rpeaks : array R-peak times in [ms] or [s]. Returns (biosppy.utils.ReturnTuple Object) ------------------------------------------ [key : format] Description. nni_diff_mean: float Mean NN interval difference [ms]. nni_diff_min : float Minimum NN interval difference [ms]. nni_diff_max : float Maximum NN interval difference [ms]. Notes ----- .. Only one type of input data is required. .. If both 'nni' and 'rpeaks' are provided, 'nni' will be chosen over the 'rpeaks' .. NN and R-peak series provided in [s] format will be converted to [ms] format. """ # Check input nn = tools.check_input(nni, rpeaks) # Get NN interval differences nnd = tools.nni_diff(nn) # output args = ( float(nnd.mean()), int(nnd.min()), int(nnd.max()), ) names = ( 'nni_diff_mean', 'nni_diff_min', 'nni_diff_max', ) return utils.ReturnTuple(args, names)
def sdsd(nni=None, rpeaks=None): """Computation of the standard deviation of differences of successive NN intervals. References: [Electrophysiology1996] Docs: https://pyhrv.readthedocs.io/en/latest/_pages/api/time.html#sdsd-sdsd Parameters ---------- nni : array NN intervals in [ms] or [s]. rpeaks : array R-peak times in [ms] or [s]. Returns (biosppy.utils.ReturnTuple Object) ------------------------------------------ [key : format] Description. sdsd : float Standard deviation of successive differences of NN intervals [ms] Notes ----- .. Only one type of input data is required .. If both 'nni' and 'rpeaks' are provided, 'nni' will be chosen over the 'rpeaks' .. NN and R-peak series provided in [s] format will be converted to [ms] format """ # Check input nn = tools.check_input(nni, rpeaks) # Compute NN differences nnd = tools.nni_diff(nn) # Computation of SDNN sdsd_ = tools.std(nnd) # Output args = [sdsd_] names = ['sdsd'] return utils.ReturnTuple(args, names)
def rmssd(nni=None, rpeaks=None): """Computes root mean of squared differences of successive NN Intervals. References: [Electrophysiology1996], [Lohninger2017] Docs: https://pyhrv.readthedocs.io/en/latest/_pages/api/time.html#rmssd-rmssd Parameters ---------- nni : array NN intervals in [ms] or [s]. rpeaks : array R-peak times in [ms] or [s]. Returns (biosppy.utils.ReturnTuple Object) ------------------------------------------ [key : format] Description. rmssd : float RMSSD value in [ms]. Notes ----- .. Only one type of input data is required .. If both 'nni' and 'rpeaks' are provided, 'nni' will be chosen over the 'rpeaks' .. NN and R-peak series provided in [s] format will be converted to [ms] format """ # Check input nn = tools.check_input(nni, rpeaks) # Compute RMSSD nnd = tools.nni_diff(nn) rmssd_ = np.sum(x**2 for x in nnd) rmssd_ = np.sqrt(1. / nnd.size * rmssd_) # Output args = (rmssd_, ) names = ('rmssd', ) return utils.ReturnTuple(args, names)
def _computeSignal(self, signal): obj = {} # Best min_dist & thres for sphygmogram signal peaks = peak.indexes(signal, min_dist=56, thres=0.16) # Ignore un normal signls (with no peaks) if (len(peaks) == 0): return obj nn = tools.nn_intervals(peaks) # Ignore un normal signls (with no NN) if (len(nn) == 0): return # Standard obj = dict(td.nni_parameters(nn, peaks), **obj) obj = dict(td.nni_differences_parameters(nn, peaks), **obj) obj = dict(td.sdnn(nn, peaks), **obj) obj = dict(td.sdnn_index(nn, peaks), **obj) obj = dict(td.sdann(nn, peaks), **obj) obj = dict(td.rmssd(nn, peaks), **obj) obj = dict(td.sdsd(nn, peaks), **obj) obj = dict(td.nn50(nn, peaks), **obj) obj = dict(td.nn20(nn, peaks), **obj) obj = dict(td.geometrical_parameters(nn, peaks, plot=False), **obj) del obj['nni_histogram'] # Additional obj = dict({'cv': self._cv(obj['sdnn'], obj['nni_mean'])}, **obj) peaks_diff = tools.nni_diff(peaks) obj = dict({'MxDMn': max(peaks_diff) - min(peaks_diff)}, **obj) obj = dict({'MxRMn': max(peaks_diff) / min(peaks_diff)}, **obj) obj = dict({'Mo': stats.mode(peaks_diff)[0][0]}, **obj) counter = Counter(peaks_diff) idx = list(counter.keys()).index(obj["Mo"]) obj = dict({'AMo': list(counter.values())[idx]}, **obj) obj = dict({'SI': obj['AMo'] / (2 * obj['Mo'] * obj['MxDMn'])}, **obj) # Autocorrelation function # Frequency stats welch = frequency_domain(signal).stats['welch']['params'] bands = list(welch['fft_bands'].keys()) obj = dict({'TP': welch['fft_total']}, **obj) obj = dict({'HF': welch['fft_rel'][bands.index('hf')]}, **obj) obj = dict({'LF': welch['fft_rel'][bands.index('lf')]}, **obj) obj = dict({'VLF': welch['fft_rel'][bands.index('vlf')]}, **obj) obj = dict({'ULF': welch['fft_rel'][bands.index('ulf')]}, **obj) obj = dict({'HFav': welch['fft_abs'][bands.index('hf')]}, **obj) obj = dict({'LFav': welch['fft_abs'][bands.index('lf')]}, **obj) obj = dict({'VLFav': welch['fft_abs'][bands.index('vlf')]}, **obj) obj = dict({'ULFav': welch['fft_abs'][bands.index('ulf')]}, **obj) obj = dict({'(LF/HF)av': obj['LFav'] / obj['HFav']}, **obj) obj = dict({'IC': obj['LF'] / obj['VLF']}, **obj) for k in obj: if (math.isnan(obj[k])): obj[k] = 0 return obj