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

Detailed Description

Function Documentation

◆ fnft__misc_CSINC()

FNFT_COMPLEX fnft__misc_CSINC ( FNFT_COMPLEX  x)

Sinc function for complex arguments.

Functions 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_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_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.