sigpyproc.core.filters#
Matched filter class for pulse detection in 1D time series data.
This module contains the MatchedFilter class for pulse detection in 1D time series data. It uses a set of pulse templates with varying widths and selects the template that produces the highest signal-to-noise ratio (SNR) as the best match.
Classes
Matched filter class for pulse detection in 1D time series data. |
|
1D pulse template class for matched filtering. |
- class sigpyproc.core.filters.MatchedFilter(data, loc_method='median', scale_method='iqr', temp_kind='boxcar', nbins_max=32, spacing_factor=1.5)[source]#
Bases:
objectMatched filter class for pulse detection in 1D time series data.
This class implements a matched filter algorithm to detect pulses of varying durations in 1D time series data. It uses a set of pulse templates with varying widths and selects the template that produces the highest signal-to-noise ratio (SNR) as the best match.
- Parameters:
- data
ndarray Input data array for matched filtering (1D).
- loc_method{“median”, “mean”, “norm”}, optional
Method to estimate location, by default “median”.
- scale_method
str, optional Method to estimate scale, by default “iqr”.
- temp_kind{“boxcar”, “gaussian”, “lorentzian”}, optional
Type of the pulse template, by default “boxcar”.
- nbins_max
int, optional Maximum number of bins for template width, by default 32.
- spacing_factor
float, optional Factor for spacing between template widths, by default 1.5.
- data
- Attributes:
dataInput data array for matched filtering.
zscoresComputed Z-scores of the input data.
temp_kindType of the pulse template.
temp_widthsTemplate widths used for matched filtering.
temp_bankList of pulse templates used for matched filtering.
convsConvolution results for all templates.
peak_binBest match template peak bin.
best_tempBest match template.
snrSignal-to-noise ratio based on best match template.
best_modelBest match template fit scaled by SNR and data Z-scores.
on_pulseBest match template pulse region.
Methods
get_box_width_spacing(size_max[, spacing_factor])Get box width spacing for matched filtering.
plot([figsize, dpi])Plot the pulse template.
- Raises:
ValueErrorIf the input
datadimension is not 1.
See also
sigpyproc.core.stats.estimate_zscoreEstimate Z-score of input data.
sigpyproc.core.stats.estimate_locEstimate location of input data.
sigpyproc.core.stats.estimate_scaleEstimate scale of input data.
Notes
The matched filter is the optimal linear filter for maximizing the signal-to-noise ratio (SNR) of a known pulse template in the presence of additive white noise.
For input data \(x(t)\) and a template \(h(t)\), the matched filter output \(y(t)\) is:
\[y(t) = (x \star h)(t) = \sum_{\tau} x(\tau) h(t - \tau)\]This is computed efficiently using the FFT-based methods. As per the circular convolution theorem:
\[Y(f) = X(f) H(f)\]\[y(t) = \mathcal{F}^{-1}(Y(f))\]where \(\mathcal{F}^{-1}\) is the inverse Fourier transform, \(X(f)\) and \(H(f)\) are the Fourier transforms of \(x(t)\) and \(h(t)\) respectively.
References
[1]Wikipedia, “Matched filter”, https://en.wikipedia.org/wiki/Matched_filter
[2]Wikipedia, “Circular convolution”, https://en.wikipedia.org/wiki/Circular_convolution
- property zscores#
Computed Z-scores of the input data.
- Returns:
ZScoreResultZ-score of the input data.
- property temp_bank#
List of pulse templates used for matched filtering.
- property snr#
Signal-to-noise ratio based on best match template.
- Returns:
floatSignal-to-noise ratio.
- property best_model#
Best match template fit scaled by SNR and data Z-scores.
- Returns:
ndarrayBest match template fit.
- property on_pulse#
Best match template pulse region.
- class sigpyproc.core.filters.Template(data, width, ref_bin=attr_dict['ref_bin'].default, ref=attr_dict['ref'].default, kind=attr_dict['kind'].default)[source]#
Bases:
object1D pulse template class for matched filtering.
This class represents various pulse shapes as templates for matched filtering and provides methods to generate and visualize them.
- Parameters:
- data
ndarray Pulse template data array (1D).
- width
float Width of the pulse template in bins.
- ref_bin
int, optional Reference bin for the pulse template, by default 0.
- ref{“start”, “peak”}, optional
Reference type for the pulse template, by default “start”.
- kind
str, optional Type of the pulse template, by default “custom”.
- data
- Attributes:
- data
- width
- ref_bin
- ref
- kind
Methods
gen_boxcar(width)Generate a boxcar pulse template.
gen_gaussian(width[, extent])Generate a Gaussian pulse template.
gen_lorentzian(width[, extent])Generate a Lorentzian pulse template.
get_model(peak_bin, nbins)Get profile model for the pulse template.
get_on_pulse(peak_bin, nbins)Get on pulse region in the profile model for the pulse template.
plot([figsize, dpi])Plot the pulse template.
- Raises:
ValueErrorIf the input data array is empty or not 1D. If the reference bin is out of bounds.
- data#
- width#
- ref_bin#
- ref#
- kind#
- get_on_pulse(peak_bin, nbins)[source]#
Get on pulse region in the profile model for the pulse template.