libdspl-2.0/dspl/src/filter_design/filter_ws1.c

97 wiersze
2.5 KiB
C
Czysty Zwykły widok Historia

New project structure for filter design algorithms Changes to be committed: deleted: dspl/src/conv.c new file: dspl/src/convolution.c new file: dspl/src/convolution/conv.c new file: dspl/src/convolution/conv_cmplx.c new file: dspl/src/convolution/conv_fft.c new file: dspl/src/convolution/conv_fft_cmplx.c new file: dspl/src/convolution/filter_iir.c deleted: dspl/src/ellipj.c deleted: dspl/src/filter_an.c deleted: dspl/src/filter_ap.c new file: dspl/src/filter_design.c new file: dspl/src/filter_design/bilinear.c new file: dspl/src/filter_design/butter_ap.c new file: dspl/src/filter_design/butter_ap_zp.c new file: dspl/src/filter_design/cheby1_ap.c new file: dspl/src/filter_design/cheby1_ap_zp.c new file: dspl/src/filter_design/cheby2_ap.c new file: dspl/src/filter_design/cheby2_ap_wp1.c new file: dspl/src/filter_design/cheby2_ap_zp.c new file: dspl/src/filter_design/ellip_ap.c new file: dspl/src/filter_design/ellip_ap_zp.c new file: dspl/src/filter_design/filter_freq_resp.c new file: dspl/src/filter_design/filter_ws1.c new file: dspl/src/filter_design/filter_zp2ab.c renamed: dspl/src/filter_fir.c -> dspl/src/filter_design/fir_linphase.c new file: dspl/src/filter_design/fir_linphase_lpf.c new file: dspl/src/filter_design/freqs.c new file: dspl/src/filter_design/freqs2time.c new file: dspl/src/filter_design/freqs_cmplx.c new file: dspl/src/filter_design/freqz.c new file: dspl/src/filter_design/group_delay.c renamed: dspl/src/filter_iir.c -> dspl/src/filter_design/iir.c new file: dspl/src/filter_design/iir_ap.c new file: dspl/src/filter_design/low2bp.c new file: dspl/src/filter_design/low2bs.c new file: dspl/src/filter_design/low2high.c new file: dspl/src/filter_design/low2low.c new file: dspl/src/filter_design/phase_delay.c new file: dspl/src/filter_design/ratcompos.c deleted: dspl/src/filter_ft.c new file: dspl/src/math_ellipj.c new file: dspl/src/math_ellipj/ellip_acd.c new file: dspl/src/math_ellipj/ellip_acd_cmplx.c new file: dspl/src/math_ellipj/ellip_asn.c new file: dspl/src/math_ellipj/ellip_asn_cmplx.c new file: dspl/src/math_ellipj/ellip_cd.c new file: dspl/src/math_ellipj/ellip_cd_cmplx.c new file: dspl/src/math_ellipj/ellip_landen.c new file: dspl/src/math_ellipj/ellip_modulareq.c new file: dspl/src/math_ellipj/ellip_rat.c new file: dspl/src/math_ellipj/ellip_sn.c new file: dspl/src/math_ellipj/ellip_sn_cmplx.c new file: dspl/src/types.c renamed: dspl/src/complex.c -> dspl/src/types/cmplx2re.c new file: dspl/src/types/re2cmplx.c new file: dspl/src/unwrap.c
2021-12-29 13:31:00 +00:00
/*
Changes to be committed: modified: dspl/dox/doxyfile_ru modified: dspl/src/array/sum.c modified: dspl/src/filter_design/bilinear.c modified: dspl/src/filter_design/butter_ap.c modified: dspl/src/filter_design/butter_ap_zp.c modified: dspl/src/filter_design/cheby1_ap.c modified: dspl/src/filter_design/cheby1_ap_zp.c modified: dspl/src/filter_design/cheby2_ap.c modified: dspl/src/filter_design/cheby2_ap_wp1.c modified: dspl/src/filter_design/cheby2_ap_zp.c modified: dspl/src/filter_design/ellip_ap.c modified: dspl/src/filter_design/ellip_ap_zp.c modified: dspl/src/filter_design/filter_freq_resp.c modified: dspl/src/filter_design/filter_ws1.c modified: dspl/src/filter_design/filter_zp2ab.c modified: dspl/src/filter_design/fir_linphase.c modified: dspl/src/filter_design/freqs.c modified: dspl/src/filter_design/freqs2time.c modified: dspl/src/filter_design/freqs_cmplx.c modified: dspl/src/filter_design/freqz.c modified: dspl/src/filter_design/group_delay.c modified: dspl/src/filter_design/iir.c modified: dspl/src/filter_design/low2bp.c modified: dspl/src/filter_design/low2bs.c modified: dspl/src/filter_design/low2high.c modified: dspl/src/filter_design/low2low.c modified: dspl/src/filter_design/phase_delay.c modified: dspl/src/filter_design/ratcompos.c modified: dspl/src/filter_design/win.c modified: dspl/src/gnuplot/gnuplot_close.c modified: dspl/src/gnuplot/gnuplot_cmd.c modified: dspl/src/gnuplot/gnuplot_create.c modified: dspl/src/gnuplot/gnuplot_open.c modified: dspl/src/inout/dspl_info.c modified: dspl/src/inout/readbin.c modified: dspl/src/inout/verif_data_gen.c modified: dspl/src/inout/verif_str.c modified: dspl/src/inout/verif_str_cmplx.c modified: dspl/src/inout/writebin.c modified: dspl/src/inout/writetxt.c modified: dspl/src/inout/writetxt_3d.c modified: dspl/src/inout/writetxt_3dline.c modified: dspl/src/inout/writetxt_cmplx.c modified: dspl/src/inout/writetxt_cmplx_im.c modified: dspl/src/inout/writetxt_cmplx_re.c modified: dspl/src/inout/writetxt_int.c modified: dspl/src/math_ellipj/ellip_acd.c modified: dspl/src/math_ellipj/ellip_acd_cmplx.c modified: dspl/src/math_ellipj/ellip_asn.c modified: dspl/src/math_ellipj/ellip_asn_cmplx.c modified: dspl/src/math_ellipj/ellip_cd.c modified: dspl/src/math_ellipj/ellip_cd_cmplx.c modified: dspl/src/math_ellipj/ellip_landen.c modified: dspl/src/math_ellipj/ellip_modulareq.c modified: dspl/src/math_ellipj/ellip_rat.c modified: dspl/src/math_ellipj/ellip_sn.c modified: dspl/src/math_ellipj/ellip_sn_cmplx.c modified: dspl/src/math_matrix/matrix_eig_cmplx.c modified: dspl/src/math_matrix/matrix_eye.c modified: dspl/src/math_matrix/matrix_eye_cmplx.c modified: dspl/src/math_matrix/matrix_mul.c modified: dspl/src/math_matrix/matrix_pinv.c modified: dspl/src/math_matrix/matrix_print.c modified: dspl/src/math_matrix/matrix_print_cmplx.c modified: dspl/src/math_matrix/matrix_svd.c modified: dspl/src/math_matrix/matrix_transpose.c modified: dspl/src/math_matrix/matrix_transpose_cmplx.c modified: dspl/src/math_matrix/matrix_transpose_hermite.c modified: dspl/src/math_matrix/vector_dot.c modified: dspl/src/math_poly/cheby_poly1.c modified: dspl/src/math_poly/cheby_poly2.c modified: dspl/src/math_poly/polyroots.c modified: dspl/src/math_poly/polyval.c modified: dspl/src/math_poly/polyval_cmplx.c modified: dspl/src/math_stat/find_max_abs.c modified: dspl/src/math_stat/histogram.c modified: dspl/src/math_stat/histogram_norm.c modified: dspl/src/math_stat/mean.c modified: dspl/src/math_stat/mean_cmplx.c modified: dspl/src/math_stat/minmax.c modified: dspl/src/math_stat/stat_std.c modified: dspl/src/math_stat/stat_std_cmplx.c modified: dspl/src/math_stat/xcorr.c modified: dspl/src/math_std/acos_cmplx.c modified: dspl/src/math_std/asin_cmplx.c modified: dspl/src/math_std/bessel_i0.c modified: dspl/src/math_std/cos_cmplx.c modified: dspl/src/math_std/dmod.c modified: dspl/src/math_std/log_cmplx.c modified: dspl/src/math_std/sin_cmplx.c modified: dspl/src/math_std/sinc.c modified: dspl/src/math_std/sine_int.c modified: dspl/src/math_std/sqrt_cmplx.c modified: dspl/src/math_std/trapint.c modified: dspl/src/math_std/trapint_cmplx.c modified: dspl/src/math_std/unwrap.c modified: dspl/src/psd/psd_bartlett.c modified: dspl/src/psd/psd_bartlett_cmplx.c modified: dspl/src/psd/psd_periodogram.c modified: dspl/src/psd/psd_periodogram_cmplx.c modified: dspl/src/psd/psd_welch.c modified: dspl/src/psd/psd_welch_cmplx.c
2023-12-13 17:18:47 +00:00
* Copyright (c) 2015-2024 Sergey Bakhurin
New project structure for filter design algorithms Changes to be committed: deleted: dspl/src/conv.c new file: dspl/src/convolution.c new file: dspl/src/convolution/conv.c new file: dspl/src/convolution/conv_cmplx.c new file: dspl/src/convolution/conv_fft.c new file: dspl/src/convolution/conv_fft_cmplx.c new file: dspl/src/convolution/filter_iir.c deleted: dspl/src/ellipj.c deleted: dspl/src/filter_an.c deleted: dspl/src/filter_ap.c new file: dspl/src/filter_design.c new file: dspl/src/filter_design/bilinear.c new file: dspl/src/filter_design/butter_ap.c new file: dspl/src/filter_design/butter_ap_zp.c new file: dspl/src/filter_design/cheby1_ap.c new file: dspl/src/filter_design/cheby1_ap_zp.c new file: dspl/src/filter_design/cheby2_ap.c new file: dspl/src/filter_design/cheby2_ap_wp1.c new file: dspl/src/filter_design/cheby2_ap_zp.c new file: dspl/src/filter_design/ellip_ap.c new file: dspl/src/filter_design/ellip_ap_zp.c new file: dspl/src/filter_design/filter_freq_resp.c new file: dspl/src/filter_design/filter_ws1.c new file: dspl/src/filter_design/filter_zp2ab.c renamed: dspl/src/filter_fir.c -> dspl/src/filter_design/fir_linphase.c new file: dspl/src/filter_design/fir_linphase_lpf.c new file: dspl/src/filter_design/freqs.c new file: dspl/src/filter_design/freqs2time.c new file: dspl/src/filter_design/freqs_cmplx.c new file: dspl/src/filter_design/freqz.c new file: dspl/src/filter_design/group_delay.c renamed: dspl/src/filter_iir.c -> dspl/src/filter_design/iir.c new file: dspl/src/filter_design/iir_ap.c new file: dspl/src/filter_design/low2bp.c new file: dspl/src/filter_design/low2bs.c new file: dspl/src/filter_design/low2high.c new file: dspl/src/filter_design/low2low.c new file: dspl/src/filter_design/phase_delay.c new file: dspl/src/filter_design/ratcompos.c deleted: dspl/src/filter_ft.c new file: dspl/src/math_ellipj.c new file: dspl/src/math_ellipj/ellip_acd.c new file: dspl/src/math_ellipj/ellip_acd_cmplx.c new file: dspl/src/math_ellipj/ellip_asn.c new file: dspl/src/math_ellipj/ellip_asn_cmplx.c new file: dspl/src/math_ellipj/ellip_cd.c new file: dspl/src/math_ellipj/ellip_cd_cmplx.c new file: dspl/src/math_ellipj/ellip_landen.c new file: dspl/src/math_ellipj/ellip_modulareq.c new file: dspl/src/math_ellipj/ellip_rat.c new file: dspl/src/math_ellipj/ellip_sn.c new file: dspl/src/math_ellipj/ellip_sn_cmplx.c new file: dspl/src/types.c renamed: dspl/src/complex.c -> dspl/src/types/cmplx2re.c new file: dspl/src/types/re2cmplx.c new file: dspl/src/unwrap.c
2021-12-29 13:31:00 +00:00
* Digital Signal Processing Library [http://dsplib.org]
*
* This file is part of libdspl-2.0.
*
* is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DSPL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#ifdef DOXYGEN_ENGLISH
#endif
#ifdef DOXYGEN_RUSSIAN
#endif
double DSPL_API filter_ws1(int ord, double rp, double rs, int type)
{
double es2, ep2, gs2, x, ws;
if(ord<1 || rp < 0.0 || rs < 0.0)
return -1.0;
es2 = pow(10.0, rs*0.1) - 1.0;
ep2 = pow(10.0, rp*0.1) - 1.0;
gs2 = 1.0 / (1.0 + es2);
x = (1.0 - gs2) / (gs2 * ep2);
switch( type & DSPL_FILTER_APPROX_MASK)
{
case DSPL_FILTER_BUTTER:
ws = pow(x, 0.5 / (double)ord);
break;
case DSPL_FILTER_CHEBY1:
case DSPL_FILTER_CHEBY2:
x = sqrt(x) + sqrt(x - 1.0);
x = log(x) / (double)ord;
ws = 0.5 * (exp(-x) + exp(x));
break;
case DSPL_FILTER_ELLIP:
{
double k, k1;
complex_t y, z;
int res;
k = sqrt(ep2 / es2);
res = ellip_modulareq(rp, rs, ord, &k1);
if(res != RES_OK)
{
ws = -1.0;
break;
}
RE(z) = sqrt(x);
IM(z) = 0.0;
res = ellip_acd_cmplx(&z, 1, k, &y);
if(res != RES_OK)
{
ws = -1.0;
break;
}
RE(y) /= (double)ord;
IM(y) /= (double)ord;
res = ellip_cd_cmplx(&y, 1, k1, &z);
if(res != RES_OK)
{
ws = -1.0;
break;
}
ws = RE(z);
break;
}
default:
ws = -1.0;
break;
}
return ws;
}