libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
farrow_spline.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 
22 
23 #include <stdlib.h>
24 #include <string.h>
25 #include <math.h>
26 #include "dspl.h"
27 
28 
29 
30 
31 #ifdef DOXYGEN_ENGLISH
32 
33 #endif
34 #ifdef DOXYGEN_RUSSIAN
35 
83 #endif
84 int DSPL_API farrow_spline(double *s, int n, double p, double q,
85  double frd, double **y, int *ny)
86 {
87  double a[4];
88  double t, x, dt;
89  int ind, k, res;
90  double g[4];
91  double *z;
92 
93  if(!s || !y)
94  return ERROR_PTR;
95 
96  if(n<1)
97  return ERROR_SIZE;
98 
99  if(p <= 0.0 || q <= 0.0)
100  return ERROR_RESAMPLE_RATIO;
101 
102  if(frd <= -1.0 || frd >= 1.0)
104 
105  dt = q/p;
106 
107  if((*ny) != (int)((double)(n-1)/dt)+1 || !(*y))
108  {
109 
110  *ny = (int)((double)(n-1)/dt)+1;
111  (*y) = (double*)realloc((*y), (*ny)*sizeof(double));
112  }
113 
114  t = -frd;
115  k = 0;
116  while(k < (*ny))
117  {
118  ind = (int)floor(t)+1;
119  x = t - (double)ind;
120  ind-=2;
121  if(ind < 0)
122  {
123  memset(g, 0, 4*sizeof(double));
124  if(ind > (-3))
125  memcpy(g-ind, s, (4+ind)*sizeof(double));
126  z = g;
127  }
128  else
129  {
130  if(ind < n-3)
131  z = s+ind;
132  else
133  {
134  memset(g, 0, 4*sizeof(double));
135  if((n-ind)>0)
136  memcpy(g, s+ind, (n-ind)*sizeof(double));
137  z = g;
138  }
139  }
140  a[0] = z[2];
141  a[1] = 0.5*(z[3] - z[1]);
142  a[3] = 2.0*(z[1] - z[2]) + a[1] + 0.5*(z[2] - z[0]);
143  a[2] = z[1] - z[2] +a[3] + a[1];
144 
145  res = polyval(a, 3, &x, 1, (*y)+k);
146 
147  if(res != RES_OK)
148  goto exit_label;
149  t+=dt;
150  k++;
151  }
152 
153 exit_label:
154  return res;
155 }
156 
int polyval(double *a, int ord, double *x, int n, double *y)
Расчет вещественного полинома
Definition: polyval.c:77
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
#define ERROR_SIZE
Ошибка при передаче размера массива. Данная ошибка возникает когда помимо указателя на массив входных...
Definition: dspl.h:618
#define ERROR_RESAMPLE_FRAC_DELAY
Неверное значение дробной задержки. Дробная задержка может принимать значения от -1 до 1,...
Definition: dspl.h:616
#define ERROR_RESAMPLE_RATIO
Коэффициент передискретизации задан неверно. Коэффициент передискретизации задается отношением ,...
Definition: dspl.h:615
int farrow_spline(double *s, int n, double p, double q, double frd, double **y, int *ny)
Передискретизация вещественного сигнала на основе сплайн интерполяции.
Definition: farrow_spline.c:84
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558