Libpolycomp  1.0
A compression/decompression library that implements the polynomial compression and other simple compression schemes
Discrete Chebyshev transforms

Functions

pcomp_chebyshev_tpcomp_init_chebyshev (size_t num_of_samples, pcomp_transform_direction_t dir)
 Allocate a new instance of the pcomp_chebyshev_t structure on the heap. More...
 
void pcomp_free_chebyshev (pcomp_chebyshev_t *plan)
 Free the memory allocated by a previous call to pcomp_init_chebyshev. More...
 
size_t pcomp_chebyshev_num_of_samples (const pcomp_chebyshev_t *plan)
 Return the number of samples in a Chebyshev transform. More...
 
pcomp_transform_direction_t pcomp_chebyshev_direction (const pcomp_chebyshev_t *plan)
 Return the direction of a Chebyshev transform. More...
 
int pcomp_run_chebyshev (pcomp_chebyshev_t *plan, pcomp_transform_direction_t dir, double *output, const double *input)
 Compute a forward/backward Chebyshev discrete transform. More...
 
const double * pcomp_chebyshev_input (const pcomp_chebyshev_t *plan)
 Return the input data used in the last call to pcomp_run_chebyshev. More...
 
const double * pcomp_chebyshev_output (const pcomp_chebyshev_t *plan)
 Return the output (Chebyshev transform) of the last call to pcomp_run_chebyshev. More...
 

Detailed Description

The following set of routines compute the Chebyshev transform of a set of floating-point numbers. They form a tiny wrapper around analogous functions of the FFTW library, with the main purpose of using the correct normalization constants in the forward and inverse transforms.

The definition of the forward transform ( $g \rightarrow F$) is the following:

\[ F_k = \frac2{N - 1} \sum_{n=1}^N{}'' g_n\,\cos\left(\frac{\pi(n - 1)(k - 1)}{N - 1}\right),\]

where

\[\sum_{n=1}^N{}'' x_n \equiv \frac{x_1}2 + \sum_{n=2}^{N - 1} x_n + \frac{x_N}2.\]

The backward transform is defined by the following equation:

\[g_n = \sum_{n=1}^N{}'' F_n \cos\left(\frac{\pi(n - 1)(k - 1)}{N - 1}\right).\]

To compute the Chebyshev transform of an array of numbers, the user must allocate a pcomp_chebyshev_t structure using the function pcomp_init_chebyshev. Such structure contains the details about the transform to compute, i.e., the number of elements $N$ and the direction (either forward or backward). The computation of the transform is done by the function pcomp_run_chebyshev.

Since the forward and backward transforms differ only by the multiplicative constant, the function pcomp_run_chebyshev is not too picky and allows the caller to specify the direction of the transform. It is therefore possible to use the same pcomp_chebyshev_t object to compute both the forward and the backward transform (with two separate calls to pcomp_run_chebyshev).

Function Documentation

pcomp_transform_direction_t pcomp_chebyshev_direction ( const pcomp_chebyshev_t plan)

Return the direction of a Chebyshev transform.

Parameters
[in]planPointer to the Chebyshev plan.
Returns
A pcomp_transform_direction_t value specifying the normalization used for the Chebyshev transform specified by plan.

Definition at line 435 of file poly.c.

const double* pcomp_chebyshev_input ( const pcomp_chebyshev_t plan)

Return the input data used in the last call to pcomp_run_chebyshev.

If pcomp_run_chebyshev was never called, the array returned by this function contains garbage.

Parameters
[in]planPointer to a Chebyshev plan created by pcomp_init_chebyshev
Returns
A pointer to the first element of the array of elements used as input by the last call to pcomp_run_chebyshev.

Definition at line 537 of file poly.c.

size_t pcomp_chebyshev_num_of_samples ( const pcomp_chebyshev_t plan)

Return the number of samples in a Chebyshev transform.

Parameters
[in]planPointer to the Chebyshev plan.
Returns
The number of elements that are used in the Chebyshev transform specified by plan.

Definition at line 416 of file poly.c.

const double* pcomp_chebyshev_output ( const pcomp_chebyshev_t plan)

Return the output (Chebyshev transform) of the last call to pcomp_run_chebyshev.

If pcomp_run_chebyshev was never called, the array returned by this function contains garbage.

Parameters
[in]planPointer to a Chebyshev plan created by pcomp_init_chebyshev
Returns
A pointer to the first element of the array of elements containing the output of the last call to pcomp_run_chebyshev.

Definition at line 558 of file poly.c.

void pcomp_free_chebyshev ( pcomp_chebyshev_t plan)

Free the memory allocated by a previous call to pcomp_init_chebyshev.

Parameters
[in]planPointer to the structure to be freed.

Definition at line 390 of file poly.c.

pcomp_chebyshev_t* pcomp_init_chebyshev ( size_t  num_of_samples,
pcomp_transform_direction_t  dir 
)

Allocate a new instance of the pcomp_chebyshev_t structure on the heap.

Despite the fact that this function takes the parameter dir, the function which actually computes the Chebyshev transform (pcomp_run_chebyshev) allow to specify the desired direction. The purpose of having dir encoded in pcomp_chebyshev_t is that sometimes it is useful to keep it memorized in the structure itself.

Parameters
[in]num_of_samplesNumber of floating-point numbers that will be transformed
[in]dirDirection of the transform (either forward or backward). This is used to determine the normalization constant of the transform:
  • If computing a forward transform, the normalization is $1 / (N - 1)$, with $N$ the number of samples.
  • If computing a backward transform, the normalization is 1.
Returns
A newly created instance of pcomp_poly_fit_data_t structure. This must be freed using pcomp_free_poly_fit, once it is no longer used.

Definition at line 365 of file poly.c.

int pcomp_run_chebyshev ( pcomp_chebyshev_t plan,
pcomp_transform_direction_t  dir,
double *  output,
const double *  input 
)

Compute a forward/backward Chebyshev discrete transform.

#define NUM_OF_POINTS 3
double points[NUM_OF_POINTS] = { 0.0, 1.0, 3.0 };
double transform[NUM_OF_POINTS];
pcomp_chebyshev_t* chebyshev;
size_t idx;
chebyshev = pcomp_init_chebyshev(NUM_OF_POINTS, PCOMP_TD_DIRECT);
pcomp_run_chebyshev(chebyshev, PCOMP_TD_DIRECT, transform, points);
puts("Transform:");
for (idx = 0; idx < NUM_OF_POINTS; ++idx) {
printf("%f\t", transform[idx]);
}
puts("");
Parameters
[in]planPointer to a Chebyshev plan created by pcomp_init_chebyshev
[in]dirDirection of the transform. This parameter overrides the internal direction of plan (returned by pcomp_chebyshev_direction).
[out]outputPointer to an array of double values that will contain the Chebyshev transform of input. It must have room for a number of elements at least equal to the return value of pcomp_num_of_samples.
[in]inputArray of double values to be transformed. The function will use the first N elements, where N is the return value of pcomp_num_of_samples.
Returns
PCOMP_STAT_SUCCESS when successful.

Definition at line 491 of file poly.c.