libdspl-2.0/examples/src/bilinear_test.c

69 wiersze
1.7 KiB
C
Czysty Zwykły widok Historia

2019-04-28 20:44:51 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
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
#define N 1000
#define ORD 4
2019-04-28 20:44:51 +00:00
2019-11-04 14:05:33 +00:00
int main(int argc, char* argv[])
2019-04-28 20:44:51 +00:00
{
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 */
double w[N], h[N];
complex_t hz[N];
double bs[ORD+1], as[ORD+1];
double bz[ORD+1], az[ORD+1];
int err, k;
hdspl = dspl_load(); /* Load DSPL function */
/* normalized analog lowpass filter Chebyshev type 1 */
err = cheby1_ap(1.0, ORD, bs, as);
if(err != RES_OK)
{
printf("cheby1_ap error code %d\n", err);
return err;
}
/* Bilinear transform */
err = bilinear(bs, as, ORD, bz, az);
if(err != RES_OK)
{
printf("bilinear error code %d\n", err);
return err;
}
/* Print coefficients */
for(k = 0; k < ORD+1; k++)
printf("bz[%d] = %7.3f az[%d] = %7.3f\n", k, bz[k], k, az[k]);
/* Digital filter magnitude */
linspace(0, M_PI, N, DSPL_PERIODIC, w);
freqz(bz, az, ORD, w, N, hz);
for(k = 0; k < N; k++)
{
h[k] = 10.0 * log10 (ABSSQR(hz[k])); /* Logarithmic scale */
w[k] /= M_PI; /* frequency from 0 to 1 */
}
writetxt(w,h,N,"dat/bilinear.txt");
/* plotting by GNUPLOT */
gnuplot_create(argc, argv, 560, 380, "img/bilinear.png", &hplot);
gnuplot_cmd(hplot, "set grid");
gnuplot_cmd(hplot, "unset key");
gnuplot_cmd(hplot, "set xlabel 'normalized frequency'");
gnuplot_cmd(hplot, "set ylabel 'Magnitude, dB'");
gnuplot_cmd(hplot, "set yrange [-80:5]");
gnuplot_cmd(hplot, "plot 'dat/bilinear.txt' with lines");
gnuplot_close(hplot);
/* free dspl handle */
dspl_free(hdspl);
2019-04-28 20:44:51 +00:00
return err;
}