Skip to main content

Signal

Struct Signal 

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

A complex baseband waveform, [n_streams, n_samples], with its sample rate.

Implementations§

Source§

impl Signal

Source

pub fn new(data: Array2<C64>, sample_rate: Hertz) -> Signal

A waveform from its samples ([n_streams, n_samples]) and its sample rate.

Source

pub fn zeros(n_streams: usize, n_samples: usize, sample_rate: Hertz) -> Signal

n_streams streams of n_samples zeros.

Source

pub fn from_stream(x: Vec<C64>, sample_rate: Hertz) -> Result<Signal>

A single-stream waveform.

§Errors

Never in practice (see Symbols::from_stream).

Source

pub fn from_streams(streams: &[Vec<C64>], sample_rate: Hertz) -> Result<Signal>

A waveform from several streams of equal length.

§Errors

Error::Shape if the streams have different lengths.

Source

pub fn sample_rate(&self) -> Hertz

Sample rate.

Source

pub fn n_streams(&self) -> usize

Number of streams.

Source

pub fn len(&self) -> usize

Number of samples per stream.

Source

pub fn is_empty(&self) -> bool

Whether the streams are empty.

Source

pub fn stream(&self, i: usize) -> &[C64] ⓘ

Stream i as a slice.

Source

pub fn stream_view(&self, i: usize) -> ArrayView1<'_, C64>

Stream i as an ndarray view.

Source

pub fn stream_mut(&mut self, i: usize) -> &mut [C64] ⓘ

Stream i as a mutable slice.

Source

pub fn to_streams(&self) -> Vec<Vec<C64>>

The streams, one vector each (the inverse of Signal::from_streams).

§Examples
use comnum_core::signal::Signal;
use comnum_core::units::Hertz;
use num_complex::Complex64 as C64;
let streams = vec![vec![C64::new(1.0, 0.0); 3], vec![C64::new(0.0, 1.0); 3]];
let x = Signal::from_streams(&streams, Hertz(1.0))?;
assert_eq!(x.to_streams(), streams);
Source

pub fn as_array(&self) -> &Array2<C64>

The samples, [n_streams, n_samples].

Source

pub fn as_array_mut(&mut self) -> &mut Array2<C64>

The samples, mutable.

Source

pub fn resize(&mut self, n_streams: usize, n_samples: usize, sample_rate: Hertz)

Resize to n_streams × n_samples at sample_rate (the content is reset when the shape changes), for the _into methods.

Source

pub fn set_stream(&mut self, x: &[C64], sample_rate: Hertz)

Make self the single stream x at sample_rate, reusing its storage when the length is unchanged (ADR 0011).

Source

pub fn assign(&mut self, other: &Signal)

Make self a copy of other, reusing its storage when the shape is unchanged (ADR 0011).

Source

pub fn set_streams( &mut self, streams: &[Vec<C64>], sample_rate: Hertz, ) -> Result<()>

Make self the streams streams at sample_rate, reusing its storage when the shape is unchanged (ADR 0011).

§Errors

Error::Shape if the streams have different lengths (self is then left unchanged).

Source

pub fn try_map_streams( &self, out: &mut Signal, f: impl FnMut(usize, &[C64]) -> Result<Vec<C64>>, ) -> Result<()>

Fill out with f(stream index, stream) for every stream of self, at the same shape and sampling rate: the body of the _into methods of the blocks that process the streams independently.

§Errors

The first error of f; Error::Shape if f returns another number of samples than it was given, rather than leaving the samples of an earlier use of out in place.

Source

pub fn map_streams( &self, out: &mut Signal, f: impl FnMut(usize, &[C64]) -> Vec<C64>, )

Signal::try_map_streams for an f that cannot fail.

§Panics

If f returns another number of samples than it was given (a broken invariant of the calling block).

Source

pub fn map_streams_in_place( &self, out: &mut Signal, f: impl FnMut(usize, &mut [C64]), )

Make out a copy of self (its storage reused when the shape is unchanged, ADR 0011), then apply f(stream index, stream) to every stream of out in place: the body of the _into methods of the blocks that transform the samples where they are, with no allocation per stream.

§Examples
use comnum_core::signal::Signal;
use comnum_core::units::Hertz;
use num_complex::Complex64 as C64;
let x = Signal::from_streams(&[vec![C64::new(1.0, 0.0); 3], vec![C64::new(0.0, 1.0); 3]], Hertz(1.0))?;
let mut out = Signal::zeros(0, 0, Hertz(1.0));
x.map_streams_in_place(&mut out, |s, y| y.iter_mut().for_each(|v| *v *= (s + 1) as f64));
assert_eq!(out.stream(1), &[C64::new(0.0, 2.0); 3]);
Source

pub fn power(&self) -> Vec<f64>

Mean power of every stream, mean(|x|²).

Trait Implementations§

Source§

impl Clone for Signal

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 Signal

Source§

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

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

impl PartialEq for Signal

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 StructuralPartialEq for Signal

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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.