#[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 Complex<Q32<31>>
impl Complex<Q32<31>>
Sourcepub fn from_angle(angle: Wrapping<i32>) -> Self
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/2Source§impl Complex<i32>
impl Complex<i32>
Sourcepub fn norm_sqr(&self) -> P32<31>
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)
);Sourcepub fn log2(&self) -> i32
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);Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Complex<T>where
T: Deserialize<'de>,
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>,
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: 'static + Copy + Mul<Output = A>, A: Add<Output = A> + Sub<Output = A> + AsPrimitive<T>> Mul for Complex<T>
impl<T: 'static + Copy + Mul<Output = A>, A: Add<Output = A> + Sub<Output = A> + AsPrimitive<T>> Mul for Complex<T>
Source§impl<T: Ord> Ord for Complex<T>
impl<T: Ord> Ord for Complex<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Complex<T>
impl<T: PartialOrd> PartialOrd for Complex<T>
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
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§impl<C: SplitProcess<i32, i32, S>, S> SplitProcess<(i32, Wrapping<i32>), Complex<i32>, [S; 2]> for Lockin<C>
Sample and phase
impl<C: SplitProcess<i32, i32, S>, S> SplitProcess<(i32, Wrapping<i32>), Complex<i32>, [S; 2]> for Lockin<C>
Sample and phase
impl<T: Copy> Copy for Complex<T>
impl<T: Eq> Eq for Complex<T>
impl<T> Pod for Complex<T>where
T: Pod,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.