![]() |
libdspl-2.0
Digital Signal Processing Algorithm Library
|
Functions | |
int DSPL_API | cheby_poly1 (double *x, int n, int ord, double *y) |
Chebyshev polynomial of the first kind order ord More... | |
int DSPL_API | cheby_poly2 (double *x, int n, int ord, double *y) |
Chebyshev polynomial of the second kind order ord More... | |
Detailed Description
Function Documentation
◆ cheby_poly1()
int cheby_poly1 | ( | double * | x, |
int | n, | ||
int | ord, | ||
double * | y | ||
) |
Chebyshev polynomial of the first kind order ord
Function calculates Chebyshev polynomial \( C_{ord}(x)\) of the first kind order ord
for the real vector x
(length n
) by recurrent equation:
\[ C_{ord}(x) = 2 x C_{ord-1}(x) - C_{ord-2}(x), \]
where \( C_0(x) = 1 \), \( C_1(x) = x\)
- Parameters
-
[in] x Pointer to the real argument vector x
.
Vector size is[n x 1]
.
[in] n Size of vectors x
andy
.
[in] ord Chebyshev polynomial order.
[out] y Pointer to the Chebyshev polynomial values, corresponds to the argument x
.
Vector size is[n x 1]
.
Memory must be allocated.
- Returns
RES_OK
if Chebyshev polynomial is calculated successfully.
Else code error.
Example:
Text files will be created in dat
directory:
cheby_poly1_ord1.txt cheby_poly1_ord2.txt cheby_poly1_ord3.txt cheby_poly1_ord4.txt
GNUPLOT package will create Chebyshev polynomials plot from saved text-files:

◆ cheby_poly2()
int cheby_poly2 | ( | double * | x, |
int | n, | ||
int | ord, | ||
double * | y | ||
) |
Chebyshev polynomial of the second kind order ord
Function calculates Chebyshev polynomial \( U_ord(x)\) of the first kind order ord
for the real vector x
(length n
) by recurrent equation:
\[ U_{ord}(x) = 2 x U_{ord-1}(x) - U_{ord-2}(x), \]
where \( U_0(x) = 1 \), \( U_1(x) = 2x\)
- Parameters
-
[in] x Pointer to the real argument vector x
.
Vector size is[n x 1]
.
[in] n Size of vectors x
andy
.
[in] ord Chebyshev polynomial order.
[out] y Pointer to the Chebyshev polynomial values, corresponds to the argument x
.
Vector size is[n x 1]
.
Memory must be allocated.
- Returns
RES_OK
if Chebyshev polynomial is calculated successfully.
Else code error.
Example:#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dspl.h"#define N 250int main(int argc, char* argv[]){void* hdspl; /* DSPL handle */void* hplot; /* GNUPLOT handle */double x[N], y[N];int ord;char fn[64];hdspl = dspl_load(); /* Load DSPL function */linspace(-1.0, 1.0, N, DSPL_SYMMETRIC, x);for(ord = 1; ord < 5; ord++){cheby_poly2(x, N, ord, y);sprintf(fn, "dat/cheby_poly2_ord%d.txt", ord);writetxt(x,y,N,fn);}/* plotting by GNUPLOT */gnuplot_create(argc, argv, 560, 380, "img/cheby_poly2.png", &hplot);gnuplot_cmd(hplot, "set grid");gnuplot_cmd(hplot, "set key left top");gnuplot_cmd(hplot, "set xlabel 'x'");gnuplot_cmd(hplot, "set ylabel 'U_N (x)'");gnuplot_cmd(hplot, "set yrange [-3.5:3.5]");gnuplot_cmd(hplot, "plot 'dat/cheby_poly2_ord1.txt' with lines, \\");gnuplot_cmd(hplot, " 'dat/cheby_poly2_ord2.txt' with lines, \\");gnuplot_cmd(hplot, " 'dat/cheby_poly2_ord3.txt' with lines, \\");gnuplot_cmd(hplot, " 'dat/cheby_poly2_ord4.txt' with lines");gnuplot_close(hplot);dspl_free(hdspl); /* free dspl handle */return 0;}
Text files will be created in dat
directory:
cheby_poly2_ord1.txt cheby_poly2_ord2.txt cheby_poly2_ord3.txt cheby_poly2_ord4.txt
GNUPLOT package will create Chebyshev polynomials plot from saved text-files:

Generated on Mon Dec 14 2020 14:02:36 for libdspl-2.0 by
