Skip to main content

Spectrogram

Struct Spectrogram 

Source
pub struct Spectrogram { /* private fields */ }
Expand description

A short-time Fourier transform (STFT) result.

Data layout: (num_channels, num_frames, num_freq_bins). Use channel for per-channel access and frame for per-frame access.

Frame times and frequency bins are derived from the sample rate, window size and hop size, so they always match the data.

Implementations§

Source§

impl Spectrogram

Source

pub fn raw_magnitude(&self) -> Array3<f64>

Source

pub fn raw_magnitude_db(&self, floor_db: f64) -> Array3<f64>

Source

pub fn amplitude_spectrum(&self) -> Array3<f64>

Source

pub fn amplitude_spectrum_db(&self, floor_db: f64) -> Array3<f64>

Source

pub fn power_spectrum(&self) -> Array3<f64>

Source

pub fn power_spectrum_db(&self, floor_db: f64) -> Array3<f64>

Source

pub fn power_spectral_density(&self) -> Array3<f64>

Source

pub fn power_spectral_density_db(&self, floor_db: f64) -> Array3<f64>

Source§

impl Spectrogram

Source

pub fn new( data: Array3<Complex64>, sample_rate: f64, window_size: usize, hop_size: usize, window_fn: WindowFn, ) -> Result<Self, SignalError>

Wrap STFT data, shape (num_channels, num_frames, num_freq_bins).

Frame f is centred at (f * hop_size + window_size / 2) / sample_rate seconds and bin k sits at k * sample_rate / window_size Hz. The data must have window_size / 2 + 1 bins, as a real FFT of that size gives. The calibration gains are computed from window_fn, the periodic window the frames were tapered with.

Source

pub fn channel_label(&self, channel: usize) -> Option<&str>

Source

pub fn set_channel_label(&mut self, channel: usize, label: Option<&str>)

Source

pub fn num_channels(&self) -> usize

Source

pub fn num_frames(&self) -> usize

Source

pub fn num_freq_bins(&self) -> usize

Source

pub fn sample_rate(&self) -> f64

Source

pub fn window_size(&self) -> usize

Source

pub fn hop_size(&self) -> usize

Source

pub fn window_fn(&self) -> WindowFn

The window the frames were tapered with (its periodic form).

Source

pub fn normalization(&self) -> SpectrogramNormalization

Calibration gains of window_fn at window_size samples.

Source

pub fn frame_times(&self) -> CowArray<'_, f64, Ix1>

Center time of each STFT frame in seconds. Computed on each call; use frame_axis for single values.

Source

pub fn frame_axis(&self) -> &XAxis

Frame time axis in seconds, without allocating.

Source

pub fn freq_bins(&self) -> CowArray<'_, f64, Ix1>

Frequency bin centers in Hz. Computed on each call; use freq_axis for single values.

Source

pub fn freq_axis(&self) -> &XAxis

Frequency axis in Hz, without allocating.

Source

pub fn data(&self) -> ArrayView3<'_, Complex64>

Raw complex STFT data, shape (num_channels, num_frames, num_freq_bins).

Source

pub fn channel(&self, ch: usize) -> ArrayView2<'_, Complex64>

Complex STFT data for a single channel, shape (num_frames, num_freq_bins).

Source

pub fn frame(&self, t: usize) -> ArrayView2<'_, Complex64>

Complex STFT data for a single frame, shape (num_channels, num_freq_bins).

Trait Implementations§

Source§

impl Clone for Spectrogram

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Spectrogram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Spectrogram

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Spectrogram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Spectrogram

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Spectrogram

Available on crate feature serde only.

Stored form: the data plus what cannot be derived from it. Frame times, frequency bins and calibration gains are rebuilt when reading, through Spectrogram::new.

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Spectrogram

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<F> ResampleSample for F

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more