dspk.ops.resample
Sample-rate changes on the device, with scipy.signal.decimate / resample_poly semantics.
decimate |
Lowers the sample rate by an integer factor, behind an anti-alias filter. |
resample_poly |
Changes the sample rate by up / down with a polyphase FIR filter. |
Functions
Section titled “Functions”decimate
Section titled “decimate”decimate( data, q: int, *, ftype: str = 'iir', order: int = DECIMATE_DEFAULT_ORDER, ripple_db: float = DECIMATE_DEFAULT_RIPPLE_DB, taps_per_factor: int = DECIMATE_FIR_TAPS_PER_FACTOR, runtime: str | None = None,) -> np.ndarrayLowers the sample rate by an integer factor, behind an anti-alias filter.
As scipy.signal.decimate(x, q, ftype=ftype, zero_phase=True).
Parameters
data:array_like
Signal(channels, samples). float32, int8, int16, uint16 and int32 arrays go to the device as they are and are converted there; other dtypes and lists become float32 first.q:int
Factor: everyq-th sample is kept,ceil(samples / q)samples out.ftype:{"iir", "fir"}, default'iir'
"iir": a zero-phase Chebyshev I oforderandripple_db, cut atDECIMATE_IIR_CUTOFFof the new Nyquist."fir": a Hammingfirwinoftaps_per_factor * q + 1taps, applied asresample_polydoes.order:int, defaultDECIMATE_DEFAULT_ORDER(8)
Order of the IIR filter.ripple_db:float, defaultDECIMATE_DEFAULT_RIPPLE_DB(0.05)
Passband ripple of the IIR filter, in dB.taps_per_factor:int, defaultDECIMATE_FIR_TAPS_PER_FACTOR(20)
FIR taps per unit ofq.runtime:str, defaultNone
A runtime fromruntime.available("cuda","hip","wgpu","cpu") for this call. By default: the one chosen withruntime.set, elseDSPK_RUNTIME, else the first available (GPUs first).
Returns
np.ndarray—(channels, ceil(samples / q)), float32.
Raises
ValueError: Forqbelow 1, an unknownftype, ordatanot 2-D.RuntimeError: When the runtime has no device.
Notes
With "iir", samples near the ends can differ slightly from scipy’s, which pads the edges
differently; the interior matches.
Examples
>>> import numpy as np>>> import dspk>>> x = np.random.default_rng(0).standard_normal((4, 30_000)).astype(np.float32)>>> lfp = dspk.ops.resample.decimate(x, 30)>>> lfp.shape(4, 1000)resample_poly
Section titled “resample_poly”resample_poly( data, up: int, down: int, *, beta: float = RESAMPLE_POLY_BETA, edge: str = RESAMPLE_POLY_DEFAULT_EDGE, runtime: str | None = None,) -> np.ndarrayChanges the sample rate by up / down with a polyphase FIR filter.
As scipy.signal.resample_poly: up-sample by up, low-pass with a Kaiser-windowed FIR,
down-sample by down.
Parameters
data:array_like
Signal(channels, samples). float32, int8, int16, uint16 and int32 arrays go to the device as they are and are converted there; other dtypes and lists become float32 first.up:int
Up-sampling factor.down:int
Down-sampling factor.beta:float, defaultRESAMPLE_POLY_BETA(5.0)
Kaiser window shape (larger: less ripple, wider transition).edge:{"zeros", "odd", "reflect", "nearest"}, defaultRESAMPLE_POLY_DEFAULT_EDGE(‘zeros’)
What the samples past each end are taken to be.runtime:str, defaultNone
A runtime fromruntime.available("cuda","hip","wgpu","cpu") for this call. By default: the one chosen withruntime.set, elseDSPK_RUNTIME, else the first available (GPUs first).
Returns
np.ndarray—(channels, ceil(samples * up / down)), float32.
Raises
ValueError: Forupordownbelow 1, an unknownedge, ordatanot 2-D.RuntimeError: When the runtime has no device.
Examples
>>> import numpy as np>>> import dspk>>> x = np.random.default_rng(0).standard_normal((4, 30_000)).astype(np.float32)>>> y = dspk.ops.resample.resample_poly(x, 2, 3)>>> y.shape(4, 20000)