libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
cheby2_ap_zp.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 
30 #ifdef DOXYGEN_ENGLISH
31 
120 #endif
121 #ifdef DOXYGEN_RUSSIAN
122 
215 #endif
216 int DSPL_API cheby2_ap_zp(int ord, double rs, complex_t* z, int* nz,
217  complex_t *p, int* np)
218 {
219  double es;
220  int L, r, k;
221  double beta;
222  int iz, ip;
223 
224  double alpha;
225  double chb, shb, sa, ca;
226  double ssh2, cch2;
227 
228  if(rs < 0 || rs == 0)
229  return ERROR_FILTER_RS;
230  if(ord < 1)
231  return ERROR_FILTER_ORD;
232  if(!z || !p || !nz || !np)
233  return ERROR_PTR;
234 
235  es = sqrt(pow(10.0, rs*0.1) - 1.0);
236  r = ord % 2;
237  L = (int)((ord-r)/2);
238 
239  beta = asinh(es)/(double)ord;
240 
241  chb = cosh(beta);
242  shb = sinh(beta);
243 
244  iz = ip = 0;
245 
246  if(r)
247  {
248  RE(p[0]) = -1.0 / sinh(beta);
249  IM(p[0]) = 0.0;
250  ip = 1;
251  }
252 
253  for(k = 0; k < L; k++)
254  {
255  alpha = M_PI*(double)(2*k + 1)/(double)(2*ord);
256  sa = sin(alpha);
257  ca = cos(alpha);
258  ssh2 = sa*shb;
259  ssh2 *= ssh2;
260 
261  cch2 = ca*chb;
262  cch2 *= cch2;
263 
264  RE(z[iz]) = RE(z[iz+1]) = 0.0;
265  IM(z[iz]) = 1.0 / ca;
266  IM(z[iz+1]) = -IM(z[iz]);
267  iz+=2;
268 
269  RE(p[ip]) = RE(p[ip+1]) = -sa*shb / (ssh2 + cch2);
270  IM(p[ip]) = ca*chb / (ssh2 + cch2);
271  IM(p[ip+1]) = -IM(p[ip]);
272  ip+=2;
273  }
274  *nz = iz;
275  *np = ip;
276 
277  return RES_OK;
278 }
279 
#define ERROR_FILTER_ORD
Порядок фильтра задан неверно. Порядок фильтра должен быть задан положительным целым значением.
Definition: dspl.h:575
#define RE(x)
Макрос определяющий реальную часть комплексного числа.
Definition: dspl.h:420
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
#define ERROR_FILTER_RS
Параметр подавления фильтра в полосе заграждения задан неверно. Данный параметр задается в дБ и долже...
Definition: dspl.h:578
double complex_t[2]
Описание комплексного типа данных.
Definition: dspl.h:86
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558
#define IM(x)
Макрос определяющий мнимую часть комплексного числа.
Definition: dspl.h:478
int cheby2_ap_zp(int ord, double rs, complex_t *z, int *nz, complex_t *p, int *np)
Расчет массивов нулей и полюсов передаточной функции аналогового нормированного ФНЧ Чебышёва второго...
Definition: cheby2_ap_zp.c:216