apfrequency: Make it more robust
The problem is that it is not robust to fluctuations around spike threshold.
-
User should be able to set FWHM of spikes and height above threshold
-
[x] ~~TJ will provide good and bad data~~
-
[ ] Copy what ipfx does (chat with Nathan)
The basic spike detection procedure implemented in IPFX is:
- Identify putative spikes as places where the dV/dt equals or exceeds 20 mV/ms (dV/dt values are taken from a Bessel-filtered version of the voltage trace with a 10 kHz cutoff frequency)
- Find putative AP peaks (max Vm between those detected points)
- Find the maximum dV/dt between the initially detected points and the putative peaks, then define the putative spike threshold as the point were it reaches 5% of that max value
- Drop putative APs where any of the following occur:
- threshold to peak is less than 2 mV
- threshold-to-peak time greater than 2 ms
- putative peak is below -30 mV
- Refine the spike thresholds by finding the point for each AP where the dV/dt is 5% of the average maximum dV/dt across all APs in the sweep (rather than its own specific max dV/dt as before)
That's the basic idea - there are some other checks/dealing with edge cases in the code (like trying to figure out if a voltage transient may be throwing off threshold/peak pairs, and that kind of thing), and there are some adjustments to the initial 20 mV/ms dV/dt detection threshold for short square sweeps where the initial passive rise in the membrane potential can exceed that value in some cells.