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

93 wiersze
2.1 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 <stdlib.h>
#include <string.h>
#include <math.h>
#include "dspl.h"
#ifdef DOXYGEN_ENGLISH
#endif
#ifdef DOXYGEN_RUSSIAN
#endif
int DSPL_API freqs2time(double* b, double* a, int ord, double fs,
int n, fft_t* pfft, double *t, double *h)
{
double *w = NULL;
complex_t *hs = NULL;
complex_t *ht = NULL;
int err, k;
if(!b || !a || !t || !h)
return ERROR_PTR;
if(ord<1)
return ERROR_FILTER_ORD;
if(n<1)
return ERROR_SIZE;
w = (double*)malloc(n*sizeof(double));
hs = (complex_t*)malloc(n*sizeof(complex_t));
err = linspace(-fs*0.5, fs*0.5, n, DSPL_PERIODIC, w);
if(err != RES_OK)
goto exit_label;
err = freqs(b, a, ord, w, n, hs);
if(err != RES_OK)
goto exit_label;
err = fft_shift_cmplx(hs, n, hs);
if(err != RES_OK)
goto exit_label;
ht = (complex_t*)malloc(n*sizeof(complex_t));
err = ifft_cmplx(hs, n, pfft, ht);
if(err != RES_OK)
{
err = idft_cmplx(hs, n, ht);
if(err != RES_OK)
goto exit_label;
}
for(k = 0; k < n; k++)
{
t[k] = (double)k/fs;
h[k] = RE(ht[k]) * fs;
}
exit_label:
if(w)
free(w);
if(hs)
free(hs);
if(ht)
free(ht);
return err;
}