![]() |
libdspl-2.0
Digital Signal Processing Algorithm Library
|
Functions | |
int DSPL_API | butter_ap (double rp, int ord, double *b, double *a) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass Butterworth filter. More... | |
int DSPL_API | butter_ap_zp (int ord, double rp, complex_t *z, int *nz, complex_t *p, int *np) |
Function calculates arrays of zeros and poles for analog normlized lowpass Batterworth filter transfer function \( H(s) \) order ord . More... | |
int DSPL_API | cheby1_ap (double rp, int ord, double *b, double *a) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass Chebyshev type 1 filter. More... | |
int DSPL_API | cheby1_ap_zp (int ord, double rp, complex_t *z, int *nz, complex_t *p, int *np) |
Function calculates arrays of zeros and poles for analog normlized lowpass Chebyshev type 1 filter transfer function \( H(s) \) order ord . More... | |
int DSPL_API | cheby2_ap (double rs, int ord, double *b, double *a) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass Chebyshev type 2 filter. More... | |
int DSPL_API | cheby2_ap_zp (int ord, double rs, complex_t *z, int *nz, complex_t *p, int *np) |
Function calculates arrays of zeros and poles for analog normlized lowpass Chebyshev type 2 filter transfer function \( H(s) \) order ord . More... | |
int DSPL_API | ellip_ap (double rp, double rs, int ord, double *b, double *a) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass elliptic filter order ord with passband ripple rp dB and stopband suppression equals rs dB. More... | |
int DSPL_API | ellip_ap_zp (int ord, double rp, double rs, complex_t *z, int *nz, complex_t *p, int *np) |
Function calculates arrays of zeros and poles for analog normlized lowpass elliptic filter transfer function \( H(s) \) order ord . More... | |
int DSPL_API | low2high (double *b, double *a, int ord, double w0, double w1, double *beta, double *alpha) |
Lowpass to highpass filter frequency transform. More... | |
int DSPL_API | low2low (double *b, double *a, int ord, double w0, double w1, double *beta, double *alpha) |
int DSPL_API | ratcompos (double *b, double *a, int n, double *c, double *d, int p, double *beta, double *alpha) |
Rational composition. More... | |
int DSPL_API | bilinear (double *bs, double *as, int ord, double *bz, double *az) |
Transform a s-plane analog filter transfer function \(H(s)\) to the digital filter transfer function \(H(z)\). More... | |
int DSPL_API | iir (double rp, double rs, int ord, double w0, double w1, int type, double *b, double *a) |
Digital IIR filter design. More... | |
Detailed Description
Function Documentation
◆ bilinear()
int bilinear | ( | double * | bs, |
double * | as, | ||
int | ord, | ||
double * | bz, | ||
double * | az | ||
) |
Transform a s-plane analog filter transfer function \(H(s)\) to the digital filter transfer function \(H(z)\).
Bilinear transform is rational composition:
\[ s \leftarrow \frac{1 - z^{-1}}{1 - z^{-1}}. \]
Digital filter order, passband magnitude ripple and stopband suppression still the same after bilinear transform as analog filter.
Frequency \(\Omega\) of analog filter and frequency
\(\omega\) of digital filter relations:
\[ \Omega = \tan(\omega / 2). \]
- Parameters
-
[in] bs Pointer to the vector of analog filter \(H(s)\) numerator coefficients. Vector size is [ord+1 x 1]
.
[in] as Pointer to the vector of analog filter \(H(s)\) denominator coefficients vector. Vector size is [ord+1 x 1]
.
[in] ord Analog and digital filters order.
[out] bz Pointer to the vector of digital filter \(H(z)\) numerator coefficients after bilinear transform. Vector size is [ord+1 x 1]
.
Memory must be allocated.
[out] az Pointer to the vector of digital filter \(H(z)\) denominator coefficients after bilinear transform. Vector size is [ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if bilinear transform is calculated successfully.
Else code error.
Example:
This program calculates the transfer function \(H(s)\) of analog Chebyshev filter of the first kind, with a cutoff frequency of 1 rad/s, and produces bilinear trandform to digital filter, with a normilized cutoff frequency equals 0.5.
Result:
bz[0] = 0.246 az[0] = 4.425 bz[1] = 0.983 az[1] = -3.318 bz[2] = 1.474 az[2] = 4.746 bz[3] = 0.983 az[3] = -2.477 bz[4] = 0.246 az[4] = 1.034 err = 0
In addition, the frequency response of the resulting digital filter is calculated and plotted by GNUPLOT package.

Definition at line 210 of file filter_iir.c.
Referenced by iir().
◆ butter_ap()
int butter_ap | ( | double | Rp, |
int | ord, | ||
double * | b, | ||
double * | a | ||
) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass Butterworth filter.
Analog normalized lowpass filter magnitude ripple equals \( -R_p \) dB for angular frequency \( \omega \) from 0 to 1 rad/s.
- Parameters
-
[in] Rp Magnitude ripple in passband (dB).
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency.
Parameter must be positive.
[in] ord Filter order.
Filter coefficients number equalsord+1
for numerator and denominator of transfer function \( H(s) \)
[out] b Pointer to the vector of transfer function \(H(s)\) numerator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
[out] a Pointer to the vector of transfer function \(H(s)\) denominator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if filter coefficients is calculated successfully.
Else code error.
Example:
Result:
b[ 0] = 1.965 a[ 0] = 1.965 b[ 1] = 0.000 a[ 1] = 3.138 b[ 2] = 0.000 a[ 2] = 2.505 b[ 3] = 0.000 a[ 3] = 1.000
In dat
folder will be created 3 files:
butter_ap_test_mag.txt magnitude butter_ap_test_phi.txt phase response butter_ap_test_tau.txt group delay
In addition, GNUPLOT will build the following graphs from data stored in files:

Definition at line 174 of file filter_ap.c.
◆ butter_ap_zp()
Function calculates arrays of zeros and poles for analog normlized lowpass Batterworth filter transfer function \( H(s) \) order ord
.
Analog normalized lowpass filter magnitude ripple equals \( -R_p \) dB for angular frequency \( \omega \) from 0 to 1 rad/s.
- Parameters
-
[in] ord Filter order.
Number of zeros and poles of filter can be less or equalord
.
[in] rp Magnitude ripple in passband (dB).
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency.
Parameter must be positive.
[out] z Pointer to the \( H(s) \) zeros array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] nz Pointer to the variable which keep number of finite zeros \( H(s) \).
Number of finite zeros which was calculated and saved in vectorz
.
Pointer cannot beNULL
.
[out] p Pointer to the \( H(s) \) poles array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] np Pointer to the variable which keep number of calculated poles of \( H(s) \).
Pointer cannot beNULL
.
- Returns
RES_OK
if zeros and poles is calculated successfully.
Else code error.
- Note
- Normalized Butterworth lowpass filter has no finite zeros. So
z
vector will not changed and in pointernz
will write 0 value.
Example of normalized Butterworth lowpass filter zeros and poles calculation:
Result:
Butterworth filter zeros: 0 Butterworth filter poles: 7 p[ 0] = -1.101 +0.000 j p[ 1] = -0.245 +1.074 j p[ 2] = -0.245 -1.074 j p[ 3] = -0.687 +0.861 j p[ 4] = -0.687 -0.861 j p[ 5] = -0.992 +0.478 j p[ 6] = -0.992 -0.478 j
In dat
folder will be created butter_ap_zp.txt
file.
In addition, GNUPLOT will build the following graphs from data stored in dat/butter_ap_zp.txt
file:

Definition at line 396 of file filter_ap.c.
Referenced by butter_ap().
◆ cheby1_ap()
int cheby1_ap | ( | double | Rp, |
int | ord, | ||
double * | b, | ||
double * | a | ||
) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass Chebyshev type 1 filter.
Analog normalized lowpass filter magnitude ripple equals \( -R_p \) dB for angular frequency \( \omega \) from 0 to 1 rad/s.
- Parameters
-
[in] Rp Magnitude ripple in passband (dB).
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency.
Parameter must be positive.
[in] ord Filter order.
Filter coefficients number equalsord+1
for numerator and denominator of transfer function \( H(s) \)
[out] b Pointer to the vector of transfer function \(H(s)\) numerator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
[out] a Pointer to the vector of transfer function \(H(s)\) denominator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if filter coefficients is calculated successfully.
Else code error.
Example:
Result:
b[ 0] = 0.125 a[ 0] = 0.177 b[ 1] = 0.000 a[ 1] = 0.405 b[ 2] = 0.000 a[ 2] = 1.169 b[ 3] = 0.000 a[ 3] = 0.582 b[ 4] = 0.000 a[ 4] = 1.000
In dat
folder will be created 3 files:
cheby1_ap_test_mag.txt magnitude cheby1_ap_test_phi.txt phase response cheby1_ap_test_tau.txt group delay
In addition, GNUPLOT will build the following graphs from data stored in files:

Definition at line 595 of file filter_ap.c.
◆ cheby1_ap_zp()
Function calculates arrays of zeros and poles for analog normlized lowpass Chebyshev type 1 filter transfer function \( H(s) \) order ord
.
Analog normalized lowpass filter magnitude ripple equals \( -R_p \) dB for angular frequency \( \omega \) from 0 to 1 rad/s.
- Parameters
-
[in] ord Filter order.
Number of zeros and poles of filter can be less or equalord
.
[in] rp Magnitude ripple in passband (dB).
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency.
Parameter must be positive.
[out] z Pointer to the \( H(s) \) zeros array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] nz Pointer to the variable which keep number of finite zeros \( H(s) \).
Number of finite zeros which was calculated and saved in vectorz
.
Pointer cannot beNULL
.
[out] p Pointer to the \( H(s) \) poles array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] np Pointer to the variable which keep number of calculated poles of \( H(s) \).
Pointer cannot beNULL
.
- Returns
RES_OK
if zeros and poles is calculated successfully.
Else code error.
- Note
- Normalized Chebyshev type 1 lowpass filter has no finite zeros. So
z
vector will not changed and in pointernz
will write 0 value.
Example of normalized Chebyshev type 1 lowpass filter zeros and poles calculation:#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dspl.h"/* Filter order */#define ORD 7int main(int argc, char* argv[]){void* hdspl; /* DSPL handle */void* hplot; /* GNUPLOT handle *//* Load DSPL functions */hdspl = dspl_load();complex_t z[ORD+1]; /* H(s) zeros vector */complex_t p[ORD+1]; /* H(s) poles vector */double Rp = 0.5; /* Magnitude ripple from 0 to 1 rad/s */int res, k, nz, np;/* Zeros and poles vectors calculation */res = cheby1_ap_zp(ORD, Rp, z, &nz, p, &np);if(res != RES_OK)printf("error code = 0x%8x\n", res);/* print H(s) zeros values */printf("Chebyshev type 1 filter zeros: %d\n", nz);for(k = 0; k < nz; k++)/* print H(s) poles values */printf("Chebyshev type 1 filter poles: %d\n", np);for(k = 0; k < np; k++)/* Write complex poles to the file */writetxt_cmplx(p, ORD, "dat/cheby1_ap_zp.txt");/* plotting by GNUPLOT */gnuplot_create(argc, argv, 440, 360, "img/cheby1_ap_zp_test.png", &hplot);gnuplot_cmd(hplot, "unset key");gnuplot_cmd(hplot, "set xzeroaxis");gnuplot_cmd(hplot, "set yzeroaxis");gnuplot_cmd(hplot, "set xlabel 'sigma'");gnuplot_cmd(hplot, "set ylabel 'jw'");gnuplot_cmd(hplot, "set size square");gnuplot_cmd(hplot, "set xrange [-1.5:1.5]");gnuplot_cmd(hplot, "set yrange [-1.5:1.5]");gnuplot_cmd(hplot, "plot 'dat/cheby1_ap_zp.txt' with points pt 2");gnuplot_close(hplot);/* free dspl handle */dspl_free(hdspl);return res;}
Result:
Chebyshev type 1 filter zeros: 0 Chebyshev type 1 filter poles: 7 p[ 0] = -0.256 +0.000 j p[ 1] = -0.057 +1.006 j p[ 2] = -0.057 -1.006 j p[ 3] = -0.160 +0.807 j p[ 4] = -0.160 -0.807 j p[ 5] = -0.231 +0.448 j p[ 6] = -0.231 -0.448 j
In dat
folder will be created cheby1_ap_zp.txt
file.
In addition, GNUPLOT will build the following graphs from data stored in dat/cheby1_ap_zp.txt
file:

Definition at line 826 of file filter_ap.c.
Referenced by cheby1_ap().
◆ cheby2_ap()
int cheby2_ap | ( | double | Rs, |
int | ord, | ||
double * | b, | ||
double * | a | ||
) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass Chebyshev type 2 filter.
Analog normalized Chebyshev type 2 filter lowpass filter has \(Rs\) dB suppression in stopband. Also analog normalized Chebyshev type 2 filter magnitude equals \(-Rs\) dB for angular frequency \(\omega = 1\) rad/s.
- Parameters
-
[in] Rs Suppression level in stopband (dB).
This parameter sets filter supression for \(\omega \geq 1\) rad/s frequency.
Parameter must be positive.
[in] ord Filter order.
Filter coefficients number equalsord+1
for numerator and denominator of transfer function \( H(s) \)
[out] b Pointer to the vector of transfer function \(H(s)\) numerator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
[out] a Pointer to the vector of transfer function \(H(s)\) denominator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if filter coefficients is calculated successfully.
Else code error.
Example:
Result:
b[ 0] = 0.008 a[ 0] = 0.008 b[ 1] = 0.000 a[ 1] = 0.068 b[ 2] = 0.008 a[ 2] = 0.300 b[ 3] = 0.000 a[ 3] = 0.774 b[ 4] = 0.001 a[ 4] = 1.000
In dat
folder will be created 3 files:
cheby2_ap_test_mag.txt magnitude cheby2_ap_test_phi.txt phase response cheby2_ap_test_tau.txt group delay
In addition, GNUPLOT will build the following graphs from data stored in files:

Definition at line 1031 of file filter_ap.c.
◆ cheby2_ap_zp()
Function calculates arrays of zeros and poles for analog normlized lowpass Chebyshev type 2 filter transfer function \( H(s) \) order ord
.
Analog normalized Chebyshev type 2 filter lowpass filter has \(Rs\) dB suppression in stopband. Also analog normalized Chebyshev type 2 filter magnitude equals \(-Rs\) dB for angular frequency \(\omega = 1\) rad/s.
- Parameters
-
[in] ord Filter order.
Number of zeros and poles of filter can be less or equalord
.
[in] rs Suppression level in stopband (dB).
This parameter sets filter supression for \(\omega \geq 1\) rad/s frequency.
Parameter must be positive.
[out] z Pointer to the \( H(s) \) zeros array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] nz Pointer to the variable which keep number of finite zeros \( H(s) \).
Number of finite zeros which was calculated and saved in vectorz
.
Pointer cannot beNULL
.
[out] p Pointer to the \( H(s) \) poles array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] np Pointer to the variable which keep number of calculated poles of \( H(s) \).
Pointer cannot beNULL
.
- Returns
RES_OK
if zeros and poles is calculated successfully.
Else code error.
Example of normalized Chebyshev type 2 lowpass filter zeros and poles calculation:#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dspl.h"/* Filter order */#define ORD 7int main(int argc, char* argv[]){void* hdspl; /* DSPL handle */void* hplot; /* GNUPLOT handle *//* Load DSPL functions */hdspl = dspl_load();complex_t z[ORD+1]; /* H(s) zeros vector */complex_t p[ORD+1]; /* H(s) poles vector */double Rs = 40; /* Stopband suppression, dB */int res, k, nz, np;/* Zeros and poles vectors calculation */res = cheby2_ap_zp(ORD, Rs, z, &nz, p, &np);if(res != RES_OK)printf("error code = 0x%8x\n", res);/* print H(s) zeros values */printf("Chebyshev type 2 filter zeros: %d\n", nz);for(k = 0; k < nz; k++)/* print H(s) poles values */printf("Chebyshev type 2 filter poles: %d\n", np);for(k = 0; k < np; k++)/* Write complex poles to the file */writetxt_cmplx(z, nz, "dat/cheby2_ap_z.txt");writetxt_cmplx(p, np, "dat/cheby2_ap_p.txt");/* plotting by GNUPLOT */gnuplot_create(argc, argv, 440, 360, "img/cheby2_ap_zp_test.png", &hplot);gnuplot_cmd(hplot, "unset key");gnuplot_cmd(hplot, "set xzeroaxis");gnuplot_cmd(hplot, "set yzeroaxis");gnuplot_cmd(hplot, "set xlabel 'sigma'");gnuplot_cmd(hplot, "set ylabel 'jw'");gnuplot_cmd(hplot, "set size square");gnuplot_cmd(hplot, "set xrange [-3:3]");gnuplot_cmd(hplot, "set yrange [-3:3]");gnuplot_cmd(hplot, "plot 'dat/cheby2_ap_p.txt' with points pt 2, \\");gnuplot_cmd(hplot, " 'dat/cheby2_ap_z.txt' with points pt 6");gnuplot_close(hplot);/* free dspl handle */dspl_free(hdspl);return res;}
Result:
Chebyshev type 2 filter zeros: 6 z[ 0] = 0.000 +1.026 j z[ 1] = 0.000 -1.026 j z[ 2] = 0.000 +1.279 j z[ 3] = 0.000 -1.279 j z[ 4] = 0.000 +2.305 j z[ 5] = 0.000 -2.305 j Chebyshev type 2 filter poles: 7 p[ 0] = -1.203 +0.000 j p[ 1] = -0.113 +0.772 j p[ 2] = -0.113 -0.772 j p[ 3] = -0.398 +0.781 j p[ 4] = -0.398 -0.781 j p[ 5] = -0.852 +0.642 j p[ 6] = -0.852 -0.642 j
In dat
folder will be created cheby2_ap_z.txt
and cheby2_ap_z.txt
files which keeps zeros and poles vectors.
In addition, GNUPLOT will build the following graphs from data stored in the files:

Definition at line 1298 of file filter_ap.c.
Referenced by cheby2_ap().
◆ ellip_ap()
int ellip_ap | ( | double | rp, |
double | rs, | ||
int | ord, | ||
double * | b, | ||
double * | a | ||
) |
Function calculates the transfer function \( H(s) \) coefficients of analog normalized lowpass elliptic filter order ord
with passband ripple rp
dB and stopband suppression equals rs
dB.
- Parameters
-
[in] rp Magnitude ripple in passband (dB).
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency.
Parameter must be positive.
[in] rs Suppression level in stopband (dB).
This parameter sets filter supression for \(\omega \geq 1\) rad/s frequency.
Parameter must be positive.
[in] ord Filter order.
Filter coefficients number equalsord+1
for numerator and denominator of transfer function \( H(s) \)
[out] b Pointer to the vector of transfer function \(H(s)\) numerator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
[out] a Pointer to the vector of transfer function \(H(s)\) denominator coefficient.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if filter coefficients is calculated successfully.
Else code error.
Example:
Result:
b[ 0] = 0.268 a[ 0] = 0.301 b[ 1] = 0.000 a[ 1] = 0.764 b[ 2] = 0.045 a[ 2] = 1.472 b[ 3] = 0.000 a[ 3] = 0.948 b[ 4] = 0.001 a[ 4] = 1.000
In dat
folder will be created 3 files:
ellip_ap_test_mag.txt magnitude ellip_ap_test_phi.txt phase response ellip_ap_test_tau.txt group delay
In addition, GNUPLOT will build the following graphs from data stored in files:

Definition at line 1532 of file filter_ap.c.
◆ ellip_ap_zp()
Function calculates arrays of zeros and poles for analog normlized lowpass elliptic filter transfer function \( H(s) \) order ord
.
- Parameters
-
[in] ord Filter order.
Number of zeros and poles of filter can be less or equalord
.
[in] rp Magnitude ripple in passband (dB).
This parameter sets maximum filter distortion from 0 to 1 rad/s frequency.
Parameter must be positive.
[in] rs Suppression level in stopband (dB).
This parameter sets filter suppression for \(\omega \geq 1\) rad/s frequency.
Parameter must be positive.
[out] z Pointer to the \( H(s) \) zeros array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] nz Pointer to the variable which keep number of finite zeros \( H(s) \).
Number of finite zeros which was calculated and saved in vectorz
.
Pointer cannot beNULL
.
[out] p Pointer to the \( H(s) \) poles array.
Maximum vector size is[ord x 1]
.
Memory must be allocated for maximum vector size.
[out] np Pointer to the variable which keep number of calculated poles of \( H(s) \).
Pointer cannot beNULL
.
- Returns
RES_OK
if zeros and poles is calculated successfully.
Else code error.
Example of normalized elliptic lowpass filter zeros and poles calculation:#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dspl.h"/* Filter order */#define ORD 7int main(int argc, char* argv[]){void* hdspl; /* DSPL handle */void* hplot; /* GNUPLOT handle *//* Load DSPL functions */hdspl = dspl_load();complex_t z[ORD+1]; /* H(s) zeros vector */complex_t p[ORD+1]; /* H(s) poles vector */double Rp = 1.0; /* Magnitude ripple from 0 to 1 rad/s */double Rs = 40; /* Stopband suppression, dB */int res, k, nz, np;/* Zeros and poles vectors calculation */res = ellip_ap_zp(ORD, Rp, Rs, z, &nz, p, &np);if(res != RES_OK)printf("error code = 0x%8x\n", res);/* print H(s) zeros values */printf("Elliptic filter zeros: %d\n", nz);for(k = 0; k < nz; k++)/* print H(s) poles values */printf("Elliptic filter poles: %d\n", np);for(k = 0; k < np; k++)/* Write complex poles to the file */writetxt_cmplx(z, nz, "dat/ellip_ap_z.txt");writetxt_cmplx(p, np, "dat/ellip_ap_p.txt");/* plotting by GNUPLOT */gnuplot_create(argc, argv, 440, 360, "img/ellip_ap_zp_test.png", &hplot);gnuplot_cmd(hplot, "unset key");gnuplot_cmd(hplot, "set xzeroaxis");gnuplot_cmd(hplot, "set yzeroaxis");gnuplot_cmd(hplot, "set xlabel 'sigma'");gnuplot_cmd(hplot, "set ylabel 'jw'");gnuplot_cmd(hplot, "set size square");gnuplot_cmd(hplot, "set xrange [-2:2]");gnuplot_cmd(hplot, "set yrange [-2:2]");gnuplot_cmd(hplot, "plot 'dat/ellip_ap_p.txt' with points pt 2, \\");gnuplot_cmd(hplot, " 'dat/ellip_ap_z.txt' with points pt 6");gnuplot_close(hplot);/* free dspl handle */dspl_free(hdspl);return res;}
Result:
Elliptic filter zeros: 6 z[ 0] = 0.000 +1.053 j z[ 1] = 0.000 -1.053 j z[ 2] = 0.000 +1.136 j z[ 3] = 0.000 -1.136 j z[ 4] = 0.000 +1.626 j z[ 5] = 0.000 -1.626 j Elliptic filter poles: 7 p[ 0] = -0.358 +0.000 j p[ 1] = -0.011 +1.000 j p[ 2] = -0.011 -1.000 j p[ 3] = -0.060 +0.940 j p[ 4] = -0.060 -0.940 j p[ 5] = -0.206 +0.689 j p[ 6] = -0.206 -0.689 j
In dat
folder will be created ellip_ap_z.txt
and ellip_ap_z.txt
files which keeps zeros and poles vectors.
In addition, GNUPLOT will build the following graphs from data stored in the files:

Definition at line 1780 of file filter_ap.c.
Referenced by ellip_ap().
◆ iir()
int iir | ( | double | rp, |
double | rs, | ||
int | ord, | ||
double | w0, | ||
double | w1, | ||
int | type, | ||
double * | b, | ||
double * | a | ||
) |
Digital IIR filter design.
The function calculates the coefficients of the digital IIR filter transfer fucntion \( H(z) \). Filter coeffitients can be used in filter_iir function
- Parameters
-
[in] rp Magnitude ripple in passband (dB).
[in] rs Suppression level in stopband (dB).
[in] ord Filter order.
Number of \(H(z)\) numerator and denominator coefficients isord+1
.
For bandpass and bandstop filtersord
must be even.
[in] w0 Normalized cutoff frequency (from 0 to 1) for lowpass or highpass filter.
Or left normalized cutoff frequency (from 0 to 1) for bandpass and bandstop filter.
[in] w1 Right normalized cutoff frequency (from 0 to 1) for bandpass and bandstop filter.
This parameter is ingnored for lowpass and highpass filters.
[in] type Filter type.
This patameter sets combination of filter type (one of follow):
DSPL_FILTER_LPF - lowpass filter; DSPL_FILTER_HPF - highpass filter; DSPL_FILTER_BPASS - bandpass filter; DSPL_FILTER_BSTOP - bandstop filter,
and of filter approximation type (one of follow):DSPL_FILTER_BUTTER - Butterworth filter; DSPL_FILTER_CHEBY1 - Chebyshev of the first kind filter; DSPL_FILTER_CHEBY2 - Chebyshev of the second kind filter; DSPL_FILTER_ELLIP - Elliptic filter.
[out] b Pointer to the transfer function \(H(z)\) numerator coefficients vector.
Vector size isord+1
.
Memory must be allocated.
[out] a Pointer to the transfer function \(H(z)\) denominator coefficients vector.
Vector size isord+1
.
- Returns
RES_OK
if filter is calculated successfully.
Else code error.
Example:
This program calcultes filter coefficients for different flags type
.
In addition, the filters magnitudes is calculated and plotted by GNUPLOT package.

Definition at line 404 of file filter_iir.c.
◆ low2high()
int low2high | ( | double * | b, |
double * | a, | ||
int | ord, | ||
double | w0, | ||
double | w1, | ||
double * | beta, | ||
double * | alpha | ||
) |
Lowpass to highpass filter frequency transform.
Function transforms lowpass filter transfer function \( H(s) \) to the highpass filter transfer function \( F(s) \).
Filter order, magnitude ripple in passband and stopband supression still the same.
- Parameters
-
[in] b Pointer to the lowpass filter transfer function \(H(s)\) numerator coefficients vector.
Vector size is[ord+1 x 1]
.
[in] a Pointer to the lowpass filter transfer function \(H(s)\) denominator coefficients vector.
Vector size is[ord+1 x 1]
.
[in] ord Filter order.
[in] w0 Lowpass filter cutoff frequency.
[in] w1 Highpass filter cutoff frequency after transformation.
[in,out] beta Pointer to the highwpass filter transfer function \(F(s)\) numerator coefficients vector after transformation.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
[in,out] alpha Pointer to the highwpass filter transfer function \(F(s)\) denominator coefficients vector after transformation.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if filter coefficients is calculated successfully.
Else code error.
Definition at line 280 of file filter_ft.c.
Referenced by iir().
◆ low2low()
int low2low | ( | double * | b, |
double * | a, | ||
int | ord, | ||
double | w0, | ||
double | w1, | ||
double * | beta, | ||
double * | alpha | ||
) |
Lowpass to lowpass filter frequency transform
Function transforms lowpass filter transfer function \( H(s) \) to the lowpass filter transfer function \( F(s) \) with other cutoff frequency.
Filter order, magnitude ripple in passband and stopband supression still the same.
- Parameters
-
[in] b Pointer to the input lowpass filter transfer function \(H(s)\) numerator coefficients vector.
Vector size is[ord+1 x 1]
.
[in] a Pointer to the input lowpass filter transfer function \(H(s)\) denominator coefficients vector.
Vector size is[ord+1 x 1]
.
[in] ord Filter order.
[in] w0 Input lowpass filter cutoff frequency.
[in] w1 Lowpass filter cutoff frequency after transformation.
[in,out] beta Pointer to the lowpass filter transfer function \(F(s)\) numerator coefficients vector after transformation.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
[in,out] alpha Pointer to the lowpass filter transfer function \(F(s)\) denominator coefficients vector after transformation.
Vector size is[ord+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if filter coefficients is calculated successfully.
Else code error.
Definition at line 426 of file filter_ft.c.
Referenced by iir().
◆ ratcompos()
int ratcompos | ( | double * | b, |
double * | a, | ||
int | n, | ||
double * | c, | ||
double * | d, | ||
int | p, | ||
double * | beta, | ||
double * | alpha | ||
) |
Rational composition.
Function calcultes composition \(Y(s) = (H \circ F)(s) = H(F(s))\), here
\[ H(s) = \frac{\sum\limits_{m = 0}^{n} b_m s^m} {\sum\limits_{k = 0}^{n} a_k s^k}, \quad F(s) = \frac{\sum\limits_{m = 0}^{p} d_m s^m} {\sum\limits_{k = 0}^{p} c_k s^k}, \quad Y(s) = \frac{\sum\limits_{m = 0}^{n p} \beta_m s^m} {\sum\limits_{k = 0}^{n p} \alpha_k s^k} \]
This function is using for filter frequency transform.
- Parameters
-
[in] b Pointer to the \(H(s)\) polynomial function numerator coefficients vector.
Vector size is[n+1 x 1]
.
[in] a Pointer to the \(H(s)\) polynomial function denominator coefficients vector.
Vector size is[n+1 x 1]
.
[in] n Order of \(H(s)\) numerator and denominator polynomials.
[in] c Pointer to the \(F(s)\) polynomial function numerator coefficients vector.
Vector size is[p+1 x 1]
.
[in] d Pointer to the \(F(s)\) polynomial function denominator coefficients vector.
Vector size is[p+1 x 1]
.
[in] p Order of \(F(s)\) numerator and denominator polynomials.
[in,out] beta Pointer to the numerator coefficients vector of \(Y(s) = (H \circ F)(s)\).
Vector size is[n*p+1 x 1]
.
Memory must be allocated.
[in,out] alpha Pointer to the denominator coefficients vector of \(Y(s) = (H \circ F)(s)\).
Vector size is[n*p+1 x 1]
.
Memory must be allocated.
- Returns
RES_OK
if rational composition is calculated successfully.
Else code error.
Definition at line 602 of file filter_ft.c.
Referenced by bilinear(), low2high(), and low2low().
Generated on Mon Dec 14 2020 14:02:36 for libdspl-2.0 by
