libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
butter_ap.c
1 /*
2 * Copyright (c) 2015-2022 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 #ifdef DOXYGEN_ENGLISH
28 
97 #endif
98 #ifdef DOXYGEN_RUSSIAN
99 
171 #endif
172 int DSPL_API butter_ap(double rp, int ord, double* b, double* a)
173 {
174  int res;
175  complex_t *z = NULL;
176  complex_t *p = NULL;
177  int nz, np;
178 
179  if(rp < 0.0)
180  return ERROR_FILTER_RP;
181  if(ord < 1)
182  return ERROR_FILTER_ORD;
183  if(!a || !b)
184  return ERROR_PTR;
185 
186  z = (complex_t*) malloc(ord*sizeof(complex_t));
187  p = (complex_t*) malloc(ord*sizeof(complex_t));
188 
189 
190  res = butter_ap_zp(ord, rp, z, &nz, p, &np);
191  if(res != RES_OK)
192  goto exit_label;
193 
194  res = filter_zp2ab(z, nz, p, np, ord, b, a);
195  if(res != RES_OK)
196  goto exit_label;
197 
198  b[0] = a[0];
199 
200 
201 exit_label:
202  if(z)
203  free(z);
204  if(p)
205  free(p);
206  return res;
207 }
208 
int butter_ap_zp(int ord, double rp, complex_t *z, int *nz, complex_t *p, int *np)
Расчет массивов нулей и полюсов передаточной функции аналогового нормированного ФНЧ Баттерворта.
Definition: butter_ap_zp.c:207
#define ERROR_FILTER_ORD
Порядок фильтра задан неверно. Порядок фильтра должен быть задан положительным целым значением.
Definition: dspl.h:575
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
#define ERROR_FILTER_RP
Параметр неравномерности фильтра в полосе пропускания задан неверно. Данный параметр задается в дБ и ...
Definition: dspl.h:577
int filter_zp2ab(complex_t *z, int nz, complex_t *p, int np, int ord, double *b, double *a)
Функция пересчета нулей и полюсов аналогового фильтра в коэффициенты передаточной характеристики .
Definition: filter_zp2ab.c:166
int butter_ap(double rp, int ord, double *b, double *a)
Расчет передаточной характеристики аналогового нормированного ФНЧ Баттерворта.
Definition: butter_ap.c:172
double complex_t[2]
Описание комплексного типа данных.
Definition: dspl.h:86
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558