Complex

Struct Complex 

Source
#[repr(transparent)]
pub struct Complex<T>(pub [T; 2]);
Expand description

A complex number in cartesian coordinates

Tuple Fields§

§0: [T; 2]

Real and imaginary parts

Implementations§

Source§

impl<T: Copy> Complex<T>

Source

pub const fn new(re: T, im: T) -> Self

Create a new Complex<T>

Source

pub fn re(&self) -> T

The real part

Source

pub fn im(&self) -> T

The imaginary part

Source§

impl<T: Copy + Neg<Output = T>> Complex<T>

Source

pub fn conj(self) -> Self

Conjugate

Source§

impl Complex<Q32<31>>

Source

pub fn from_angle(angle: Wrapping<i32>) -> Self

Return a Complex on the unit circle given an angle.

Example:

use core::num::Wrapping as W;
use idsp::Complex;
Complex::<_>::from_angle(W(0));
Complex::<_>::from_angle(W(1 << 30)); // pi/2
Complex::<_>::from_angle(W(-1 << 30)); // -pi/2
Source§

impl Complex<i32>

Source

pub fn norm_sqr(&self) -> P32<31>

Return the absolute square (the squared magnitude).

Note(panic): This will panic for Complex(i32::MIN, i32::MIN)

Example:

use dsp_fixedpoint::{P32, Q32};
use idsp::Complex;
assert_eq!(Complex::new(i32::MIN, 0).norm_sqr(), P32::new(1 << 31));
assert_eq!(
    Complex::new(i32::MAX, i32::MAX).norm_sqr(),
    P32::new(u32::MAX - 3)
);
assert_eq!(
    Complex::new(i32::MIN, i32::MAX).norm_sqr(),
    P32::new(u32::MAX - 1)
);
Source

pub fn log2(&self) -> i32

trunc(log2(power)) re full scale (approximation)

TODO: scale up, interpolate

Example:

use idsp::Complex;
assert_eq!(Complex::new(i32::MIN, i32::MIN).log2(), 0);
assert_eq!(Complex::new(i32::MAX, i32::MAX).log2(), -1);
assert_eq!(Complex::new(i32::MIN, 0).log2(), -1);
assert_eq!(Complex::new(i32::MAX, 0).log2(), -2);
assert_eq!(Complex::new(-1, 0).log2(), -63);
assert_eq!(Complex::new(1, 0).log2(), -63);
assert_eq!(Complex::new(0, 0).log2(), -64);
Source

pub fn arg(&self) -> Wrapping<i32>

Return the angle.

Note: Normalization is 1 << 31 == pi.

Example:

use core::num::Wrapping as W;
use idsp::Complex;
assert_eq!(Complex::new(0, 0).arg(), W(0));
assert_eq!(Complex::new(0, 1).arg(), W((1 << 30) - 1));

Trait Implementations§

Source§

impl<T: Copy + Add<Output = T>> Add for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<T: Copy + BitAnd<Output = T>> BitAnd<T> for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: T) -> Self

Performs the & operation. Read more
Source§

impl<T: Copy + BitAnd<Output = T>> BitAnd for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self

Performs the & operation. Read more
Source§

impl<T: Copy + BitOr<Output = T>> BitOr<T> for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: T) -> Self

Performs the | operation. Read more
Source§

impl<T: Copy + BitOr<Output = T>> BitOr for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl<T: Copy + BitXor<Output = T>> BitXor<T> for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: T) -> Self

Performs the ^ operation. Read more
Source§

impl<T: Copy + BitXor<Output = T>> BitXor for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self

Performs the ^ operation. Read more
Source§

impl<T: Clone> Clone for Complex<T>

Source§

fn clone(&self) -> Complex<T>

Returns a duplicate 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<T: Debug> Debug for Complex<T>

Source§

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

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

impl<T: Default> Default for Complex<T>

Source§

fn default() -> Complex<T>

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Deserialize<'de> for Complex<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Copy + Div<Output = T>> Div<T> for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self

Performs the / operation. Read more
Source§

impl<T: Copy + Mul<Output = T>> Mul<T> for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self

Performs the * operation. Read more
Source§

impl<T: 'static + Copy + Mul<Output = A>, A: Add<Output = A> + Sub<Output = A> + AsPrimitive<T>> Mul for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl<T: Copy + Neg<Output = T>> Neg for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T: Copy + Not<Output = T>> Not for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl<T: Ord> Ord for Complex<T>

Source§

fn cmp(&self, other: &Complex<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Complex<T>

Source§

fn eq(&self, other: &Complex<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Complex<T>

Source§

fn partial_cmp(&self, other: &Complex<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Product for Complex<T>
where Self: Default + Mul<Output = Self>,

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<T: Copy + Rem<Output = T>> Rem<T> for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: T) -> Self

Performs the % operation. Read more
Source§

impl<T> Serialize for Complex<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<C: SplitProcess<i32, i32, S>, S> SplitProcess<(i32, Complex<Q<i32, i64, 31>>), Complex<i32>, [S; 2]> for Lockin<C>

Input and LO

Source§

fn process( &self, state: &mut [S; 2], x: (i32, Complex<Q32<31>>), ) -> Complex<i32>

Update the lockin with a sample taken at a local oscillator IQ value.

Source§

fn block(&self, state: &mut S, x: &[X], y: &mut [Y])

Process a block of inputs Read more
Source§

impl<C: SplitProcess<i32, i32, S>, S> SplitProcess<(i32, Wrapping<i32>), Complex<i32>, [S; 2]> for Lockin<C>

Sample and phase

Source§

fn process(&self, state: &mut [S; 2], x: (i32, Wrapping<i32>)) -> Complex<i32>

Update the lockin with a sample taken at a given phase.

Source§

fn block(&self, state: &mut S, x: &[X], y: &mut [Y])

Process a block of inputs Read more
Source§

impl<T: Copy + Sub<Output = T>> Sub for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<T> Sum for Complex<T>
where Self: Default + Add<Output = Self>,

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T> Zeroable for Complex<T>
where T: Zeroable,

Source§

fn zeroed() -> Self

Source§

impl<T: Copy> Copy for Complex<T>

Source§

impl<T: Eq> Eq for Complex<T>

Source§

impl<T> Pod for Complex<T>
where T: Pod,

Source§

impl<T> StructuralPartialEq for Complex<T>

Auto Trait Implementations§

§

impl<T> Freeze for Complex<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Complex<T>
where T: RefUnwindSafe,

§

impl<T> Send for Complex<T>
where T: Send,

§

impl<T> Sync for Complex<T>
where T: Sync,

§

impl<T> Unpin for Complex<T>
where T: Unpin,

§

impl<T> UnwindSafe for Complex<T>
where T: 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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> NoUninit for T
where T: Pod,