FNFT
|
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... | |
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.
[in] | x | FNFT_COMPLEX argument. |
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.
[in] | D | Number of samples in array q. |
[in] | q | Complex valued array to be subsampled. |
[out] | qsub_ptr | Pointer to the starting location of subsampled signal. |
[out] | Dsub_ptr | Pointer 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_index | Vector 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]]. |
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.
[in,out] | N | It 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] | vals | Complex valued array with elements to be filtered. |
[in] | rearrange_as_well | Complex 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_box | A real array of 4 elements. The elements determine the corners of the bounding box being used for filtering. |
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.
[in,out] | N_ptr | It 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] | vals | Complex valued array with elements to be filtered. |
[in] | rearrange_as_well | Complex 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_box | A real array of 4 elements. The elements determine the corners of the bounding box being used for filtering. |
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.
[in,out] | N_ptr | Pointer 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] | vals | Complex valued array with elements to be filtered. |
[in] | tol_im | Real valued tolerance. |
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.
[in] | lenA | Length of vector vecA. |
[in] | vecA | Complex vector of length lenA. |
[in] | lenB | length of vector vecB. |
[in] | vecB | Complex vector of length lenB. |
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\).
[in] | N | Number of elements in the array. |
[in] | Z | Complex valued array of length N. |
[in] | a | Real number corresponding to first element of Z. |
[in] | b | Real number corresponding to last element of Z. |
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)
[in] | n | Positive integer that is the order of the Legendre polynomial. |
[in] | x | Real scalar value at which the value of the polynomial is to be calculated. |
|
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.
[in] | U | Pointer to the first element of complex values 2x2 matrix U. |
[in,out] | T | Pointer to the first element of complex values 2x2 matrix T. Contains the result U*T on return. |
|
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.
[in] | U | Pointer to the first element of complex values 4x4 matrix U. |
[in,out] | T | Pointer to the first element of complex values 4x4 matrix T. Contains the result U*T on return. |
|
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.
[in] | N | Positive integer that is the size of the two matrices. |
[in] | U | Pointer to the first element of complex valued NxN matrix U. |
[in] | T | Pointer to the first element of complex valued NxN matrix T. |
[out] | TM | Pointer to the first element of complex valued NxN matrix TM which will contain the result TM=U*T on return. |
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.
[in,out] | N_ptr | It 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] | vals | Complex valued array with elements to be filtered. |
[in] | tol | Real valued tolerance. |
Closest larger or equal number that is a power of two.
[in] | number |
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.
[in] | len | Length of the array to be printed. |
[in] | buf | Array to be printed. |
[in] | varname | Name of the array being printed. |
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]|}\).
[in] | len | Length of the vectors |
[in] | vec_numer | Complex array of numerically computed result of length len. |
[in] | vec_exact | Complex array of exact result of length len. |
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".
[in] | D | Number of samples in array q. |
[in] | eps_t | Step-size of t. |
[in] | q | Complex valued array to be resampled. |
[in] | delta | Real valued shift to be applied during resampling. |
[out] | q_new | Complex valued array of resampled signal. |
FNFT_COMPLEX fnft__misc_sech | ( | FNFT_COMPLEX | Z | ) |
Hyperbolic secant.
This function returns the hyperbolic secant of a FNFT_COMPLEX.
[in] | Z | FNFT_COMPLEX argument. |