Struct gw_signal::timeseries::TimeSeries

source ·
pub struct TimeSeries<D> { /* private fields */ }
Expand description

Time series object: Consists in a vector of data indexed by time.

Implementations§

source§

impl<D: ComplexFloat + Float> TimeSeries<D>

source

pub fn white_noise(size: usize, fs: f64, mu: D, sigma: D) -> Self

Real signal generators:

Generates a white noise signal with a given size, sampling frequency and the noise amplitude

§Examples
use gw_signal::timeseries::*;
 
// creates a white noise signal with 20000 points, sampled at 1 kHz,
// the variance of the noise as 0.1 V
let mut signal: TimeSeries = TimeSeries::white_noise(20000, 1e3, 0f64, 1f64);
source§

impl<D: ComplexFloat> TimeSeries<D>

source

pub fn wave(size: usize, fs: f64, freq: D, ampl: D, phase: D) -> Self

Generates a sinusoidal signal.

§Examples
use gw_signal::timeseries::*;

// creates a sinusoidal signal with 20000 points, sampled at 1 kHz, using 8 bytes for each sample
// The frequency, amplitudes and phase at the origin are respectively:
//  5 Hz, 10 V and 0 rad.
let mut signal: TimeSeries = TimeSeries::wave(20000, 1e3, 5f64, 10f64, 0f64);
source

pub fn constant(size: usize, fs: f64, value: D) -> Self

Generates a constant signal.

§Examples
use gw_signal::timeseries::*;

// creates a constant signal with 20000 points, sampled at 1 kHz
let mut signal: TimeSeries = TimeSeries::constant(20000, 1e3, 1f64);
source

pub fn from_vector(fs: f64, t0: f64, input_data: Vec<D>) -> Self

Base onstructor, called by the other functions

source§

impl<D: ComplexFloat> TimeSeries<D>

Generates a modulated signal The amplitude, the frequency or the phase

source

pub fn modulated_signal( size: usize, fs: f64, carrier: f64, amplitude_mod: fn(_: f64) -> D, frequency_mod: fn(_: f64) -> f64, phase_mod: fn(_: f64) -> f64 ) -> TimeSeries<D>

Generates a sinusoidal waves that can be modulated in amplitude, in frequency or in phase

§Examples
use std::f64::consts::PI;
use gw_signal::timeseries::*;
 
// sampling frequency
let sampling: f64 = 1e3;

// defines a sinusoidal wave at 10 Hz, modulated in frequency
let mut signal: TimeSeries<f64> = TimeSeries::modulated_signal(
	200000, sampling,
	10., 												// carrier frequency
	|t: f64| 1f64, 										// amplitude modulation
	|t: f64| -> f64 {0.2 * (2. * PI * t * 0.05).cos()}, // frequency modulation
	|t: f64| 0f64 										// phase modulation
);
 
source§

impl<D: ComplexFloat<Real = F>, F> TimeSeries<D>

Getter functions

source

pub fn get_size(&self) -> usize

source

pub fn get_fs(&self) -> f64

source

pub fn get_t0(&self) -> f64

source

pub fn get_data(&self) -> Vec<D>

get data vector

source

pub fn get_subts(&self, start: usize, end: usize) -> TimeSeries<D>

extract a sub time series

source§

impl<D: ComplexFloat<Real = F>, F> TimeSeries<D>

Math functions

source

pub fn inv(&mut self) -> &mut TimeSeries<D>

compute the inverse value of the data

source

pub fn sqrt(&mut self) -> &mut TimeSeries<D>

compute square root of the data

source

pub fn real(&self) -> TimeSeries<F>

source

pub fn imag(&self) -> TimeSeries<F>

source

pub fn abs(&self) -> TimeSeries<F>

source

pub fn arg(&self) -> TimeSeries<F>

source

pub fn mean(&self) -> D

Compute mean value of the time series

source§

impl<D: Float> TimeSeries<D>

Math functions for real time series

source

pub fn max(&self) -> D

Get the maximum value of the time series

source

pub fn min(&self) -> D

Get the maximum value of the time series

source§

impl<D: ComplexFloat<Real = F>, F: Float> TimeSeries<D>

source

pub fn to_f32(&self) -> TimeSeries<f32>

source

pub fn to_f64(&self) -> TimeSeries<f64>

source

pub fn to_c32(&self) -> TimeSeries<Complex<f32>>

source

pub fn to_c64(&self) -> TimeSeries<Complex<f64>>

source§

impl<D> TimeSeries<D>

Spectral analysis methods

source

pub fn csd(&self, other: &TimeSeries<D>, window: &Window) -> FrequencySeries

Compute the cross spectal density between two signals, using the Welch’s method

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(20000, 1e3, 0f64, 1f64);
let mut signal_2: TimeSeries = signal_1.clone * 2.;

// compute the csd
let csd: FrequencySeries = signal_1.csd(&signal_2, &window);
 
source

pub fn psd(&self, window: &Window) -> FrequencySeries

Compute power spectral density using cross spectral density with itself

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);

// compute the csd
let psd: FrequencySeries = signal_1.psd(&window);
 
source

pub fn asd(&self, window: &Window) -> FrequencySeries

Compute the amplitude spectral density of a signal. Uses the psd function

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);

// compute the csd
let asd: FrequencySeries = signal_1.asd(&window);
 
source

pub fn coherence( &self, other: &TimeSeries<D>, window: &Window ) -> FrequencySeries

Compute the coherence between two signals. \gamma_{1,2}(f) = \frac{|csd_{1,2}(f)|}{psd_1(f) \cdot psd_2(f)}

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);
let mut signal_2: TimeSeries = signal_1.clone() * 2.;

// compute the csd
let coherence: FrequencySeries = signal_1.coherence(&signal_2, &window);
 
source

pub fn transfer_function( &self, other: &TimeSeries<D>, window: &Window ) -> FrequencySeries

Compute the transfer functions between two signals. \TF_{1,2}(f) = \frac{csd_{1,2}(f)}{psd_1(f)}

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);
let mut signal_2: TimeSeries = signal_1.clone() * 2.;

// compute the csd
let transfer_function: FrequencySeries = signal_1.transfer_function(&signal_2, &window);
 
source

pub fn time_csd( &self, other: &TimeSeries<D>, window: &Window, nb_fft: usize ) -> Spectrogram

Compute the cross spectal density between two signals, using the Welch’s method

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);
let mut signal_2: TimeSeries = signal_1.clone() * 2.;

// compute the csd
let csd: Spectrogram = signal_1.time_csd(&signal_2, &window, 10.);
 
source

pub fn time_psd(&self, window: &Window, nb_fft: usize) -> Spectrogram

Compute power spectral density using cross spectral density with itself

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);

// compute the csd
let psd: FrequencySeries = signal_1.time_psd(&window, 10);
 
source

pub fn time_asd(&self, window: &Window, nb_fft: usize) -> Spectrogram

Compute the amplitude spectral density of a signal. Uses the psd function

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);

// compute the csd
let asd: FrequencySeries = signal_1.time_asd(&window, 10);
 
source

pub fn time_cohe( &self, other: &TimeSeries<D>, window: &Window, nb_fft: usize ) -> Spectrogram

Compute the coherence between two signals. \gamma_{1,2}(f) = \frac{|csd_{1,2}(f)|}{psd_1(f) \cdot psd_2(f)}

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);
let mut signal_2: TimeSeries = signal_1.clone() * 2.;

// compute the csd
let coherence: FrequencySeries = signal_1.time_cohe(&signal_2, &window, 10);
 
source

pub fn time_tf( &self, other: &TimeSeries<D>, window: &Window, nb_fft: usize ) -> Spectrogram

Compute the transfer functions between two signals. \TF_{1,2}(f) = \frac{csd_{1,2}(f)}{psd_1(f)}

§Example
use gw_signal::{
	timeseries::*,
	frequencyseries::*,
	windows::*,
};

// creates two white noise signals
let window: Window = hann(1., 0.5, 1e3);
let mut signal_1: TimeSeries = TimeSeries::white_noise(2000000, 1e3, 0f64, 1f64);
let mut signal_2: TimeSeries = signal_1.clone() * 2.;

// compute the csd
let transfer_function: FrequencySeries = signal_1.time_tf(&signal_2, &window 10);
 
source§

impl<D> TimeSeries<D>

Implement signal filtering

source

pub fn apply_filter(&mut self, input_filter: &Filter)

The following method apply an IIR filter to a time series modify the original time series object.

§Example
use gw_signal::{
	timeseries::*,
	filter::*,
};

// creates two white noise signals
let fs: f64 = 1e3;
let mut signal_1: TimeSeries = TimeSeries::white_noise(20000, f64, 1.);
 
// generates an 8th butterworth lowpass filter at 10 Hz
let butter: Filter::butterworth(8, BType::LowType(10.), fs);
 
// apply the filter to the signal
let mut signal_2: TimeSeries = signal_1.apply_filter(butter);

Trait Implementations§

source§

impl<'a, D> Add<&TimeSeries<D>> for &'a mut TimeSeries<D>

Operator overloading:

notes:

The operators DOES NOT create a new time series, they modify one of the time series parameter.
§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the + operator.
source§

fn add(self, other: &TimeSeries<D>) -> &'a mut TimeSeries<D>

Performs the + operation. Read more
source§

impl<'a> Add<&'a mut TimeSeries<Complex<f32>>> for Complex<f32>

§

type Output = &'a mut TimeSeries<Complex<f32>>

The resulting type after applying the + operator.
source§

fn add( self, other: &'a mut TimeSeries<Complex<f32>> ) -> &'a mut TimeSeries<Complex<f32>>

Performs the + operation. Read more
source§

impl<'a> Add<&'a mut TimeSeries<Complex<f64>>> for Complex<f64>

§

type Output = &'a mut TimeSeries<Complex<f64>>

The resulting type after applying the + operator.
source§

fn add( self, other: &'a mut TimeSeries<Complex<f64>> ) -> &'a mut TimeSeries<Complex<f64>>

Performs the + operation. Read more
source§

impl<'a> Add<&'a mut TimeSeries<f32>> for f32

§

type Output = &'a mut TimeSeries<f32>

The resulting type after applying the + operator.
source§

fn add(self, other: &'a mut TimeSeries<f32>) -> &'a mut TimeSeries<f32>

Performs the + operation. Read more
source§

impl<'a> Add<&'a mut TimeSeries<f64>> for f64

§

type Output = &'a mut TimeSeries<f64>

The resulting type after applying the + operator.
source§

fn add(self, other: &'a mut TimeSeries<f64>) -> &'a mut TimeSeries<f64>

Performs the + operation. Read more
source§

impl<'a, D> Add<D> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the + operator.
source§

fn add(self, other: D) -> &'a mut TimeSeries<D>

Performs the + operation. Read more
source§

impl<D: Clone> Clone for TimeSeries<D>

source§

fn clone(&self) -> TimeSeries<D>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<D: Debug> Debug for TimeSeries<D>

source§

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

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

impl<'a, D> Div<&TimeSeries<D>> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the / operator.
source§

fn div(self, other: &TimeSeries<D>) -> &'a mut TimeSeries<D>

Performs the / operation. Read more
source§

impl<'a> Div<&'a mut TimeSeries<Complex<f32>>> for Complex<f32>

§

type Output = &'a mut TimeSeries<Complex<f32>>

The resulting type after applying the / operator.
source§

fn div( self, other: &'a mut TimeSeries<Complex<f32>> ) -> &'a mut TimeSeries<Complex<f32>>

Performs the / operation. Read more
source§

impl<'a> Div<&'a mut TimeSeries<Complex<f64>>> for Complex<f64>

§

type Output = &'a mut TimeSeries<Complex<f64>>

The resulting type after applying the / operator.
source§

fn div( self, other: &'a mut TimeSeries<Complex<f64>> ) -> &'a mut TimeSeries<Complex<f64>>

Performs the / operation. Read more
source§

impl<'a> Div<&'a mut TimeSeries<f32>> for f32

§

type Output = &'a mut TimeSeries<f32>

The resulting type after applying the / operator.
source§

fn div(self, other: &'a mut TimeSeries<f32>) -> &'a mut TimeSeries<f32>

Performs the / operation. Read more
source§

impl<'a> Div<&'a mut TimeSeries<f64>> for f64

§

type Output = &'a mut TimeSeries<f64>

The resulting type after applying the / operator.
source§

fn div(self, other: &'a mut TimeSeries<f64>) -> &'a mut TimeSeries<f64>

Performs the / operation. Read more
source§

impl<'a, D> Div<D> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the / operator.
source§

fn div(self, other: D) -> &'a mut TimeSeries<D>

Performs the / operation. Read more
source§

impl<D: ComplexFloat> Index<usize> for TimeSeries<D>

§

type Output = D

The returned type after indexing.
source§

fn index(&self, i: usize) -> &D

Performs the indexing (container[index]) operation. Read more
source§

impl<D: ComplexFloat> IndexMut<usize> for TimeSeries<D>

source§

fn index_mut(&mut self, i: usize) -> &mut D

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a, D> Mul<&TimeSeries<D>> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the * operator.
source§

fn mul(self, other: &TimeSeries<D>) -> &'a mut TimeSeries<D>

Performs the * operation. Read more
source§

impl<'a> Mul<&'a mut TimeSeries<Complex<f32>>> for Complex<f32>

§

type Output = &'a mut TimeSeries<Complex<f32>>

The resulting type after applying the * operator.
source§

fn mul( self, other: &'a mut TimeSeries<Complex<f32>> ) -> &'a mut TimeSeries<Complex<f32>>

Performs the * operation. Read more
source§

impl<'a> Mul<&'a mut TimeSeries<Complex<f64>>> for Complex<f64>

§

type Output = &'a mut TimeSeries<Complex<f64>>

The resulting type after applying the * operator.
source§

fn mul( self, other: &'a mut TimeSeries<Complex<f64>> ) -> &'a mut TimeSeries<Complex<f64>>

Performs the * operation. Read more
source§

impl<'a> Mul<&'a mut TimeSeries<f32>> for f32

§

type Output = &'a mut TimeSeries<f32>

The resulting type after applying the * operator.
source§

fn mul(self, other: &'a mut TimeSeries<f32>) -> &'a mut TimeSeries<f32>

Performs the * operation. Read more
source§

impl<'a> Mul<&'a mut TimeSeries<f64>> for f64

§

type Output = &'a mut TimeSeries<f64>

The resulting type after applying the * operator.
source§

fn mul(self, other: &'a mut TimeSeries<f64>) -> &'a mut TimeSeries<f64>

Performs the * operation. Read more
source§

impl<'a, D> Mul<D> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the * operator.
source§

fn mul(self, other: D) -> &'a mut TimeSeries<D>

Performs the * operation. Read more
source§

impl<'a, D> Neg for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the - operator.
source§

fn neg(self) -> &'a mut TimeSeries<D>

Performs the unary - operation. Read more
source§

impl<D: ComplexFloat + ToString + FromStr + Display> SeriesIO for TimeSeries<D>

source§

fn print(&self, n1: usize, n2: usize)

Example Read more
source§

fn write_csv(&self, file_name: &str)

Example Read more
source§

fn read_csv(file_name: &str) -> Self

Example Read more
source§

impl<'a, D> Sub<&TimeSeries<D>> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the - operator.
source§

fn sub(self, other: &TimeSeries<D>) -> &'a mut TimeSeries<D>

Performs the - operation. Read more
source§

impl<'a> Sub<&'a mut TimeSeries<Complex<f32>>> for Complex<f32>

§

type Output = &'a mut TimeSeries<Complex<f32>>

The resulting type after applying the - operator.
source§

fn sub( self, other: &'a mut TimeSeries<Complex<f32>> ) -> &'a mut TimeSeries<Complex<f32>>

Performs the - operation. Read more
source§

impl<'a> Sub<&'a mut TimeSeries<Complex<f64>>> for Complex<f64>

§

type Output = &'a mut TimeSeries<Complex<f64>>

The resulting type after applying the - operator.
source§

fn sub( self, other: &'a mut TimeSeries<Complex<f64>> ) -> &'a mut TimeSeries<Complex<f64>>

Performs the - operation. Read more
source§

impl<'a> Sub<&'a mut TimeSeries<f32>> for f32

§

type Output = &'a mut TimeSeries<f32>

The resulting type after applying the - operator.
source§

fn sub(self, other: &'a mut TimeSeries<f32>) -> &'a mut TimeSeries<f32>

Performs the - operation. Read more
source§

impl<'a> Sub<&'a mut TimeSeries<f64>> for f64

§

type Output = &'a mut TimeSeries<f64>

The resulting type after applying the - operator.
source§

fn sub(self, other: &'a mut TimeSeries<f64>) -> &'a mut TimeSeries<f64>

Performs the - operation. Read more
source§

impl<'a, D> Sub<D> for &'a mut TimeSeries<D>

§

type Output = &'a mut TimeSeries<D>

The resulting type after applying the - operator.
source§

fn sub(self, other: D) -> &'a mut TimeSeries<D>

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<D> Freeze for TimeSeries<D>

§

impl<D> RefUnwindSafe for TimeSeries<D>
where D: RefUnwindSafe,

§

impl<D> Send for TimeSeries<D>
where D: Send,

§

impl<D> Sync for TimeSeries<D>
where D: Sync,

§

impl<D> Unpin for TimeSeries<D>
where D: Unpin,

§

impl<D> UnwindSafe for TimeSeries<D>
where D: UnwindSafe,

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V