Signal-to-noise ratio (snr)

Calculation

  • \(A_{\mu s}\) : maximum amplitude of the mean spike waverform (on the best channel).

  • \(\sigma_b\) : standard deviation of the background noise on the same channel (usually computed via the median absolute deviation).

\[\textrm{SNR} = \frac{A_{\mu s}}{\sigma_b}\]

Expectation and use

A high SNR unit has a signal which is greater in amplitude than the background noise and is likely to correspond to a neuron [Jackson], [Lemon]. A low SNR value (close to 0) suggests that the unit is highly contaminated by noise (type I error).

Example code

Without SpikeInterface:

import numpy as np
import scipy.stats

data        # The data from your recording in shape (channel, time)
mean_wvf    # The mean waveform of your unit in shape (channel, time)
# If your data is filtered, then both data and mean_wvf need to be filtered the same.

best_channel = np.argmax(np.max(np.abs(mean_wvf), axis=1))
noise_level = scipy.stats.median_abs_deviation(data[best_channel], scale="normal")
amplitude = np.max(np.abs(mean_wvf))

SNR = amplitude / noise_level

With SpikeInterface:

import spikeinterface.qualitymetrics as qm

# Make recording, sorting and wvf_extractor object for your data.

SNRs = qm.compute_snrs(wvf_extractor)
# SNRs is a dict containing the units' ID as keys and their SNR as values.

References

Various cluster quality metrics.

Some of then come from or the old implementation: * https://github.com/AllenInstitute/ecephys_spike_sorting/tree/master/ecephys_spike_sorting/modules/quality_metrics * https://github.com/SpikeInterface/spikemetrics

Implementations here have been refactored to support the multi-segment API of spikeinterface.

spikeinterface.qualitymetrics.misc_metrics.compute_snrs(waveform_extractor, peak_sign: str = 'neg', peak_mode: str = 'extremum', **kwargs)

Compute signal to noise ratio.

Parameters
waveform_extractorWaveformExtractor

The waveform extractor object.

peak_sign{‘neg’, ‘pos’, ‘both’}

The sign of the template to compute best channels.

peak_mode: {‘extremum’, ‘at_index’}

How to compute the amplitude. Extremum takes the maxima/minima At_index takes the value at t=0

Returns
snrsdict

Computed signal to noise ratio for each unit.

Literature

Presented by Lemon and useful initial discussion by Jackson.

Citations

Jackson

Jadin Jackson, Neil Schmitzer-Torbert, K.D. Harris, and A.D. Redish. Quantitative assessment of extracellular multichannel recording quality using measures of cluster separation. Soc Neurosci Abstr, 518, 01 2005.

Lemon
  1. Lemon. Methods for neuronal recording in conscious animals. IBRO Handbook Series, 4:56–60, 1984.