def test_signal_interpolate(): x_axis = np.linspace(start=10, stop=30, num=10) signal = np.cos(x_axis) interpolated = nk.signal_interpolate(signal, desired_length=1000) assert len(interpolated) == 1000 new_x = np.linspace(start=0, stop=40, num=1000) interpolated = nk.signal_interpolate(signal, desired_length=1000, x_axis=x_axis, new_x=new_x) assert len(interpolated) == 1000 assert interpolated[0] == signal[0]
def test_signal_interpolate(): x_axis = np.linspace(start=10, stop=30, num=10) signal = np.cos(x_axis) interpolated = nk.signal_interpolate(x_axis, signal, x_new=np.arange(1000)) assert len(interpolated) == 1000 assert interpolated[0] == signal[0] assert interpolated[-1] == signal[-1]
def _hrv_get_rri(peaks=None, sampling_rate=1000, interpolate=False, **kwargs): rri = np.diff(peaks) / sampling_rate * 1000 if interpolate is False: return rri else: # Minimum sampling rate for interpolation if sampling_rate < 10: sampling_rate = 10 # Compute length of interpolated heart period signal at requested sampling rate. desired_length = int(np.rint(peaks[-1])) rri = nk.signal_interpolate( peaks[ 1:], # Skip first peak since it has no corresponding element in heart_period rri, x_new=np.arange(desired_length), **kwargs) return rri, sampling_rate
for database in np.unique(file["Database"]): print(str(database)) data = file[file["Database"] == database] for participant in np.unique(data["Participant"]): data_participant = data[data["Participant"] == participant] sampling_rate = np.unique(data_participant["Sampling_Rate"])[0] rpeaks = data_participant["Rpeaks"].values # Interpolate rri = np.diff(rpeaks) / sampling_rate * 1000 desired_length = int( np.rint(rpeaks[-1] / sampling_rate * sampling_rate)) rri = nk.signal_interpolate(rpeaks[1:], rri, x_new=np.arange(desired_length)) # Get PSD psd = nk.signal_psd(rri, sampling_rate=sampling_rate) # # results = nk.hrv_frequency(rpeaks, sampling_rate=sampling_rate) # results["Participant"] = participant # results["Database"] = database # results["Recording_Length"] = rpeaks[-1] / sampling_rate / 60 # # all_results = pd.concat([all_results, results], axis=0) # #all_results.to_csv("data.csv", index=False)