libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
ellip_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 #ifdef DOXYGEN_ENGLISH
29 
117 #endif
118 #ifdef DOXYGEN_RUSSIAN
119 
212 #endif
213 int DSPL_API ellip_ap_zp(int ord, double rp, double rs,
214  complex_t* z, int* nz, complex_t* p, int* np)
215 {
216  double es, ep;
217  int L, r, n, res;
218  int iz, ip;
219  double ke, k, u, t;
220  complex_t tc, v0, jv0;
221 
222 
223  if(rp < 0 || rp == 0)
224  return ERROR_FILTER_RP;
225  if(rs < 0 || rs == 0)
226  return ERROR_FILTER_RS;
227  if(ord < 1)
228  return ERROR_FILTER_ORD;
229  if(!z || !p || !nz || !np)
230  return ERROR_PTR;
231 
232  es = sqrt(pow(10.0, rs*0.1) - 1.0);
233  ep = sqrt(pow(10.0, rp*0.1) - 1.0);
234  ke = ep / es;
235 
236  r = ord % 2;
237  L = (int)((ord-r)/2);
238 
239  res = ellip_modulareq(rp, rs, ord, &k);
240  if(res != RES_OK)
241  return res;
242  // v0
243  RE(tc) = 0.0;
244  IM(tc) = 1.0 / ep;
245 
246  ellip_asn_cmplx(&tc, 1, ke, &v0);
247 
248  t = RE(v0);
249  RE(v0) = IM(v0) / (double)ord;
250  IM(v0) = -t / (double)ord;
251 
252  RE(jv0) = -IM(v0);
253  IM(jv0) = RE(v0);
254 
255  iz = ip = 0;
256 
257  if(r)
258  {
259  res = ellip_sn_cmplx(&jv0, 1, k, &tc);
260  if(res != RES_OK)
261  return res;
262  RE(p[0]) = -IM(tc);
263  IM(p[0]) = RE(tc);
264  ip = 1;
265  }
266 
267  for(n = 0; n < L; n++)
268  {
269  u = (double)(2 * n + 1)/(double)ord;
270 
271  res = ellip_cd(& u, 1, k, &t);
272  if(res != RES_OK)
273  return res;
274 
275  RE(z[iz]) = RE(z[iz+1]) = 0.0;
276  IM(z[iz]) = 1.0/(k*t);
277  IM(z[iz+1]) = -1.0/(k*t);
278  iz+=2;
279 
280  RE(tc) = u - RE(jv0);
281  IM(tc) = - IM(jv0);
282 
283  res = ellip_cd_cmplx(&tc, 1, k, p+ip+1);
284  if(res != RES_OK)
285  return res;
286 
287  RE(p[ip]) = -IM(p[ip+1]);
288  IM(p[ip]) = RE(p[ip+1]);
289 
290  RE(p[ip+1]) = RE(p[ip]);
291  IM(p[ip+1]) = -IM(p[ip]);
292 
293  ip+=2;
294  }
295  *nz = iz;
296  *np = ip;
297 
298  return RES_OK;
299 }
300 
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
int ellip_cd(double *u, int n, double k, double *y)
Эллиптическая функция Якоби вещественного аргумента
Definition: ellip_cd.c:125
#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_RP
Параметр неравномерности фильтра в полосе пропускания задан неверно. Данный параметр задается в дБ и ...
Definition: dspl.h:577
#define ERROR_FILTER_RS
Параметр подавления фильтра в полосе заграждения задан неверно. Данный параметр задается в дБ и долже...
Definition: dspl.h:578
int ellip_sn_cmplx(complex_t *u, int n, double k, complex_t *y)
Эллиптическая функция Якоби комплексного аргумента
int ellip_asn_cmplx(complex_t *w, int n, double k, complex_t *u)
Обратная эллиптическая функция Якоби комплексного аргумента
double complex_t[2]
Описание комплексного типа данных.
Definition: dspl.h:86
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558
int ellip_cd_cmplx(complex_t *u, int n, double k, complex_t *y)
Эллиптическая функция Якоби комплексного аргумента
#define IM(x)
Макрос определяющий мнимую часть комплексного числа.
Definition: dspl.h:478