Trait basic_dsp_vector::ComplexToRealGetterOps

source ·
pub trait ComplexToRealGetterOps<A, T, N, D>
where T: RealNumber, N: NumberSpace, D: Domain, A: GetMetaData<T, N, D>,
{ // Required methods fn get_real(&self, destination: &mut A); fn get_imag(&self, destination: &mut A); fn get_magnitude(&self, destination: &mut A); fn get_magnitude_squared(&self, destination: &mut A); fn get_phase(&self, destination: &mut A); fn get_real_imag(&self, real: &mut A, imag: &mut A); fn get_mag_phase(&self, mag: &mut A, phase: &mut A); }
Expand description

Defines getters to get real data from complex types.

§Failures

All operations in this trait set the arguments len() to 0 if the type isn’t in the complex number space.

Required Methods§

source

fn get_real(&self, destination: &mut A)

Copies all real elements into the given vector.

§Example
use basic_dsp_vector::*;
let vector = vec!(Complex::new(1.0, 2.0), Complex::new(3.0, 4.0)).to_complex_time_vec();
let mut target = Vec::new().to_real_time_vec();
vector.get_real(&mut target);
assert_eq!([1.0, 3.0], target[..]);
source

fn get_imag(&self, destination: &mut A)

Copies all imag elements into the given vector.

§Example
use basic_dsp_vector::*;
let vector = vec!(Complex::new(1.0, 2.0), Complex::new(3.0, 4.0)).to_complex_time_vec();
let mut target = Vec::new().to_real_time_vec();
vector.get_imag(&mut target);
assert_eq!([2.0, 4.0], target[..]);
source

fn get_magnitude(&self, destination: &mut A)

Copies the absolute value or magnitude of all vector elements into the given target vector.

§Example
use basic_dsp_vector::*;
let vector = vec!(Complex::new(3.0, -4.0), Complex::new(-3.0, 4.0)).to_complex_time_vec();
let mut target = Vec::new().to_real_time_vec();
vector.get_magnitude(&mut target);
assert_eq!([5.0, 5.0], target[..]);
source

fn get_magnitude_squared(&self, destination: &mut A)

Copies the absolute value squared or magnitude squared of all vector elements into the given target vector.

§Example

Copies the absolute value or magnitude of all vector elements into the given target vector.

§Example
use basic_dsp_vector::*;
let vector = vec!(Complex::new(3.0, -4.0), Complex::new(-3.0, 4.0)).to_complex_time_vec();
let mut target = Vec::new().to_real_time_vec();
vector.get_magnitude_squared(&mut target);
assert_eq!([25.0, 25.0], target[..]);
source

fn get_phase(&self, destination: &mut A)

Copies the phase of all elements in [rad] into the given vector.

§Example
use basic_dsp_vector::*;
let vector =
    vec!(Complex::new(1.0, 0.0), Complex::new(0.0, 4.0), Complex::new(-2.0, 0.0), Complex::new(0.0, -3.0), Complex::new(1.0, 1.0)).to_complex_time_vec();
let mut target = Vec::new().to_real_time_vec();
vector.get_phase(&mut target);
let actual = &target[..];
let expected = &[0.0, 1.5707964, 3.1415927, -1.5707964, 0.7853982];
assert_eq!(actual.len(), expected.len());
for i in 0..actual.len() {
       assert!(f64::abs(actual[i] - expected[i]) < 1e-4);
}
source

fn get_real_imag(&self, real: &mut A, imag: &mut A)

Gets the real and imaginary parts and stores them in the given vectors. See also get_phase and get_complex_abs for further information.

source

fn get_mag_phase(&self, mag: &mut A, phase: &mut A)

Gets the magnitude and phase and stores them in the given vectors. See also get_real and get_imag for further information.

Implementors§

source§

impl<S, T, N, NR, D, O, DO> ComplexToRealGetterOps<O, T, NR, DO> for DspVec<S, T, N, D>
where DspVec<S, T, N, D>: ToRealResult, O: Vector<T> + GetMetaData<T, NR, DO> + FloatIndex<Range<usize>, Output = [T]> + FloatIndexMut<Range<usize>>, S: ToSlice<T>, T: RealNumber, N: ComplexNumberSpace, NR: RealNumberSpace, D: Domain, DO: PosEq<D> + Domain,