Instruction set:
Data structure: complex_number
It's composed of two variables: int32_t real and int32_t imaginary
Example of variable declaration:
complex_number z1;
cplx_assign(int32_t real , int32_t imaginary , complex_number *z )
Stores inside the variable z (pointer), the complex number formed by the real part "real" and the imaginary part "imaginary".
Example:
cplx_assign(param_R1,param_I1,&z1);
real(complex_number *z )
Returns the real part of the complex number z.
Example:
disp_sumR = real(&z3);
imaginary(complex_number *z )
Returns the imaginary part of the complex number z.
Example:
disp_sumI = imaginary(&z3);
cplx_sum(complex_number *z1 , complex_number *z2 ** , complex_number *z3)**
Performs the sum z1 + z2, stores the result in the variable z3. (Pointers!)
Example:
cplx_sum(&z1,&z2,&z3);
cplx_subtract(complex_number *z1 , complex_number *z2 ** , complex_number *z3)**
Performs the sum z1 - z2, stores the result in the variable z3. (Pointers!)
Example:
cplx_subtract(&z1,&z2,&z3);
cplx_mul_Q27(complex_number *z1 , complex_number *z2 , complex_number *out )
Performs z1 * z2 in fixed point (using Q27 format) and stores the result into the variable "out"
cplx_mul_Q27(&z1,&z2,&z4);
cplx_div_Q27(complex_number *z1 , complex_number *z2 , complex_number *out )
Performs z1 / z2 in fixed point (using Q27 format) and stores the result into the variable "out"
cplx_div_Q27(&z1,&z2,&z5);
cplx_pow_Q27(complex_number *z , int32_t exp , complex_number *out )
Performs z^exp in fixed point (using Q27 format) and stores the result into the variable "out".
cplx_pow_Q27(&z1,param_exp,&z6);
cplx_scale_Q27(complex_number *z , int32_t scale , complex_number *out )
Performs a scalar multiplication between the complex number z and the integer scale (in fixed point, Q27 format) and stores the result into the complex number "out".
cplx_scale_Q27(&z1,param_rate,&z7);
cplx_interp_Q27(complex_number *z1 , complex_number *z2 , int32_t rate , complex_number *out )
Interpolates linearly between two complex numbers z1 and z2 and stores the result into the variable "out". The amount of interpolation is set by the integer "rate".
Rate = 0 outputs z1
Rate = (1<<27) outputs z2
cplx_interp_Q27(&z1,&z2,param_rate,&z8);
cplx_rotate(complex_number *z , uint32_t phase , complex_number *out )
Rotates the complex number z by an amount "phase" and stores the result in the variable "out".
The phase is expressed in unsigned int.
phase = 0 corresponds to 0
phase = (1<<29) corresponds to pi/4
phase = (1<<30) corresponds to pi/2
phase = (1<<31) corresponds to pi
phase = (1<<32) corresponds to 2pi
cplx_rotate(&z1,param_rate<<5,&z10);
cplx_rotate_cheap(complex_number *z , uint32_t phase , complex_number *out )
Rotates the complex number z by an amount "phase" and stores the result in the variable "out".
The phase is expressed in unsigned int.
This one is slightly cheaper than the previous, it just reads the sine2t table, without interpolation.
cplx_rotate_cheap(&z1,param_rate<<5,&z10);
cplx_polar_Q27(complex_number *z , int32_t *modulo , uint32_t *phase )
Converts the complex number z in polar form, and stores the components in the integer variables "modulo" and "phase".
Phase follows the format i described above for the rotate function.
cplx_polar(&z10,&disp_mod,&phase);
cplx_cartesian(complex_number *z , int32_t *real_out , int32_t *imaginary_out )
Outputs the complex number z in cartesian form in the variables real_out and imaginary_out.
It's really just a condensation of the real() and imaginary() functions..
cplx_cartesian(&z4,&disp_mulR,&disp_mulI);