Repository navigation
Iterative peak detection with ecg_peaks()? #1080
Replies: 1 comment
|
Hi Nikki! Sorry for getting back to you so late. Noise is definitely a difficult issue and unfortunately happens a lot and is a difficult task to automate. I hope you have been able to find a solution that fits your specific needs, but I will give a potential solution to your problem. My first thought would just be to remove the noisy data altogether manually (your second suggestion) such that you only apply the function on the actual good data. Just using numpy, I can come up with the following example: import numpy as np
# Pretend anything above 100 is a noisy area
data = np.array([1, 2, 3, 104, 105, 106, 7, 8, 9])
# Find the area of noise to takeout
noise_indices = np.arange(3, 6)
# Store the data somewhere else
bad_data = data[noise_indices]
# Create a mask for getting the "good" data
data_mask = np.ones(len(data), dtype=bool)
data_mask[noise_indices] = False
# Get the good data and perform some function (like peak detection)
good_data = data[data_mask]
# Do some function like getting the rpeak values (here just multiply by 2)
result = good_data * 2
# Readd the removed noise indices
result_data = np.zeros(len(data))
result_data[data_mask] = result
print(f"Original data: {data}")
print(f"Noisy data: {bad_data}")
print(f"Good data to apply the function to: {good_data}")
print(f"Our function result: {result}")
print(f"Our function result, adding the noisy section again: {result_data}")Output: This way you only applied the algorithm to the good data, but still have a one-to-one mapping with the original data! To answer your other question, the artifact correction in ecg_peaks does use the Perhaps if you remove the more heavy noise using manually removing the data (like in the above example) and try the artifact correction again on the more mild areas, perhaps this would then do a better job too. If you have found a solution already, please feel free to share it too! It would be great to have your input! |
Uh oh!
There was an error while loading. Please reload this page.
Hello! :)
I'm new to using neurokit and am currently analysing some ECG data, on which we want to run some HRV analyses. In our study, participants engage in 5min discussions, whilst their ECG is measured. Due to the naturalistic setting, we do have some motion and some noisy sections within the data. I completed the preprocessing and plotted all the data to see how well the peaks were being detected. For the noisy sections, I noticed that the algorithm still attempts to find peaks, so I was wondering whether there is a more robust or conservative approach of peak detection (which if in doubt can ignore these noisy sections completely)?
I am using artefact correction within ecg_peaks(), but based on the source code, I believe this doesn't offer (1) an iterative peak finding approach like nk.signal_fixpeaks() does, or (2) an option to automatically identify and ignore noisy sections? Apologies if it does! I was unable to find a list of all available kwargs for this.
I'm running this code in Jupyter Notebook:
And this is an example of a participant with a noisy section where peak detection was attempted:
Person 73

Person 68

Person 83

Thank you! :)
Nikki
All reactions