libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
ellip_ap.c
1 /*
2 * Copyright (c) 2015-2024 Sergey Bakhurin
3 * Digital Signal Processing Library [http://dsplib.org]
4 *
5 * This file is part of libdspl-2.0.
6 *
7 * is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * DSPL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "dspl.h"
25 
26 
27 
28 
29 #ifdef DOXYGEN_ENGLISH
30 
105 #endif
106 #ifdef DOXYGEN_RUSSIAN
107 
190 #endif
191 int DSPL_API ellip_ap(double rp, double rs, int ord, double* b, double* a)
192 {
193  int res;
194  complex_t *z = NULL;
195  complex_t *p = NULL;
196  int nz, np;
197  double norm, g0;
198 
199 
200  if(rp < 0.0)
201  return ERROR_FILTER_RP;
202  if(rs < 0.0)
203  return ERROR_FILTER_RS;
204  if(ord < 1)
205  return ERROR_FILTER_ORD;
206  if(!a || !b)
207  return ERROR_PTR;
208 
209  z = (complex_t*) malloc(ord*sizeof(complex_t));
210  p = (complex_t*) malloc(ord*sizeof(complex_t));
211 
212 
213  res = ellip_ap_zp(ord, rp, rs, z, &nz, p, &np);
214  if(res != RES_OK)
215  goto exit_label;
216 
217  res = filter_zp2ab(z, nz, p, np, ord, b, a);
218  if(res != RES_OK)
219  goto exit_label;
220 
221 
222  g0 = 1.0;
223  if(!(ord % 2))
224  {
225  g0 = 1.0 / pow(10.0, rp*0.05);
226  }
227 
228 
229  norm = g0 * a[0] / b[0];
230 
231  for(nz = 0; nz < ord+1; nz++)
232  b[nz]*=norm;
233 
234  exit_label:
235  if(z)
236  free(z);
237  if(p)
238  free(p);
239  return res;
240 }
241 
242 
int ellip_ap_zp(int ord, double rp, double rs, complex_t *z, int *nz, complex_t *p, int *np)
Расчет массивов нулей и полюсов передаточной функции аналогового нормированного эллиптического ФНЧ.
Definition: ellip_ap_zp.c:213
#define ERROR_FILTER_ORD
Порядок фильтра задан неверно. Порядок фильтра должен быть задан положительным целым значением.
Definition: dspl.h:575
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
#define ERROR_FILTER_RP
Параметр неравномерности фильтра в полосе пропускания задан неверно. Данный параметр задается в дБ и ...
Definition: dspl.h:577
#define ERROR_FILTER_RS
Параметр подавления фильтра в полосе заграждения задан неверно. Данный параметр задается в дБ и долже...
Definition: dspl.h:578
int filter_zp2ab(complex_t *z, int nz, complex_t *p, int np, int ord, double *b, double *a)
Функция пересчета нулей и полюсов аналогового фильтра в коэффициенты передаточной характеристики .
Definition: filter_zp2ab.c:166
double complex_t[2]
Описание комплексного типа данных.
Definition: dspl.h:86
int ellip_ap(double rp, double rs, int ord, double *b, double *a)
Расчет передаточной характеристики аналогового нормированного эллиптического ФНЧ.
Definition: ellip_ap.c:191
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558