20 #include <KLocalizedString> 30 #define ADD(i,n,s,d) append(i,n,_(s), _(d)) 40 ADD(
INTPOL_SAH, 6,
"sample_hold",I18N_NOOP(
"Sample and Hold"));
67 for (i = 0; i <
count; i++) {
89 if (!
count())
return 0.0;
91 unsigned int degree = 0;
94 if (input < 0.0) input = 0.0;
95 if (input > 1.0) input = 1.0;
101 while ((i < count) && (
m_x[i] < input))
104 double dif1 =
m_x[i] -
m_x[i-1];
105 double dif2 = input - m_x[i-1];
107 return (
m_y[i-1] + ((
m_y[i] -
m_y[i-1])*dif2 / dif1));
114 while ((j < count) && (
m_x[j] < input))
119 a = (m_x[j] - input) / diff;
120 b = (input - m_x[j-1]) / diff;
122 return (a*
m_y[j-1] + b*
m_y[j] + ((a*a*a - a)*
m_der[j - 1] +
123 (b*b*b - b)*
m_der[j])*(diff*diff) / 6);
128 for (
unsigned int j = 1; j <
count; j++)
129 ny = ny * (input -
m_x[j]) +
m_y[j];
135 while ((i < count) && (
m_x[i] < input))
150 if (degree && (degree <= 7)) {
156 QVector<double> ax(7);
157 QVector<double> ay(7);
160 while ((i < count) && (
m_x[i] < input))
166 for (
unsigned int j = 1; j < degree; j++)
167 ny = ny * (input - ax[j]) + ay[j];
178 if (!
count())
return false;
180 m_x = QVector<double>((
count() + 1),
double(0.0));
181 m_y = QVector<double>((
count() + 1),
double(0.0));
182 m_der = QVector<double>();
186 while (it.hasNext()) {
192 m_x[c] = m_y[c] = 0.0;
199 m_der = QVector<double>((
count() + 1),
double(0.0));
213 for (
unsigned int i = 0; i < len; i++) {
214 if (y[i] > 1) y[i] = 1;
215 if (y[i] < 0) y[i] = 0;
225 if (!len)
return QVector<double>();
227 unsigned int degree = 0;
228 QVector<double> y_out(len, 0.0);
240 while (it.hasNext()) {
242 const double x1 = p.x();
243 const double y1 = p.y();
245 double dy = (y1 - y0);
253 double h = dx ? ((double(i - min)) / dx) : 0.0;
254 y_out[i] = y0 + (h * dy);
265 unsigned int count = points.count();
268 QVector<double> der(count + 1);
269 QVector<double> x(count + 1);
270 QVector<double> y(count + 1);
273 while (it.hasNext()) {
284 for (
unsigned int j = 2; j <=
count; j++) {
286 for (
int i = start; i < ent; i++) {
287 const double xin =
static_cast<double>(i) / len;
288 const double h = x[j] - x[j - 1];
290 if (!qFuzzyIsNull(h)) {
291 const double a = (x[j] - xin) / h;
292 const double b = (xin - x[j - 1]) / h;
294 ny = (a * y[j - 1] + b * y[j] +
295 ((a * a * a - a) * der[j - 1] +
296 (b * b * b - b) * der[j]) * (h * h) / 6.0);
306 if (!degree) degree = 3;
309 if (!degree) degree = 5;
313 if (!degree) degree = 7;
314 const unsigned int count = points.count();
315 QVector<double> x(7);
316 QVector<double> y(7);
319 for (
unsigned int px = 0; px < count - 1; px++) {
321 const double start = points[px].x();
324 if (px >= count - degree / 2 + 1)
327 ent = points[px + 1].x();
333 for (
unsigned int j = 1; j < degree; j++)
334 ny = ny * ((static_cast<double>(i)) / len - x[j])
345 const int count = points.count();
347 QVector<double> x(count+1);
348 QVector<double> y(count+1);
352 for (
unsigned int i = 1; i < len; i++) {
353 const double px =
static_cast<double>(i) / len;
355 for (
int j = 1; j <
count; j++)
356 ny = ny * (px - x[j]) + y[j];
371 while (it.hasNext()) {
373 const double x1 = p.x();
374 const double y1 = p.y();
393 QVector<double> &x, QVector<double> &y)
395 Q_ASSERT(!points.isEmpty());
397 if (points.isEmpty())
return;
400 Q_ASSERT(points.count() ==
m_curve->count());
401 if (points.count() !=
m_curve->count())
return;
403 unsigned int count = 0;
405 while (it.hasNext()) {
412 for (
unsigned int k = 0; k <
count; k++)
413 for (
unsigned int j = k; j; ) {
415 y[j] = (y[j] - y[j+1]) / (x[j] - x[k]);
421 const QVector<double> &y, QVector<double> &ab,
unsigned int n)
427 QVector<double> u(n);
432 for (i = 2; i < n; ++i) {
433 const double sig = (x[i] - x[i-1]) / (x[i+1] - x[i-1]);
434 const double p = sig * ab[i-1] + 2;
436 u[i] = (y[i+1] - y[i]) / (x[i+1] - x[i])
437 - (y[i] - y[i-1]) / (x[i] - x[i-1]);
438 u[i] = (6 * u[i] / (x[i+1] - x[i-1]) - sig * u[i-1]) / p;
443 ab[n] = (un - qn * u[n - 1]) / (qn * ab[n - 1] + 1);
445 for (k = n - 1; k > 0; --k)
446 ab[k] = ab[k] * ab[k + 1] + u[k];
452 QVector<double> &x, QVector<double> &y,
453 int pos,
unsigned int degree)
455 unsigned int count = 0;
457 if (!it.hasNext())
return;
480 for (
int i = 0; i < pos; i++)
483 while ((count < degree) && it.hasNext()) {
492 while (count < degree) {
493 x[
count] = 1.0 + 0.5 * (i++);
498 for (
unsigned int k = 0; k < degree; k++)
499 for (
int j = k - 1; j >= 0; j--)
500 y[j] = (y[j] - y[j + 1]) / (x[j] - x[k]);
void get2Derivate(const QVector< double > &x, const QVector< double > &y, QVector< double > &ab, unsigned int n)
Kwave::interpolation_t type()
unsigned int count() const
Kwave::interpolation_t m_type
QString description(IDX type, bool localized) const
static QString name(Kwave::interpolation_t type)
static InterpolationMap m_interpolation_map
QVector< double > limitedInterpolation(const Kwave::Curve &points, unsigned int len)
const Kwave::Curve * m_curve
QListIterator< QPointF > ConstIterator
Interpolation(Kwave::interpolation_t type=INTPOL_LINEAR)
bool prepareInterpolation(const Kwave::Curve &points)
void createPolynom(const Kwave::Curve &points, QVector< double > &x, QVector< double > &y, int pos, unsigned int degree)
double singleInterpolation(double pos)
QVector< double > interpolation(const Kwave::Curve &points, unsigned int len)
virtual void fill() Q_DECL_OVERRIDE
QString name(IDX type) const
static QStringList descriptions(bool localized=false)
IDX findFromData(const DATA &data) const
void createFullPolynom(const Kwave::Curve &points, QVector< double > &x, QVector< double > &y)