added example for cheby_zp and ellip_zp

pull/6/merge
Sergey Bakhurin 2020-07-15 23:04:21 +03:00
rodzic a557330fe6
commit d2dd42dea8
4 zmienionych plików z 171 dodań i 22 usunięć

Wyświetl plik

@ -28,7 +28,7 @@ int main(int argc, char* argv[])
/* print H(s) zeros values */
printf("Butterworth filter zeros: %d\n", nz);
for(k = 0; k < nz; k++)
printf("z[%2d] = %9.3f %+9.3f j\n", k, RE(z[k]), IM(p[k]));
printf("z[%2d] = %9.3f %+9.3f j\n", k, RE(z[k]), IM(z[k]));
/* print H(s) poles values */
printf("Butterworth filter poles: %d\n", np);

Wyświetl plik

@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/* Filter order */
#define ORD 7
int 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++)
printf("z[%2d] = %9.3f %+9.3f j\n", k, RE(z[k]), IM(z[k]));
/* print H(s) poles values */
printf("Chebyshev type 1 filter poles: %d\n", np);
for(k = 0; k < np; k++)
printf("p[%2d] = %9.3f %+9.3f j\n", k, RE(p[k]), IM(p[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;
}

Wyświetl plik

@ -1,32 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define ORD 7
/* Filter order */
#define ORD 7
int main()
int main(int argc, char* argv[])
{
void* handle; /* DSPL handle */
handle = dspl_load(); /* Load DSPL functions */
void* hdspl; /* DSPL handle */
void* hplot; /* GNUPLOT handle */
/* Load DSPL functions */
hdspl = dspl_load();
complex_t z[ORD], p[ORD];
int nz, np, k;
double Rs = 40.0;
int res = cheby2_ap_zp(ORD, Rs, z, &nz, p, &np);
if(res != RES_OK)
printf("error code = 0x%8x\n", res);
printf("\nChebyshev type 2 zeros:\n");
for(k = 0; k < nz; k++)
printf("z[%2d] = %9.3f %9.3f j\n", k, RE(z[k]), IM(z[k]));
complex_t z[ORD+1]; /* H(s) zeros vector */
complex_t p[ORD+1]; /* H(s) poles vector */
double Rs = 40; /* Stopband suppression, dB */
printf("\nChebyshev type 2 poles:\n");
for(k = 0; k < np; k++)
printf("p[%2d] = %9.3f %9.3f j\n", k, RE(p[k]), IM(p[k]));
int res, k, nz, np;
dspl_free(handle); /* free dspl handle */
return 0;
/* 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++)
printf("z[%2d] = %9.3f %+9.3f j\n", k, RE(z[k]), IM(z[k]));
/* print H(s) poles values */
printf("Chebyshev type 2 filter poles: %d\n", np);
for(k = 0; k < np; k++)
printf("p[%2d] = %9.3f %+9.3f j\n", k, RE(p[k]), IM(p[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;
}

Wyświetl plik

@ -0,0 +1,62 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/* Filter order */
#define ORD 7
int 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++)
printf("z[%2d] = %9.3f %+9.3f j\n", k, RE(z[k]), IM(z[k]));
/* print H(s) poles values */
printf("Elliptic filter poles: %d\n", np);
for(k = 0; k < np; k++)
printf("p[%2d] = %9.3f %+9.3f j\n", k, RE(p[k]), IM(p[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;
}