I encountered the following problem while analyzing PPG data using the cardioception package and systole for a Heartbeat counting task. While analyzing the data, I came across the following error and am posting this to inquire about a solution.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[43], line 6
2 for nTrial in range(6):
4 print(f'Analyzing trial number {nTrial+1}')
----> 6 signal, peaks = ppg_peaks(ppg[str(nTrial)][0], clean_extra=True, sfreq=25, new_sfreq=1000)
7 axs = plot_raw(
8 signal=signal, sfreq=1000, figsize=(18, 5), clean_extra=True,
9 show_heart_rate=True
10 );
12 # Show the windows of interest
13 # We need to convert sample vector into Matplotlib internal representation
14 # so we can index it easily
File [c:\Users\user\anaconda3\envs\cardioception\lib\site-packages\systole\detection.py:133](file:///C:/Users/user/anaconda3/envs/cardioception/lib/site-packages/systole/detection.py:133), in ppg_peaks(signal, sfreq, win, new_sfreq, clipping, clipping_thresholds, moving_average, moving_average_length, peak_enhancement, distance, clean_extra, clean_nan, verbose)
131 time = np.arange(0, len(x) / sfreq, 1 / sfreq)
132 new_time = np.arange(0, len(x) / sfreq, 1 / new_sfreq)
--> 133 x = np.interp(new_time, time, x)
135 # Copy resampled signal for output
136 resampled_signal = np.copy(x)
File <__array_function__ internals>:180, in interp(*args, **kwargs)
File [c:\Users\user\anaconda3\envs\cardioception\lib\site-packages\numpy\lib\function_base.py:1570](file:///C:/Users/user/anaconda3/envs/cardioception/lib/site-packages/numpy/lib/function_base.py:1570), in interp(x, xp, fp, left, right, period)
1567 xp = np.concatenate((xp[-1:]-period, xp, xp[0:1]+period))
1568 fp = np.concatenate((fp[-1:], fp, fp[0:1]))
-> 1570 return interp_func(x, xp, fp, left, right)
ValueError: fp and xp are not of the same length.
To debug the issue, I used np.arange and found that the length of time and x do not match.
x = ppg['2'][0]
time = np.arange(0, len(x)/25, 0.04)
new_time = np.arange(0, len(x) / 25, 1/1000)
# x = np.interp(new_time, time, x)
print(len(time), len(new_time))
print(len(x))
It doesn't match. maybe /25 and * 25 makes some error due to 946/25*25=946.0000000000001
Is there a good way to solve this issue? I appreciate any suggestions.