Trait basic_dsp::ComplexOps

source ·
pub trait ComplexOps<T>
where T: RealNumber,
{ // Required methods fn multiply_complex_exponential(&mut self, a: T, b: T); fn conj(&mut self); }
Expand description

Operations on complex types.

§Failures

If one of the methods is called on real data then self.len() will be set to 0. To avoid this it’s recommended to use the to_real_time_vec, to_real_freq_vec to_complex_time_vec and to_complex_freq_vec constructor methods since the resulting types will already check at compile time (using the type system) that the data is complex.

Required Methods§

source

fn multiply_complex_exponential(&mut self, a: T, b: T)

Multiplies each vector element with exp(j*(a*idx*self.delta() + b)) where a and b are arguments and idx is the index of the data points in the vector ranging from 0 to self.points() - 1. j is the imaginary number and exp the exponential function.

This method can be used to perform a frequency shift in time domain.

§Example
use basic_dsp_vector::*;
let mut vector = vec!(Complex::new(1.0, 2.0), Complex::new(3.0, 4.0)).to_complex_time_vec();
vector.multiply_complex_exponential(2.0, 3.0);
let actual = &vector[..];
let expected = &[Complex::new(-1.2722325, -1.838865), Complex::new(4.6866837, -1.7421241)];
assert_eq!(actual.len(), expected.len());
for i in 0..actual.len() {
       assert!((actual[i] - expected[i]).norm() < 1e-4);
}
source

fn conj(&mut self)

Calculates the complex conjugate of the vector.

§Example
use basic_dsp_vector::*;
let mut vector = vec!(Complex::new(1.0, 2.0), Complex::new(3.0, 4.0)).to_complex_time_vec();
vector.conj();
assert_eq!([Complex::new(1.0, -2.0), Complex::new(3.0, -4.0)], vector[..]);

Implementors§

source§

impl<S, T, N, D> ComplexOps<T> for DspVec<S, T, N, D>

source§

impl<V, S, T> ComplexOps<T> for Matrix2xN<V, S, T>
where V: Vector<T> + ComplexOps<T>, S: ToSlice<T>, T: RealNumber,

source§

impl<V, S, T> ComplexOps<T> for Matrix3xN<V, S, T>
where V: Vector<T> + ComplexOps<T>, S: ToSlice<T>, T: RealNumber,

source§

impl<V, S, T> ComplexOps<T> for Matrix4xN<V, S, T>
where V: Vector<T> + ComplexOps<T>, S: ToSlice<T>, T: RealNumber,

source§

impl<V, S, T> ComplexOps<T> for MatrixMxN<V, S, T>
where V: Vector<T> + ComplexOps<T>, S: ToSlice<T>, T: RealNumber,