FNFT
Files | Functions
PRIVATE: Miscellaneous helper functions

Files

file  fnft__misc.h
 Miscellaneous functions used in the FNFT library.
 

Functions

void fnft__misc_print_buf (const FNFT_INT len, FNFT_COMPLEX const *const buf, char const *const varname)
 Helper function for debugging. Prints an array in MATLAB style. More...
 
FNFT_REAL fnft__misc_rel_err (const FNFT_INT len, FNFT_COMPLEX const *const vec_numer, FNFT_COMPLEX const *const vec_exact)
 Relative l1 error between two vectors. More...
 
FNFT_REAL fnft__misc_hausdorff_dist (const FNFT_UINT lenA, FNFT_COMPLEX const *const vecA, const FNFT_UINT lenB, FNFT_COMPLEX const *const vecB)
 Hausdorff distance between two vectors. More...
 
FNFT_COMPLEX fnft__misc_sech (FNFT_COMPLEX Z)
 Hyperbolic secant. More...
 
FNFT_REAL fnft__misc_l2norm2 (const FNFT_UINT N, FNFT_COMPLEX const *const Z, const FNFT_REAL a, const FNFT_REAL b)
 Squared l2 norm. More...
 
FNFT_INT fnft__misc_filter (FNFT_UINT *const N, FNFT_COMPLEX *const vals, FNFT_COMPLEX *const rearrange_as_well, FNFT_REAL const *const bounding_box)
 Filters array by retaining elements inside a bounding box. More...
 
FNFT_INT fnft__misc_filter_nonreal (FNFT_UINT *N_ptr, FNFT_COMPLEX *const vals, const FNFT_REAL tol_im)
 Filter array based on specified tolerance. More...
 
FNFT_INT fnft__misc_filter_inv (FNFT_UINT *const N_ptr, FNFT_COMPLEX *const vals, FNFT_COMPLEX *const rearrange_as_well, FNFT_REAL const *const bounding_box)
 Filters array by retaining elements outside a bounding box. More...
 
FNFT_INT fnft__misc_merge (FNFT_UINT *N_ptr, FNFT_COMPLEX *const vals, FNFT_REAL tol)
 Merges elements in an array with distance lower than tol. More...
 
FNFT_INT fnft__misc_downsample (const FNFT_UINT D, FNFT_COMPLEX const *const q, FNFT_UINT *const Dsub_ptr, FNFT_COMPLEX **qsub_ptr, FNFT_UINT *const first_last_index)
 Downsamples an array. More...
 
FNFT_COMPLEX fnft__misc_CSINC (FNFT_COMPLEX x)
 Sinc function for complex arguments. More...
 
FNFT_UINT fnft__misc_nextpowerof2 (const FNFT_UINT number)
 Closest larger or equal number that is a power of two. More...
 
FNFT_INT fnft__misc_resample (const FNFT_UINT D, const FNFT_REAL eps_t, FNFT_COMPLEX const *const q, const FNFT_REAL delta, FNFT_COMPLEX *const q_new)
 Resamples an array. More...
 
static void fnft__misc_mat_mult_proto (const FNFT_UINT N, FNFT_COMPLEX *const U, FNFT_COMPLEX *const T, FNFT_COMPLEX *const TM)
 Multiples two square matrices of size N. More...
 
static void fnft__misc_mat_mult_2x2 (FNFT_COMPLEX *const U, FNFT_COMPLEX *const T)
 Multiples two square matrices of size 2. More...
 
static void fnft__misc_mat_mult_4x4 (FNFT_COMPLEX *const U, FNFT_COMPLEX *const T)
 Multiples two square matrices of size 4. More...
 
static FNFT_REAL fnft__misc_legendre_poly (const FNFT_UINT n, const FNFT_REAL x)
 This routine returns the nth degree Legendre polynomial at x. More...
 

Detailed Description

Function Documentation

◆ fnft__misc_CSINC()

FNFT_COMPLEX fnft__misc_CSINC ( FNFT_COMPLEX  x)

Sinc function for complex arguments.

Function computes the Sinc function sin(x)/x for FNFT_COMPLEX argument.

Parameters
[in]xFNFT_COMPLEX argument.
Returns
Sinc(x).

◆ fnft__misc_downsample()

FNFT_INT fnft__misc_downsample ( const FNFT_UINT  D,
FNFT_COMPLEX const *const  q,
FNFT_UINT *const  Dsub_ptr,
FNFT_COMPLEX **  qsub_ptr,
FNFT_UINT *const  first_last_index 
)

Downsamples an array.

Computes a subsampled version of q. The length of q is D>=2. The routine will allocate memory for the subsampled signal qsub and updates the pointer *qsub_ptr such that it points to the newly allocated qsub. The user is responsible to freeing the memory later.

Parameters
[in]DNumber of samples in array q.
[in]qComplex valued array to be subsampled.
[out]qsub_ptrPointer to the starting location of subsampled signal.
[out]Dsub_ptrPointer to new number of samples. Upon entry, *Dsub_ptr should contain a desired number of samples. Upon exit, *Dsub_ptr has been overwritten with the actual number of samples that the routine has chosen. It is usually close to the desired one.
[out]first_last_indexVector of length two. Upon exit, it contains the original index of the first and the last sample in qsub. That is, qsub[0]=q[first_last_index[0]] and qsub[Dsub-1]=q[first_last_index[1]].
Returns
Returns SUCCESS or an error code.

◆ fnft__misc_filter()

FNFT_INT fnft__misc_filter ( FNFT_UINT *const  N,
FNFT_COMPLEX *const  vals,
FNFT_COMPLEX *const  rearrange_as_well,
FNFT_REAL const *const  bounding_box 
)

Filters array by retaining elements inside a bounding box.

This function filters the array vals. Only values that satisfy

 bounding_box[0] <= real(val) <= bounding_box[1]

and

 bounding_box[2] <= imag(val) <= bounding_box[3]

are kept.

Parameters
[in,out]NIt is the pointer to the number of values to be filtered. On exit *N is overwritten with the number of values that have survived fitering. Their values will be moved to the beginning of vals.
[in,out]valsComplex valued array with elements to be filtered.
[in]rearrange_as_wellComplex valued array. If the array rearrange_as_well is not NULL, then the values in there are rearranged together with the values in vals.
[in]bounding_boxA real array of 4 elements. The elements determine the corners of the bounding box being used for filtering.
Returns
Returns SUCCESS or an error code.

◆ fnft__misc_filter_inv()

FNFT_INT fnft__misc_filter_inv ( FNFT_UINT *const  N_ptr,
FNFT_COMPLEX *const  vals,
FNFT_COMPLEX *const  rearrange_as_well,
FNFT_REAL const *const  bounding_box 
)

Filters array by retaining elements outside a bounding box.

This function filters the array vals. Only values OUTSIDE the bounding box are kept.

Parameters
[in,out]N_ptrIt is the pointer to the number of values to be filtered. On exit *N_ptr is overwritten with the number of values that have survived fitering. Their values will be moved to the beginning of vals.
[in,out]valsComplex valued array with elements to be filtered.
[in]rearrange_as_wellComplex valued array. If the array rearrange_as_well is not NULL, then the values in there are rearranged together with the values in vals.
[in]bounding_boxA real array of 4 elements. The elements determine the corners of the bounding box being used for filtering.
Returns
Returns SUCCESS or an error code.

◆ fnft__misc_filter_nonreal()

FNFT_INT fnft__misc_filter_nonreal ( FNFT_UINT N_ptr,
FNFT_COMPLEX *const  vals,
const FNFT_REAL  tol_im 
)

Filter array based on specified tolerance.

This function removes all entries from the array vals with |Im(val)|>tol_im.

Parameters
[in,out]N_ptrPointer to number of values to be filtered. On exit *N_ptr is overwritten with the number of values that have survived fitering. Their values will be moved to the beginning of vals.
[in,out]valsComplex valued array with elements to be filtered.
[in]tol_imReal valued tolerance.
Returns
Returns SUCCESS or an error code.

◆ fnft__misc_hausdorff_dist()

FNFT_REAL fnft__misc_hausdorff_dist ( const FNFT_UINT  lenA,
FNFT_COMPLEX const *const  vecA,
const FNFT_UINT  lenB,
FNFT_COMPLEX const *const  vecB 
)

Hausdorff distance between two vectors.

This function computes the Hausdorff distance between two vectors vecA and vecB.

Parameters
[in]lenALength of vector vecA.
[in]vecAComplex vector of length lenA.
[in]lenBlength of vector vecB.
[in]vecBComplex vector of length lenB.
Returns
Returns the real valued Hausdorff distance between the vectors vecA and vecB.

◆ fnft__misc_l2norm2()

FNFT_REAL fnft__misc_l2norm2 ( const FNFT_UINT  N,
FNFT_COMPLEX const *const  Z,
const FNFT_REAL  a,
const FNFT_REAL  b 
)

Squared l2 norm.

This function computes the quantity
\( val = \frac{b-a}{2N}.(|Z[0]|^2+|Z[N-1]|^2)+\sum_{i=1}^{i=N-2}\frac{b-a}{N}.|Z[i]|^2\).

Parameters
[in]NNumber of elements in the array.
[in]ZComplex valued array of length N.
[in]aReal number corresponding to first element of Z.
[in]bReal number corresponding to last element of Z.
Returns
Returns the quantity val. Returns NAN if N<2 or a>=b.

◆ fnft__misc_legendre_poly()

static FNFT_REAL fnft__misc_legendre_poly ( const FNFT_UINT  n,
const FNFT_REAL  x 
)
inlinestatic

This routine returns the nth degree Legendre polynomial at x.

Calculates the the nth degree Legendre polynomial at x using a recursive relation (Online, Accessed July 2020)

Parameters
[in]nPositive integer that is the order of the Legendre polynomial.
[in]xReal scalar value at which the value of the polynomial is to be calculated.
Returns
Returns the value of nth degree Legendre polynomial at x.

◆ fnft__misc_mat_mult_2x2()

static void fnft__misc_mat_mult_2x2 ( FNFT_COMPLEX *const  U,
FNFT_COMPLEX *const  T 
)
inlinestatic

Multiples two square matrices of size 2.

Multiples two square matrices U and T of size 2. T is replaced by the result U*T.

Parameters
[in]UPointer to the first element of complex values 2x2 matrix U.
[in,out]TPointer to the first element of complex values 2x2 matrix T. Contains the result U*T on return.

◆ fnft__misc_mat_mult_4x4()

static void fnft__misc_mat_mult_4x4 ( FNFT_COMPLEX *const  U,
FNFT_COMPLEX *const  T 
)
inlinestatic

Multiples two square matrices of size 4.

Multiples two square matrices U and T of size 4. T is replaced by the result U*T.

Parameters
[in]UPointer to the first element of complex values 4x4 matrix U.
[in,out]TPointer to the first element of complex values 4x4 matrix T. Contains the result U*T on return.

◆ fnft__misc_mat_mult_proto()

static void fnft__misc_mat_mult_proto ( const FNFT_UINT  N,
FNFT_COMPLEX *const  U,
FNFT_COMPLEX *const  T,
FNFT_COMPLEX *const  TM 
)
inlinestatic

Multiples two square matrices of size N.

Multiples two square matrices U and T of size N. T is replaced by the result U*T.

Parameters
[in]NPositive integer that is the size of the two matrices.
[in]UPointer to the first element of complex valued NxN matrix U.
[in]TPointer to the first element of complex valued NxN matrix T.
[out]TMPointer to the first element of complex valued NxN matrix TM which will contain the result TM=U*T on return.

◆ fnft__misc_merge()

FNFT_INT fnft__misc_merge ( FNFT_UINT N_ptr,
FNFT_COMPLEX *const  vals,
FNFT_REAL  tol 
)

Merges elements in an array with distance lower than tol.

This function filters an array by merging elements if distance between the elements is less than tol.

Parameters
[in,out]N_ptrIt is the pointer to the number of elements to be filtered. On exit *N_ptr is overwritten with the number of values that have survived fitering. Their values will be moved to the beginning of vals.
[in,out]valsComplex valued array with elements to be filtered.
[in]tolReal valued tolerance.
Returns
Returns SUCCESS or an error code.

◆ fnft__misc_nextpowerof2()

FNFT_UINT fnft__misc_nextpowerof2 ( const FNFT_UINT  number)

Closest larger or equal number that is a power of two.

Parameters
[in]number
Returns
min{r >= number : exists d such that r = 2^d}

◆ fnft__misc_print_buf()

void fnft__misc_print_buf ( const FNFT_INT  len,
FNFT_COMPLEX const *const  buf,
char const *const  varname 
)

Helper function for debugging. Prints an array in MATLAB style.

This function prints an array in MATLAB style.

Parameters
[in]lenLength of the array to be printed.
[in]bufArray to be printed.
[in]varnameName of the array being printed.

◆ fnft__misc_rel_err()

FNFT_REAL fnft__misc_rel_err ( const FNFT_INT  len,
FNFT_COMPLEX const *const  vec_numer,
FNFT_COMPLEX const *const  vec_exact 
)

Relative l1 error between two vectors.

This function computes the relative l1 error between two vectors.
\(err = \frac{\sum_{i=0}^{i=len-1} |vec\_numer[i]-vec\_exact[i]|}{\sum_{i=0}^{i=len-1} |vec\_exact[i]|}\).

Parameters
[in]lenLength of the vectors
[in]vec_numerComplex array of numerically computed result of length len.
[in]vec_exactComplex array of exact result of length len.
Returns
Returns the real valued relative error err.

◆ fnft__misc_resample()

FNFT_INT fnft__misc_resample ( const FNFT_UINT  D,
const FNFT_REAL  eps_t,
FNFT_COMPLEX const *const  q,
const FNFT_REAL  delta,
FNFT_COMPLEX *const  q_new 
)

Resamples an array.

Computes a resampled version of q. The length of q is D>=2. Performs bandlimited interpolation to obtain signal samples at new locations \(q(t_{n}+\delta)\) from samples given at \(q(t_{n})\) for \(n=0,1,...,D-1\). This is required for the CF4_2, CF4_3, CF5_3, CF6_4, 4SPLIT4A and 4SPLIT4B discretizations. The routine checks the difference between the l2-norm of the complete spectrum and approximately 90% of the spectrum. The following warning is issued if the difference is high. "Signal does not appear to be bandlimited. Interpolation step may be inaccurate. Try to reduce the step size, or switch to a discretization that does not require interpolation".

Parameters
[in]DNumber of samples in array q.
[in]eps_tStep-size of t.
[in]qComplex valued array to be resampled.
[in]deltaReal valued shift to be applied during resampling.
[out]q_newComplex valued array of resampled signal.
Returns
Returns SUCCESS or an error code.

◆ fnft__misc_sech()

FNFT_COMPLEX fnft__misc_sech ( FNFT_COMPLEX  Z)

Hyperbolic secant.

This function returns the hyperbolic secant of a FNFT_COMPLEX.

Parameters
[in]ZFNFT_COMPLEX argument.
Returns
hyperbolic secant of Z.