Signal-to-noise ratio (snr)
Calculation
\(A_{\mu s}\) : maximum amplitude of the median 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).
The amplitude, bu default, is the amplitude of the largest peak (positive or negative) of the median waveform on the best channel.
If the waveforms extension is not available, the amplitude is computedon the average waveform.
The noise level is computed using the median absolute deviation of the signal on the best channel, which is a robust
estimator of the standard deviation of the noise.
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.metrics.quality as sqm
# Combining sorting and recording into a sorting_analzyer
SNRs = sqm.compute_snrs(sorting_analzyer=sorting_analzyer)
# SNRs is a dict containing the unit IDs as keys and their SNRs as values.
Links to original implementations
From the AllenSDK
References
- spikeinterface.metrics.quality.misc_metrics.compute_snrs(sorting_analyzer, unit_ids=None, peak_sign: str = 'both', peak_mode: str = 'extremum', operator: str = 'median')
Compute signal to noise ratio.
- Parameters:
- sorting_analyzerSortingAnalyzer
A SortingAnalyzer object.
- unit_idslist or None
The list of unit ids to compute the SNR. If None, all units are used.
- peak_sign“neg” | “pos” | “both”, default: “neg”
The sign of the template to compute best channels.
- peak_mode“extremum” | “at_index” | “peak_to_peak”, default: “extremum”
How to compute the amplitude. Extremum takes the maxima/minima At_index takes the value at t=sorting_analyzer.nbefore.
- operator“median” | “average”, default: “median”
The operator to apply to retrieve templates and amplitudes.
- Returns:
- snrsdict
Computed signal to noise ratio for each unit.
Literature
Presented by [Lemon] and useful initial discussion by [Jackson].