The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
Complex arithmetics in the openMHA
Collaboration diagram for Complex arithmetics in the openMHA:

Classes

struct  mha_complex_t
 Type for complex floating point values. More...
 

Functions

mha_complex_tset (mha_complex_t &self, mha_real_t real, mha_real_t imag=0)
 Assign real and imaginary parts to a mha_complex_t variable. More...
 
mha_complex_t mha_complex (mha_real_t real, mha_real_t imag=0)
 Create a new mha_complex_t with specified real and imaginary parts. More...
 
mha_complex_tset (mha_complex_t &self, const std::complex< mha_real_t > &stdcomplex)
 Assign a mha_complex_t variable from a std::complex. More...
 
std::complex< mha_real_tstdcomplex (const mha_complex_t &self)
 Create a std::complex from mha_complex_t. More...
 
mha_complex_texpi (mha_complex_t &self, mha_real_t angle)
 replaces the value of the given mha_complex_t with exp(i*b). More...
 
double angle (const mha_complex_t &self)
 Computes the angle of a complex number in the complex plane. More...
 
mha_complex_toperator+= (mha_complex_t &self, const mha_complex_t &other)
 Addition of two complex numbers, overwriting the first. More...
 
mha_complex_t operator+ (const mha_complex_t &self, const mha_complex_t &other)
 Addition of two complex numbers, result is a temporary object. More...
 
mha_complex_toperator+= (mha_complex_t &self, mha_real_t other_real)
 Addition of a complex and a real number, overwriting the complex. More...
 
mha_complex_t operator+ (const mha_complex_t &self, mha_real_t other_real)
 Addition of a complex and a real number, result is a temporary object. More...
 
mha_complex_toperator-= (mha_complex_t &self, const mha_complex_t &other)
 Subtraction of two complex numbers, overwriting the first. More...
 
mha_complex_t operator- (const mha_complex_t &self, const mha_complex_t &other)
 Subtraction of two complex numbers, result is a temporary object. More...
 
mha_complex_toperator-= (mha_complex_t &self, mha_real_t other_real)
 Subtraction of a complex and a real number, overwriting the complex. More...
 
mha_complex_t operator- (const mha_complex_t &self, mha_real_t other_real)
 Subtraction of a complex and a real number, result is a temporary object. More...
 
mha_complex_toperator*= (mha_complex_t &self, const mha_complex_t &other)
 Multiplication of two complex numbers, overwriting the first. More...
 
mha_complex_t operator* (const mha_complex_t &self, const mha_complex_t &other)
 Multiplication of two complex numbers, result is a temporary object. More...
 
mha_complex_toperator*= (mha_complex_t &self, mha_real_t other_real)
 Multiplication of a complex and a real number, overwriting the complex. More...
 
mha_complex_texpi (mha_complex_t &self, mha_real_t angle, mha_real_t factor)
 replaces (!) the value of the given mha_complex_t with a * exp(i*b) More...
 
mha_complex_t operator* (const mha_complex_t &self, mha_real_t other_real)
 Multiplication of a complex and a real number, result is a temporary object. More...
 
mha_real_t abs2 (const mha_complex_t &self)
 Compute the square of the absolute value of a complex value. More...
 
mha_real_t abs (const mha_complex_t &self)
 Compute the absolute value of a complex value. More...
 
mha_complex_toperator/= (mha_complex_t &self, mha_real_t other_real)
 Division of a complex and a real number, overwriting the complex. More...
 
mha_complex_t operator/ (const mha_complex_t &self, mha_real_t other_real)
 Division of a complex and a real number, result is a temporary object. More...
 
mha_complex_tsafe_div (mha_complex_t &self, const mha_complex_t &other, mha_real_t eps, mha_real_t eps2)
 
mha_complex_toperator/= (mha_complex_t &self, const mha_complex_t &other)
 Division of two complex numbers, overwriting the first. More...
 
mha_complex_t operator/ (const mha_complex_t &self, const mha_complex_t &other)
 Division of two complex numbers, result is a temporary object. More...
 
mha_complex_t operator- (const mha_complex_t &self)
 Unary minus on a complex results in a negative temporary object. More...
 
bool operator== (const mha_complex_t &x, const mha_complex_t &y)
 Compare two complex numbers for equality. More...
 
bool operator!= (const mha_complex_t &x, const mha_complex_t &y)
 Compare two complex numbers for inequality. More...
 
void conjugate (mha_complex_t &self)
 Replace (!) the value of this mha_complex_t with its conjugate. More...
 
mha_complex_t _conjugate (const mha_complex_t &self)
 Compute the cojugate of this complex value. More...
 
void reciprocal (mha_complex_t &self)
 Replace the value of this complex with its reciprocal. More...
 
mha_complex_t _reciprocal (const mha_complex_t &self)
 compute the reciprocal of this complex value. More...
 
void normalize (mha_complex_t &self)
 Divide a complex by its absolute value, thereby normalizing it (projecting onto the unit circle). More...
 
void normalize (mha_complex_t &self, mha_real_t margin)
 Divide a complex by its absolute value, thereby normalizing it (projecting onto the unit circle), with a safety margin. More...
 
bool almost (const mha_complex_t &self, const mha_complex_t &other, mha_real_t times_epsilon=1e2)
 Compare two complex numbers for equality except for a small relative error. More...
 
bool operator< (const mha_complex_t &x, const mha_complex_t &y)
 Compares the absolute values of two complex numbers. More...
 

Detailed Description

Function Documentation

◆ set() [1/2]

mha_complex_t& set ( mha_complex_t self,
mha_real_t  real,
mha_real_t  imag = 0 
)
inline

Assign real and imaginary parts to a mha_complex_t variable.

Parameters
selfThe mha_complex_t variable whose value is about to change.
realThe new real part.
imagThe new imaginary part.
Returns
A reference to the changed variable.

◆ mha_complex()

mha_complex_t mha_complex ( mha_real_t  real,
mha_real_t  imag = 0 
)
inline

Create a new mha_complex_t with specified real and imaginary parts.

Parameters
realThe real part.
imagThe imaginary part.
Returns
The new value.

◆ set() [2/2]

mha_complex_t& set ( mha_complex_t self,
const std::complex< mha_real_t > &  stdcomplex 
)
inline

Assign a mha_complex_t variable from a std::complex.

Parameters
selfThe mha_complex_t variable whose value is about to change.
stdcomplexThe new complex value.
Returns
A reference to the changed variable.

◆ stdcomplex()

std::complex<mha_real_t> stdcomplex ( const mha_complex_t self)
inline

Create a std::complex from mha_complex_t.

◆ expi() [1/2]

mha_complex_t& expi ( mha_complex_t self,
mha_real_t  angle 
)
inline

replaces the value of the given mha_complex_t with exp(i*b).

Parameters
selfThe mha_complex_t variable whose value is about to change.
angleThe angle in the complex plane [rad].
Returns
A reference to the changed variable.

◆ angle()

double angle ( const mha_complex_t self)
inline

Computes the angle of a complex number in the complex plane.

Parameters
selfThe complex number whose angle is needed.
Returns
The angle of a complex number in the complex plane.

◆ operator+=() [1/2]

mha_complex_t& operator+= ( mha_complex_t self,
const mha_complex_t other 
)
inline

Addition of two complex numbers, overwriting the first.

◆ operator+() [1/2]

mha_complex_t operator+ ( const mha_complex_t self,
const mha_complex_t other 
)
inline

Addition of two complex numbers, result is a temporary object.

◆ operator+=() [2/2]

mha_complex_t& operator+= ( mha_complex_t self,
mha_real_t  other_real 
)
inline

Addition of a complex and a real number, overwriting the complex.

◆ operator+() [2/2]

mha_complex_t operator+ ( const mha_complex_t self,
mha_real_t  other_real 
)
inline

Addition of a complex and a real number, result is a temporary object.

◆ operator-=() [1/2]

mha_complex_t& operator-= ( mha_complex_t self,
const mha_complex_t other 
)
inline

Subtraction of two complex numbers, overwriting the first.

◆ operator-() [1/3]

mha_complex_t operator- ( const mha_complex_t self,
const mha_complex_t other 
)
inline

Subtraction of two complex numbers, result is a temporary object.

◆ operator-=() [2/2]

mha_complex_t& operator-= ( mha_complex_t self,
mha_real_t  other_real 
)
inline

Subtraction of a complex and a real number, overwriting the complex.

◆ operator-() [2/3]

mha_complex_t operator- ( const mha_complex_t self,
mha_real_t  other_real 
)
inline

Subtraction of a complex and a real number, result is a temporary object.

◆ operator*=() [1/2]

mha_complex_t& operator*= ( mha_complex_t self,
const mha_complex_t other 
)
inline

Multiplication of two complex numbers, overwriting the first.

◆ operator*() [1/2]

mha_complex_t operator* ( const mha_complex_t self,
const mha_complex_t other 
)
inline

Multiplication of two complex numbers, result is a temporary object.

◆ operator*=() [2/2]

mha_complex_t& operator*= ( mha_complex_t self,
mha_real_t  other_real 
)
inline

Multiplication of a complex and a real number, overwriting the complex.

◆ expi() [2/2]

mha_complex_t& expi ( mha_complex_t self,
mha_real_t  angle,
mha_real_t  factor 
)
inline

replaces (!) the value of the given mha_complex_t with a * exp(i*b)

Parameters
selfThe mha_complex_t variable whose value is about to change.
angleThe imaginary exponent.
factorThe absolute value of the result.
Returns
A reference to the changed variable.

◆ operator*() [2/2]

mha_complex_t operator* ( const mha_complex_t self,
mha_real_t  other_real 
)
inline

Multiplication of a complex and a real number, result is a temporary object.

◆ abs2()

mha_real_t abs2 ( const mha_complex_t self)
inline

Compute the square of the absolute value of a complex value.

Returns
The square of the absolute value of self.

◆ abs()

mha_real_t abs ( const mha_complex_t self)
inline

Compute the absolute value of a complex value.

Returns
The absolute value of self.

◆ operator/=() [1/2]

mha_complex_t& operator/= ( mha_complex_t self,
mha_real_t  other_real 
)
inline

Division of a complex and a real number, overwriting the complex.

◆ operator/() [1/2]

mha_complex_t operator/ ( const mha_complex_t self,
mha_real_t  other_real 
)
inline

Division of a complex and a real number, result is a temporary object.

◆ safe_div()

mha_complex_t& safe_div ( mha_complex_t self,
const mha_complex_t other,
mha_real_t  eps,
mha_real_t  eps2 
)
inline

Safe division of two complex numbers, overwriting the first. If abs(divisor) < eps, then divisor is replaced by eps. eps2 = eps*eps.

◆ operator/=() [2/2]

mha_complex_t& operator/= ( mha_complex_t self,
const mha_complex_t other 
)
inline

Division of two complex numbers, overwriting the first.

◆ operator/() [2/2]

mha_complex_t operator/ ( const mha_complex_t self,
const mha_complex_t other 
)
inline

Division of two complex numbers, result is a temporary object.

◆ operator-() [3/3]

mha_complex_t operator- ( const mha_complex_t self)
inline

Unary minus on a complex results in a negative temporary object.

◆ operator==()

bool operator== ( const mha_complex_t x,
const mha_complex_t y 
)
inline

Compare two complex numbers for equality.

◆ operator!=()

bool operator!= ( const mha_complex_t x,
const mha_complex_t y 
)
inline

Compare two complex numbers for inequality.

◆ conjugate()

void conjugate ( mha_complex_t self)
inline

Replace (!) the value of this mha_complex_t with its conjugate.

◆ _conjugate()

mha_complex_t _conjugate ( const mha_complex_t self)
inline

Compute the cojugate of this complex value.

Returns
A temporary object holding the conjugate value.

◆ reciprocal()

void reciprocal ( mha_complex_t self)
inline

Replace the value of this complex with its reciprocal.

◆ _reciprocal()

mha_complex_t _reciprocal ( const mha_complex_t self)
inline

compute the reciprocal of this complex value.

Returns
A temporary object holding the reciprocal value.

◆ normalize() [1/2]

void normalize ( mha_complex_t self)
inline

Divide a complex by its absolute value, thereby normalizing it (projecting onto the unit circle).

◆ normalize() [2/2]

void normalize ( mha_complex_t self,
mha_real_t  margin 
)
inline

Divide a complex by its absolute value, thereby normalizing it (projecting onto the unit circle), with a safety margin.

◆ almost()

bool almost ( const mha_complex_t self,
const mha_complex_t other,
mha_real_t  times_epsilon = 1e2 
)
inline

Compare two complex numbers for equality except for a small relative error.

Parameters
selfThe first complex number.
otherThe second complex number.
times_epsilonPermitted relative error is this number multiplied with the machine accuracy for this Floating point format (std::numeric_limits<mha_real_t>::epsilon)
Returns
true if the relative difference is below times_epsilon * std::numeric_limits<mha_real_t>::epsilon

◆ operator<()

bool operator< ( const mha_complex_t x,
const mha_complex_t y 
)
inline

Compares the absolute values of two complex numbers.