MedianFrequency

class of dascore.transform.spectral_descriptors
inherits from: dascore.transform.spectral_descriptors._SharedFields, dascore.transform.spectral_descriptors._SpectralDescriptor, PatchProcessor, DascoreBaseModel, pydantic.main.BaseModel
source

MedianFrequency(
    *args ,
    dim: Any = None,
    fmin: Any = None,
    fmax: Any = None,
    spectral_format: Any = auto,
    negative_frequencies: Any = auto,
)-> None

Compute the median frequency of a Fourier-domain patch.

This measure divides a signal’s power spectrum into two regions of equal total power. The input patch must already be transformed with Patch.dft or Patch.stft.

See for more detail: - (Phinyomark12?) - Online version of the Phinyomark publication - Matlab’s medfreq

Parameters

Parameter Description
dim Frequency dimension over which to compute the descriptor. This can be
either the original dimension name, such as "time", or the Fourier
dimension name, such as "ft_time". If omitted, a single Fourier
dimension is inferred.
fmin Optional lower frequency bound.
fmax Optional upper frequency bound.
spectral_format Representation of the spectral data. "auto" uses DASCore DFT/STFT
metadata when available. Other options are "fft" for complex Fourier
coefficients, "amplitude" for amplitude spectra, "power" for
power spectra, and "density" for power spectral densities.
negative_frequencies How to handle negative frequency bins. "auto" drops negative bins
when power is symmetric and raises otherwise, folding a verified
negative Nyquist bin to positive frequency without changing its
power. "drop" always uses
non-negative frequencies, "raise" rejects spectra with negative bins, and
"keep" includes them in the calculation.

Returns

The Patch instance with the median-frequency as data.

Example

import dascore as dc
import matplotlib.pyplot as plt

patch = dc.examples.get_example_patch('example_event_2')

fig, axs = plt.subplots(1,2, layout='constrained', figsize=(12,4))
ax = patch.viz.waterfall(cmap='seismic', ax=axs[0])

spec = patch.stft(time=.02, overlap=.019, taper_window="boxcar")
med = spec.median_frequency(fmin=50, fmax=300)
ax = med.viz.waterfall(cmap='turbo', ax=axs[1], scale=[0,1])

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
describe Return the frequency which halves the power.
get_metadata Return the reduced metadata, and the bins and format to read.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
numpy_kernel Return the descriptor of the power in the bins kept.
median_frequency Compute the median frequency of a Fourier-domain patch.
reconcile Return metadata or a patch holding the final data; default as is.
result_dtype Return the dtype describe returns for power of dtype power.
run Run the operation: check, get_metadata, kernel, reconcile, record.
units Return the output’s data units: the frequencies’ by default.