ZeroCrossDetector
ZeroCrossDetector
A class to detect zero-crossings in a signal after applying a low-pass filter.
This detector processes input data to identify points where the signal crosses a specified threshold (both positive and negative), accounting for the phase delay introduced by the filter.
Attributes:
Name | Type | Description |
---|---|---|
f_cutoff |
float
|
Cutoff frequency of the low-pass filter in Hz. |
threshold |
float
|
Threshold for detecting zero-crossings. |
samplerate |
float
|
Sampling rate of the signal in Hz. |
_filter_coeff |
tuple
|
Coefficients of the low-pass filter. |
_filter_zi |
ndarray
|
Initial conditions for the filter. |
_last_filtered_sample |
float
|
Last sample of the filtered data. |
_first_run |
bool
|
Flag to indicate the first processing cycle. |
_last_zc_p |
int or None
|
Last positive zero-crossing index from the previous block. |
_last_zc_n |
int or None
|
Last negative zero-crossing index from the previous block. |
_filter_delay_samples |
float
|
Filter delay in samples due to phase shift. |
_filtered_data |
list
|
Temporary storage for filtered data during processing. |
__init__(f_cutoff, threshold, samplerate)
Initializes the ZeroCrossDetector with the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f_cutoff
|
float
|
Cutoff frequency of the low-pass filter in Hz. |
required |
threshold
|
float
|
Threshold for detecting zero-crossings. |
required |
samplerate
|
float
|
Sampling rate of the signal in Hz. |
required |
process(data)
Processes a block of input data and detect zero-crossings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
Input data block to be processed. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of zero-crossing points (in sample indices). |