libdspl-2.0/examples/src/cheby1_ap_zp_test.c

60 wiersze
1.7 KiB
C
Czysty Zwykły widok Historia

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/* Filter order */
#define ORD 7
int main(int argc, char* argv[])
{
Examples style changed Changes to be committed: modified: examples/src/array_test.c modified: examples/src/bessel_i0.c modified: examples/src/bilinear_test.c modified: examples/src/butter_ap_test.c modified: examples/src/butter_ap_zp_test.c modified: examples/src/cheby1_ap_test.c modified: examples/src/cheby1_ap_zp_test.c modified: examples/src/cheby2_ap_test.c modified: examples/src/cheby2_ap_zp_test.c modified: examples/src/cheby_poly1_test.c modified: examples/src/cheby_poly2_test.c modified: examples/src/complex_test.c modified: examples/src/conv_fft_cmplx_test.c modified: examples/src/conv_fft_test.c modified: examples/src/conv_test.c modified: examples/src/dft_cmplx_test.c modified: examples/src/dft_test.c modified: examples/src/dspl_info_test.c modified: examples/src/ellip_ap_test.c modified: examples/src/ellip_ap_zp_test.c modified: examples/src/ellip_landen_test.c modified: examples/src/fft_cmplx_test.c modified: examples/src/fft_test.c modified: examples/src/filter_iir_test.c modified: examples/src/fir_linphase_test.c modified: examples/src/gnuplot_script_test.c modified: examples/src/idft_cmplx_test.c modified: examples/src/ifft_cmplx_test.c modified: examples/src/iir_bstop.c modified: examples/src/iir_lpf.c modified: examples/src/iir_test.c modified: examples/src/matrix_eig.c modified: examples/src/matrix_mul.c modified: examples/src/matrix_print.c modified: examples/src/matrix_transpose.c modified: examples/src/polyroots_test.c modified: examples/src/randb_test.c modified: examples/src/randi_test.c modified: examples/src/randn_test.c modified: examples/src/randu_accuracy_test.c modified: examples/src/randu_test.c modified: examples/src/sinc_test.c modified: examples/src/sine_int_test.c modified: examples/src/writetxt_3d_test.c
2020-07-18 06:34:52 +00:00
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;
}