Find_ecg_events

Hi everyone, I have been using the find_ecg_events() function to determine how many time points contain ECG artifacts.

Could someone explain what the parameters (event_id, qrs_threshold, and filter_length) in this function mean?
I read through the documentation, but I am still unsure about these parameters.

Information:

  • MNE version: 1.0.3
  • operating system: Windows 11

Thank you!

one thing that the function returns is an events array, which has sample numbers in the first column and integer event codes in the last column (the middle column is usually all zeros and can usually be ignored; more info on that in the sidebar here). the event_id parameter is a way for you to decide what integer event code to use for the heartbeat events. For most users the default 999 is fine, but if you happened to have an event array for epoching where one of your event codes was 999 then you’d probably want to change the heartbeat event code to something different.

QRS threshold refers to the QRS complex - Wikipedia which is the stereotypical electrical pattern created by heartbeats. To be honest I’m not sure exactly how this works, but changing it affects the sensitivity of the heartbeat detector. If you’re seeing some heartbeats get missed or some false positives, adjust this number until the results look good for that subject. Here again, usually the default of “auto” is fine for most use cases (which will try a few different values of threshold and keep the one that gives most plausible results, given what we know about physiologically plausible heartrates).

For filter_length — I agree that the documentation is pretty bad there! The default is a string "10s" and the description is “number of taps”. Here I think DSP Guru has a pretty clear explanation:

A FIR “tap” is simply a coefficient/delay pair. The number of FIR taps, (often designated as “N”) is an indication of 1) the amount of memory required to implement the filter, 2) the number of calculations required, and 3) the amount of “filtering” the filter can do; in effect, more taps means more stopband attenuation, less ripple, narrower filters, etc.

I don’t know offhand how we internally convert "10s" to some number of taps / the filter order. Perhaps @larsoner can fill in some more details, and then you could make a pull request to improve that docstring!

1 Like

“Taps” are the same thing as the filter length, and are equal to the filter order plus one. See e.g.:

For the duration → taps/length conversion, it’s just a multiplication with the sample rate of the data (plus a conversion from the resulting float to int).

PR welcome to add to Background information on filtering — MNE 1.3.dev0 documentation to help clarify these points!

Thank you for your replies. I apologize for not responding to your messages sooner; I was very busy for the past few weeks.

Additionally, thank you for this detailed explanation. I found it helpful for my understanding of the parameters. I ultimately did not end up using this function, but if I ever need it in the future, I can come back to this post. Again, thank you so much!