Снимок экрана вывода, как показано ниже:

# Convert NN intervals to seconds
nn_intervals_sec = df_f['rr_intervals']/1000
# Create a time series for interpolation
time = np.cumsum(nn_intervals_sec)
# Ensure time has a standard numerical index
time = pd.Series(time.values, index=np.arange(len(time))) # Reset index
# Resample to fixed rate (e.g., 64 Hz)
resampled_time = np.arange(0, time.iloc[-1], 1/8) # Access last element using iloc
resampled_nn = np.interp(resampled_time, time.index, time.values) # Use index and values
# Welch's method for Power Spectral Density (PSD)
freqs, psd = welch(resampled_nn, fs=8, nperseg=128)
# Define frequency bands
lf_band = (0.04, 0.15)
hf_band = (0.15, 0.4)
window_size = 5
df['lf_power'] = df['rr_intervals'].rolling(window=window_size).apply(lambda x: np.trapz(psd[(freqs >= lf_band[0]) & (freqs = lf_band[0]) & (freqs = hf_band[0]) & (freqs = hf_band[0]) & (freqs
Подробнее здесь: https://stackoverflow.com/questions/793 ... io-using-p
Мобильная версия