Currently, I have ECG sensor data, stored in dataframe df_data with column names ‘sample_number’ (x axis) and ‘data’(y axis). I detect peaks and store the location of peak as ‘Peak_sample’(xaxis) and ‘peak_data’ (y-axis) in df_BFI.
So, I have two dataframes
- df_data: This has ‘sample_number’ and ‘data’ as two columns
- df_BFI: This has column ‘Peak_sample’(this is subset of ‘sample_number in df_data) and ‘peak_data’(subset of ‘data’ in df_data)
I use each entry in df_BFI.Peak_sample(These values are present in df_data.data) and pick values from df_data.data to create an array of 60 values to the left of the peak detected.
df_BFI['p_left_60'] = df_BFI['Peak_sample'].apply(lambda p:df_data.loc[p-60:p, 'data'].to_list())#Make array of 60 samples
I check for any peak in this 60-sample range using argrelextrema.
df_data_BFI['turning_pts'] = df_data_BFI.p_left_60.apply(lambda p: np.array(argrelextrema(np.array(p),np.greater)))#find the turning points in 60 samples.
This returns me the array of positions of peaks in these 60 values.
I need to compare ‘data’ values at these positions from df_data and add to the next column in df_BFI if the ‘data’ value at these positions is >0.75% of ‘peak_data’ of df_BFI.
How to handle this?