Trait basic_dsp::RealVectorOperations
[−]
[src]
pub trait RealVectorOperations<T>: DataVector<T> where T: RealNumber { type ComplexPartner; fn real_offset(self, offset: T) -> VecResult<Self>; fn real_scale(self, offset: T) -> VecResult<Self>; fn abs(self) -> VecResult<Self>; fn to_complex(self) -> VecResult<Self::ComplexPartner>; fn wrap(self, divisor: T) -> VecResult<Self>; fn unwrap(self, divisor: T) -> VecResult<Self>; fn real_dot_product(&self, factor: &Self) -> ScalarResult<T>; fn real_statistics(&self) -> Statistics<T>; fn real_statistics_splitted(&self, len: usize) -> Vec<Statistics<T>>; }
Defines all operations which are valid on DataVectors
containing real data.
Failures
All operations in this trait fail with VectorMustBeReal
if the vector isn't in the real number space.
Associated Types
type ComplexPartner
Required Methods
fn real_offset(self, offset: T) -> VecResult<Self>
Adds a scalar to the vector.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; let vector = RealTimeVector32::from_array(&[1.0, 2.0]); let result = vector.real_offset(2.0).expect("Ignoring error handling in examples"); assert_eq!([3.0, 4.0], result.data());
fn real_scale(self, offset: T) -> VecResult<Self>
Multiplies the vector with a scalar.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; let vector = RealTimeVector32::from_array(&[1.0, 2.0]); let result = vector.real_scale(4.0).expect("Ignoring error handling in examples"); assert_eq!([4.0, 8.0], result.data());
fn abs(self) -> VecResult<Self>
Gets the absolute value of all vector elements.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; let vector = RealTimeVector32::from_array(&[1.0, -2.0]); let result = vector.abs().expect("Ignoring error handling in examples"); assert_eq!([1.0, 2.0], result.data());
fn to_complex(self) -> VecResult<Self::ComplexPartner>
Converts the real vector into a complex vector.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; let vector = RealTimeVector32::from_array(&[1.0, 2.0]); let result = vector.to_complex().expect("Ignoring error handling in examples"); assert_eq!([1.0, 0.0, 2.0, 0.0], result.data());
fn wrap(self, divisor: T) -> VecResult<Self>
Each value in the vector is devided by the divisor and the remainder is stored in the resulting vector. This the same a modulo operation or to phase wrapping.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]); let result = vector.wrap(4.0).expect("Ignoring error handling in examples"); assert_eq!([1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0], result.data());
fn unwrap(self, divisor: T) -> VecResult<Self>
This function corrects the jumps in the given vector which occur due to wrap or modulo operations. This will undo a wrap operation only if the deltas are smaller than half the divisor.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations, DataVector}; let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0]); let result = vector.unwrap(4.0).expect("Ignoring error handling in examples"); assert_eq!([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], result.data());
fn real_dot_product(&self, factor: &Self) -> ScalarResult<T>
Calculates the dot product of self and factor. Self and factor remain unchanged.
Failures
VecResult may report the following ErrorReason
members:
VectorMetaDataMustAgree
:self
andfactor
must be in the same domain and number space
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations}; let vector1 = RealTimeVector32::from_array(&[9.0, 2.0, 7.0]); let vector2 = RealTimeVector32::from_array(&[4.0, 8.0, 10.0]); let result = vector1.real_dot_product(&vector2).expect("Ignoring error handling in examples"); assert_eq!(122.0, result);
fn real_statistics(&self) -> Statistics<T>
Calculates the statistics of the data contained in the vector.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations}; let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0, 5.0]); let result = vector.real_statistics(); assert_eq!(result.sum, 15.0); assert_eq!(result.count, 5); assert_eq!(result.average, 3.0); assert!((result.rms - 3.3166).abs() < 1e-4); assert_eq!(result.min, 1.0); assert_eq!(result.min_index, 0); assert_eq!(result.max, 5.0); assert_eq!(result.max_index, 4);
fn real_statistics_splitted(&self, len: usize) -> Vec<Statistics<T>>
Calculates the statistics of the data contained in the vector as if the vector would
have been split into len
pieces. self.len
should be devisable by len
without a remainder,
but this isn't enforced by the implementation.
Example
use basic_dsp::{RealTimeVector32, RealVectorOperations}; let vector = RealTimeVector32::from_array(&[1.0, 2.0, 3.0, 4.0]); let result = vector.real_statistics_splitted(2); assert_eq!(result[0].sum, 4.0); assert_eq!(result[1].sum, 6.0);
Implementors
impl RealVectorOperations<f32> for GenericDataVector<f32>
impl RealVectorOperations<f64> for GenericDataVector<f64>
impl RealVectorOperations<f32> for RealTimeVector<f32>
impl RealVectorOperations<f64> for RealTimeVector<f64>
impl RealVectorOperations<f32> for RealFreqVector<f32>
impl RealVectorOperations<f64> for RealFreqVector<f64>