libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::FilterSavitzkyGolay Class Reference

uses Savitsky-Golay filter on trace More...

#include <savgolfilter.h>

Inheritance diagram for pappso::FilterSavitzkyGolay:
pappso::FilterNameInterface pappso::FilterInterface

Public Member Functions

 FilterSavitzkyGolay ()
 FilterSavitzkyGolay (int nL, int nR, int m, int lD, bool convolveWithNr=false)
 FilterSavitzkyGolay (const SavGolParams sav_gol_params)
 FilterSavitzkyGolay (const QString &parameters)
 FilterSavitzkyGolay (const FilterSavitzkyGolay &other)
virtual ~FilterSavitzkyGolay ()
FilterSavitzkyGolayoperator= (const FilterSavitzkyGolay &other)
Tracefilter (Trace &data_points) const override
SavGolParams getParameters () const
char runFilter (double *y_data_p, double *y_filtered_data_p, int data_point_count) const
 Perform the Savitzky-Golay filtering process.
void filteredData (std::vector< pappso_double > &data)
QString name () const override
QString toString () const override
 Return a string with the textual representation of the configuration data.
Public Member Functions inherited from pappso::FilterNameInterface
virtual ~FilterNameInterface ()
Public Member Functions inherited from pappso::FilterInterface
virtual ~FilterInterface ()

Protected Member Functions

void buildFilterFromString (const QString &strBuildParams) override
 build this filter using a string

Private Member Functions

int * ivector (long nl, long nh) const
pappso_doubledvector (long nl, long nh) const
pappso_double ** dmatrix (long nrl, long nrh, long ncl, long nch) const
void free_ivector (int *v, long nl, long nh) const
void free_dvector (pappso_double *v, long nl, long nh) const
void free_dmatrix (pappso_double **m, long nrl, long nrh, long ncl, long nch) const
void lubksb (pappso_double **a, int n, int *indx, pappso_double b[]) const
void ludcmp (pappso_double **a, int n, int *indx, pappso_double *d) const
void four1 (pappso_double data[], unsigned long nn, int isign)
void twofft (pappso_double data1[], pappso_double data2[], pappso_double fft1[], pappso_double fft2[], unsigned long n)
void realft (pappso_double data[], unsigned long n, int isign)
char convlv (pappso_double data[], unsigned long n, pappso_double respns[], unsigned long m, int isign, pappso_double ans[])
char sgcoeff (pappso_double c[], int np, int nl, int nr, int ld, int m) const

Private Attributes

SavGolParams m_params
pappso_doublem_x
 C array of keys of the Trace.
pappso_doublem_yr
 C array of raw values of the Trace.
pappso_doublem_yf
 C array of filtered values after the computation has been performed.

Detailed Description

uses Savitsky-Golay filter on trace

Definition at line 143 of file savgolfilter.h.

Constructor & Destructor Documentation

◆ FilterSavitzkyGolay() [1/5]

pappso::FilterSavitzkyGolay::FilterSavitzkyGolay ( )

Definition at line 54 of file savgolfilter.cpp.

55{
56 // m_params will have defaults that work well with mass spectra.
57}

Referenced by FilterSavitzkyGolay(), and operator=().

◆ FilterSavitzkyGolay() [2/5]

pappso::FilterSavitzkyGolay::FilterSavitzkyGolay ( int nL,
int nR,
int m,
int lD,
bool convolveWithNr = false )

Construct a FilterSavitzkyGolay instance using the Savitzky-Golay parameters

Parameters
nLnumber of data point left of the point being filtered
nRnumber of data point right of the point being filtered
morder of the polynomial to use in the regression analysis
lDorder of the derivative to extract
convolveWithNrset to false

Definition at line 59 of file savgolfilter.cpp.

60{
61 m_params.nL = nL;
62 m_params.nR = nR;
63 m_params.m = m;
64 m_params.lD = lD;
65 m_params.convolveWithNr = convolveWithNr;
66}

References m_params.

◆ FilterSavitzkyGolay() [3/5]

pappso::FilterSavitzkyGolay::FilterSavitzkyGolay ( const SavGolParams sav_gol_params)

Definition at line 69 of file savgolfilter.cpp.

70{
71 m_params.nL = sav_gol_params.nL;
72 m_params.nR = sav_gol_params.nR;
73 m_params.m = sav_gol_params.m;
74 m_params.lD = sav_gol_params.lD;
75 m_params.convolveWithNr = sav_gol_params.convolveWithNr;
76}

References pappso::SavGolParams::convolveWithNr, pappso::SavGolParams::lD, pappso::SavGolParams::m, m_params, pappso::SavGolParams::nL, and pappso::SavGolParams::nR.

◆ FilterSavitzkyGolay() [4/5]

pappso::FilterSavitzkyGolay::FilterSavitzkyGolay ( const QString & parameters)

Definition at line 79 of file savgolfilter.cpp.

80{
81 buildFilterFromString(parameters);
82}
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string

References buildFilterFromString().

◆ FilterSavitzkyGolay() [5/5]

pappso::FilterSavitzkyGolay::FilterSavitzkyGolay ( const FilterSavitzkyGolay & other)

Copy constructor

Parameters
otherTODO

Definition at line 85 of file savgolfilter.cpp.

86{
87 // This function only copies the parameters, not the data.
88
89 m_params.nL = other.m_params.nL;
90 m_params.nR = other.m_params.nR;
91 m_params.m = other.m_params.m;
92 m_params.lD = other.m_params.lD;
93 m_params.convolveWithNr = other.m_params.convolveWithNr;
94}

References FilterSavitzkyGolay(), pappso::SavGolParams::convolveWithNr, pappso::SavGolParams::lD, pappso::SavGolParams::m, m_params, pappso::SavGolParams::nL, and pappso::SavGolParams::nR.

◆ ~FilterSavitzkyGolay()

pappso::FilterSavitzkyGolay::~FilterSavitzkyGolay ( )
virtual

Destructor

Definition at line 97 of file savgolfilter.cpp.

98{
99}

Member Function Documentation

◆ buildFilterFromString()

void pappso::FilterSavitzkyGolay::buildFilterFromString ( const QString & strBuildParams)
overrideprotectedvirtual

build this filter using a string

Parameters
strBuildParamsa string coding the filter and its parameters "filterName|param1;param2;param3"

Implements pappso::FilterNameInterface.

Definition at line 120 of file savgolfilter.cpp.

121{
122 // Typical string: "Savitzky-Golay|15;15;4;0;false"
123 if(parameters.startsWith(QString("%1|").arg(name())))
124 {
125 QStringList params = parameters.split("|").back().split(";");
126
127 m_params.nL = params.at(0).toInt();
128 m_params.nR = params.at(1).toInt();
129 m_params.m = params.at(2).toInt();
130 m_params.lD = params.at(3).toInt();
131 m_params.convolveWithNr = (params.at(4) == "true" ? true : false);
132 }
133 else
134 {
135 throw pappso::ExceptionNotRecognized(
136 QString("Building of FilterSavitzkyGolay from string '%1' failed").arg(parameters));
137 }
138}
QString name() const override

References m_params, and name().

Referenced by FilterSavitzkyGolay(), and filteredData().

◆ convlv()

char pappso::FilterSavitzkyGolay::convlv ( pappso_double data[],
unsigned long n,
pappso_double respns[],
unsigned long m,
int isign,
pappso_double ans[] )
private

Definition at line 520 of file savgolfilter.cpp.

526{
527 unsigned long i, no2;
528 pappso_double dum, mag2, *fft;
529
530 fft = dvector(1, n << 1);
531 for(i = 1; i <= (m - 1) / 2; i++)
532 respns[n + 1 - i] = respns[m + 1 - i];
533 for(i = (m + 3) / 2; i <= n - (m - 1) / 2; i++)
534 respns[i] = 0.0;
535 twofft(data, respns, fft, ans, n);
536 no2 = n >> 1;
537 for(i = 2; i <= n + 2; i += 2)
538 {
539 if(isign == 1)
540 {
541 ans[i - 1] = (fft[i - 1] * (dum = ans[i - 1]) - fft[i] * ans[i]) / no2;
542 ans[i] = (fft[i] * dum + fft[i - 1] * ans[i]) / no2;
543 }
544 else if(isign == -1)
545 {
546 if((mag2 = ans[i - 1] * ans[i - 1] + ans[i] * ans[i]) == 0.0)
547 {
548 qDebug("Attempt of deconvolving at zero response in convlv().");
549 return (1);
550 }
551 ans[i - 1] = (fft[i - 1] * (dum = ans[i - 1]) + fft[i] * ans[i]) / mag2 / no2;
552 ans[i] = (fft[i] * dum - fft[i - 1] * ans[i]) / mag2 / no2;
553 }
554 else
555 {
556 qDebug("No meaning for isign in convlv().");
557 return (1);
558 }
559 }
560 ans[2] = ans[n + 1];
561 realft(ans, n, -1);
562 free_dvector(fft, 1, n << 1);
563 return (0);
564}
pappso_double * dvector(long nl, long nh) const
void free_dvector(pappso_double *v, long nl, long nh) const
void twofft(pappso_double data1[], pappso_double data2[], pappso_double fft1[], pappso_double fft2[], unsigned long n)
void realft(pappso_double data[], unsigned long n, int isign)
double pappso_double
A type definition for doubles.
Definition types.h:60

References dvector(), free_dvector(), realft(), and twofft().

Referenced by runFilter().

◆ dmatrix()

pappso_double ** pappso::FilterSavitzkyGolay::dmatrix ( long nrl,
long nrh,
long ncl,
long nch ) const
private

Definition at line 233 of file savgolfilter.cpp.

234{
235 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
236 pappso_double **m;
237 m = (pappso_double **)malloc((size_t)((nrow + 1) * sizeof(pappso_double *)));
238 if(!m)
239 {
240 qFatal("Error: Allocation failure.");
241 }
242 m += 1;
243 m -= nrl;
244 m[nrl] = (pappso_double *)malloc((size_t)((nrow * ncol + 1) * sizeof(pappso_double)));
245 if(!m[nrl])
246 {
247 qFatal("Error: Allocation failure.");
248 }
249 m[nrl] += 1;
250 m[nrl] -= ncl;
251 for(i = nrl + 1; i <= nrh; i++)
252 m[i] = m[i - 1] + ncol;
253 return m;
254}

Referenced by sgcoeff().

◆ dvector()

pappso_double * pappso::FilterSavitzkyGolay::dvector ( long nl,
long nh ) const
private

Definition at line 217 of file savgolfilter.cpp.

218{
219 pappso_double *v;
220 long k;
221 v = (pappso_double *)malloc((size_t)((nh - nl + 2) * sizeof(pappso_double)));
222 if(!v)
223 {
224 qFatal("Error: Allocation failure.");
225 }
226 for(k = nl; k <= nh; k++)
227 v[k] = 0.0;
228 return v - nl + 1;
229}

Referenced by convlv(), filter(), ludcmp(), runFilter(), and sgcoeff().

◆ filter()

Trace & pappso::FilterSavitzkyGolay::filter ( Trace & data_points) const
overridevirtual

Implements pappso::FilterInterface.

Definition at line 142 of file savgolfilter.cpp.

143{
144 // Initialize data:
145
146 // We want the filter to stay constant so we create a local copy of the data.
147
148 int data_point_count = data_points.size();
149
150 pappso_double *x_data_p = dvector(1, data_point_count);
151 pappso_double *y_initial_data_p = dvector(1, data_point_count);
152 pappso_double *y_filtered_data_p = nullptr;
153
154 if(m_params.convolveWithNr)
155 y_filtered_data_p = dvector(1, 2 * data_point_count);
156 else
157 y_filtered_data_p = dvector(1, data_point_count);
158
159 for(int iter = 0; iter < data_point_count; ++iter)
160 {
161 x_data_p[iter] = data_points.at(iter).x;
162 y_initial_data_p[iter] = data_points.at(iter).y;
163 }
164
165 // Now run the filter.
166
167 runFilter(y_initial_data_p, y_filtered_data_p, data_point_count);
168
169 // Put back the modified y values into the trace.
170 auto iter_yf = y_filtered_data_p;
171 for(auto &data_point : data_points)
172 {
173 data_point.y = *iter_yf;
174 iter_yf++;
175 }
176
177 return data_points;
178}
char runFilter(double *y_data_p, double *y_filtered_data_p, int data_point_count) const
Perform the Savitzky-Golay filtering process.

References dvector(), m_params, and runFilter().

◆ filteredData()

void pappso::FilterSavitzkyGolay::filteredData ( std::vector< pappso_double > & data)

◆ four1()

void pappso::FilterSavitzkyGolay::four1 ( pappso_double data[],
unsigned long nn,
int isign )
private

Definition at line 377 of file savgolfilter.cpp.

378{
379 unsigned long n, mmax, m, j, istep, i;
380 pappso_double wtemp, wr, wpr, wpi, wi, theta;
381 pappso_double tempr, tempi;
382
383 n = nn << 1;
384 j = 1;
385 for(i = 1; i < n; i += 2)
386 {
387 if(j > i)
388 {
389 SWAP(data[j], data[i]);
390 SWAP(data[j + 1], data[i + 1]);
391 }
392 m = n >> 1;
393 while(m >= 2 && j > m)
394 {
395 j -= m;
396 m >>= 1;
397 }
398 j += m;
399 }
400 mmax = 2;
401 while(n > mmax)
402 {
403 istep = mmax << 1;
404 theta = isign * (6.28318530717959 / mmax);
405 wtemp = sin(0.5 * theta);
406 wpr = -2.0 * wtemp * wtemp;
407 wpi = sin(theta);
408 wr = 1.0;
409 wi = 0.0;
410 for(m = 1; m < mmax; m += 2)
411 {
412 for(i = m; i <= n; i += istep)
413 {
414 j = i + mmax;
415 tempr = wr * data[j] - wi * data[j + 1];
416 tempi = wr * data[j + 1] + wi * data[j];
417 data[j] = data[i] - tempr;
418 data[j + 1] = data[i + 1] - tempi;
419 data[i] += tempr;
420 data[i + 1] += tempi;
421 }
422 wr = (wtemp = wr) * wpr - wi * wpi + wr;
423 wi = wi * wpr + wtemp * wpi + wi;
424 }
425 mmax = istep;
426 }
427}
#define SWAP(a, b)

References SWAP.

Referenced by realft(), and twofft().

◆ free_dmatrix()

void pappso::FilterSavitzkyGolay::free_dmatrix ( pappso_double ** m,
long nrl,
long nrh,
long ncl,
long nch ) const
private

Definition at line 272 of file savgolfilter.cpp.

274{
275 free((char *)(m[nrl] + ncl - 1));
276 free((char *)(m + nrl - 1));
277}

Referenced by sgcoeff().

◆ free_dvector()

void pappso::FilterSavitzkyGolay::free_dvector ( pappso_double * v,
long nl,
long nh ) const
private

Definition at line 265 of file savgolfilter.cpp.

266{
267 free((char *)(v + nl - 1));
268}

Referenced by convlv(), ludcmp(), runFilter(), and sgcoeff().

◆ free_ivector()

void pappso::FilterSavitzkyGolay::free_ivector ( int * v,
long nl,
long nh ) const
private

Definition at line 258 of file savgolfilter.cpp.

259{
260 free((char *)(v + nl - 1));
261}

Referenced by sgcoeff().

◆ getParameters()

SavGolParams pappso::FilterSavitzkyGolay::getParameters ( ) const

Definition at line 182 of file savgolfilter.cpp.

183{
184 return SavGolParams(m_params.nL, m_params.nR, m_params.m, m_params.lD, m_params.convolveWithNr);
185}

References m_params.

◆ ivector()

int * pappso::FilterSavitzkyGolay::ivector ( long nl,
long nh ) const
private

Definition at line 204 of file savgolfilter.cpp.

205{
206 int *v;
207 v = (int *)malloc((size_t)((nh - nl + 2) * sizeof(int)));
208 if(!v)
209 {
210 qFatal("Error: Allocation failure.");
211 }
212 return v - nl + 1;
213}

Referenced by sgcoeff().

◆ lubksb()

void pappso::FilterSavitzkyGolay::lubksb ( pappso_double ** a,
int n,
int * indx,
pappso_double b[] ) const
private

Definition at line 281 of file savgolfilter.cpp.

282{
283 int i, ii = 0, ip, j;
285
286 for(i = 1; i <= n; i++)
287 {
288 ip = indx[i];
289 sum = b[ip];
290 b[ip] = b[i];
291 if(ii)
292 for(j = ii; j <= i - 1; j++)
293 sum -= a[i][j] * b[j];
294 else if(sum)
295 ii = i;
296 b[i] = sum;
297 }
298 for(i = n; i >= 1; i--)
299 {
300 sum = b[i];
301 for(j = i + 1; j <= n; j++)
302 sum -= a[i][j] * b[j];
303 b[i] = sum / a[i][i];
304 }
305}
@ sum
sum of intensities
Definition types.h:279

References pappso::a, and pappso::b.

Referenced by sgcoeff().

◆ ludcmp()

void pappso::FilterSavitzkyGolay::ludcmp ( pappso_double ** a,
int n,
int * indx,
pappso_double * d ) const
private

Definition at line 309 of file savgolfilter.cpp.

310{
311 int i, imax = 0, j, k;
312 pappso_double big, dum, sum, temp;
313 pappso_double *vv;
314
315 vv = dvector(1, n);
316 *d = 1.0;
317 for(i = 1; i <= n; i++)
318 {
319 big = 0.0;
320 for(j = 1; j <= n; j++)
321 if((temp = fabs(a[i][j])) > big)
322 big = temp;
323 if(big == 0.0)
324 {
325 qFatal("Error: Singular matrix found in routine ludcmp().");
326 }
327 vv[i] = 1.0 / big;
328 }
329 for(j = 1; j <= n; j++)
330 {
331 for(i = 1; i < j; i++)
332 {
333 sum = a[i][j];
334 for(k = 1; k < i; k++)
335 sum -= a[i][k] * a[k][j];
336 a[i][j] = sum;
337 }
338 big = 0.0;
339 for(i = j; i <= n; i++)
340 {
341 sum = a[i][j];
342 for(k = 1; k < j; k++)
343 sum -= a[i][k] * a[k][j];
344 a[i][j] = sum;
345 if((dum = vv[i] * fabs(sum)) >= big)
346 {
347 big = dum;
348 imax = i;
349 }
350 }
351 if(j != imax)
352 {
353 for(k = 1; k <= n; k++)
354 {
355 dum = a[imax][k];
356 a[imax][k] = a[j][k];
357 a[j][k] = dum;
358 }
359 *d = -(*d);
360 vv[imax] = vv[j];
361 }
362 indx[j] = imax;
363 if(a[j][j] == 0.0)
364 a[j][j] = std::numeric_limits<pappso_double>::epsilon();
365 if(j != n)
366 {
367 dum = 1.0 / (a[j][j]);
368 for(i = j + 1; i <= n; i++)
369 a[i][j] *= dum;
370 }
371 }
372 free_dvector(vv, 1, n);
373}

References pappso::a, dvector(), and free_dvector().

Referenced by sgcoeff().

◆ name()

QString pappso::FilterSavitzkyGolay::name ( ) const
overridevirtual

Implements pappso::FilterNameInterface.

Definition at line 197 of file savgolfilter.cpp.

198{
199 return "Savitzky-Golay";
200}

Referenced by buildFilterFromString(), filteredData(), and toString().

◆ operator=()

FilterSavitzkyGolay & pappso::FilterSavitzkyGolay::operator= ( const FilterSavitzkyGolay & other)

Definition at line 102 of file savgolfilter.cpp.

103{
104 if(&other == this)
105 return *this;
106
107 // This function only copies the parameters, not the data.
108
109 m_params.nL = other.m_params.nL;
110 m_params.nR = other.m_params.nR;
111 m_params.m = other.m_params.m;
112 m_params.lD = other.m_params.lD;
113 m_params.convolveWithNr = other.m_params.convolveWithNr;
114
115 return *this;
116}

References FilterSavitzkyGolay(), pappso::SavGolParams::convolveWithNr, pappso::SavGolParams::lD, pappso::SavGolParams::m, m_params, pappso::SavGolParams::nL, and pappso::SavGolParams::nR.

◆ realft()

void pappso::FilterSavitzkyGolay::realft ( pappso_double data[],
unsigned long n,
int isign )
private

Definition at line 468 of file savgolfilter.cpp.

469{
470 unsigned long i, i1, i2, i3, i4, np3;
471 pappso_double c1 = 0.5, c2, h1r, h1i, h2r, h2i;
472 pappso_double wr, wi, wpr, wpi, wtemp, theta;
473
474 theta = 3.141592653589793 / (pappso_double)(n >> 1);
475 if(isign == 1)
476 {
477 c2 = -0.5;
478 four1(data, n >> 1, 1);
479 }
480 else
481 {
482 c2 = 0.5;
483 theta = -theta;
484 }
485 wtemp = sin(0.5 * theta);
486 wpr = -2.0 * wtemp * wtemp;
487 wpi = sin(theta);
488 wr = 1.0 + wpr;
489 wi = wpi;
490 np3 = n + 3;
491 for(i = 2; i <= (n >> 2); i++)
492 {
493 i4 = 1 + (i3 = np3 - (i2 = 1 + (i1 = i + i - 1)));
494 h1r = c1 * (data[i1] + data[i3]);
495 h1i = c1 * (data[i2] - data[i4]);
496 h2r = -c2 * (data[i2] + data[i4]);
497 h2i = c2 * (data[i1] - data[i3]);
498 data[i1] = h1r + wr * h2r - wi * h2i;
499 data[i2] = h1i + wr * h2i + wi * h2r;
500 data[i3] = h1r - wr * h2r + wi * h2i;
501 data[i4] = -h1i + wr * h2i + wi * h2r;
502 wr = (wtemp = wr) * wpr - wi * wpi + wr;
503 wi = wi * wpr + wtemp * wpi + wi;
504 }
505 if(isign == 1)
506 {
507 data[1] = (h1r = data[1]) + data[2];
508 data[2] = h1r - data[2];
509 }
510 else
511 {
512 data[1] = c1 * ((h1r = data[1]) + data[2]);
513 data[2] = c1 * (h1r - data[2]);
514 four1(data, n >> 1, -1);
515 }
516}
void four1(pappso_double data[], unsigned long nn, int isign)

References four1().

Referenced by convlv().

◆ runFilter()

char pappso::FilterSavitzkyGolay::runFilter ( double * y_data_p,
double * y_filtered_data_p,
int data_point_count ) const

Perform the Savitzky-Golay filtering process.

Definition at line 621 of file savgolfilter.cpp.

624{
625 int np = m_params.nL + 1 + m_params.nR;
627 char retval;
628
629#if CONVOLVE_WITH_NR_CONVLV
630 c = dvector(1, data_point_count);
631 retval = sgcoeff(c, np, m_nL, m_nR, m_lD, m_m);
632 if(retval == 0)
633 convlv(y_data_p, data_point_count, c, np, 1, y_filtered_data_p);
634 free_dvector(c, 1, data_point_count);
635#else
636 int j;
637 long int k;
638 c = dvector(1, m_params.nL + m_params.nR + 1);
639 retval = sgcoeff(c, np, m_params.nL, m_params.nR, m_params.lD, m_params.m);
640 if(retval == 0)
641 {
642 qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
643 << "retval is 0";
644
645 for(k = 1; k <= m_params.nL; k++)
646 {
647 for(y_filtered_data_p[k] = 0.0, j = -m_params.nL; j <= m_params.nR; j++)
648 {
649 if(k + j >= 1)
650 {
651 y_filtered_data_p[k] +=
652 c[(j >= 0 ? j + 1 : m_params.nR + m_params.nL + 2 + j)] * y_data_p[k + j];
653 }
654 }
655 }
656 for(k = m_params.nL + 1; k <= data_point_count - m_params.nR; k++)
657 {
658 for(y_filtered_data_p[k] = 0.0, j = -m_params.nL; j <= m_params.nR; j++)
659 {
660 y_filtered_data_p[k] +=
661 c[(j >= 0 ? j + 1 : m_params.nR + m_params.nL + 2 + j)] * y_data_p[k + j];
662 }
663 }
664 for(k = data_point_count - m_params.nR + 1; k <= data_point_count; k++)
665 {
666 for(y_filtered_data_p[k] = 0.0, j = -m_params.nL; j <= m_params.nR; j++)
667 {
668 if(k + j <= data_point_count)
669 {
670 y_filtered_data_p[k] +=
671 c[(j >= 0 ? j + 1 : m_params.nR + m_params.nL + 2 + j)] * y_data_p[k + j];
672 }
673 }
674 }
675 }
676
677 free_dvector(c, 1, m_params.nR + m_params.nL + 1);
678#endif
679
680 return (retval);
681}
char convlv(pappso_double data[], unsigned long n, pappso_double respns[], unsigned long m, int isign, pappso_double ans[])
char sgcoeff(pappso_double c[], int np, int nl, int nr, int ld, int m) const

References pappso::c, convlv(), dvector(), free_dvector(), m_params, and sgcoeff().

Referenced by filter().

◆ sgcoeff()

char pappso::FilterSavitzkyGolay::sgcoeff ( pappso_double c[],
int np,
int nl,
int nr,
int ld,
int m ) const
private

Definition at line 568 of file savgolfilter.cpp.

569{
570 int imj, ipj, j, k, kk, mm, *indx;
571 pappso_double d, fac, sum, **a, *b;
572
573 if(np < nl + nr + 1 || nl < 0 || nr < 0 || ld > m || nl + nr < m)
574 {
575 qDebug("Inconsistent arguments detected in routine sgcoeff.");
576 return (1);
577 }
578 indx = ivector(1, m + 1);
579 a = dmatrix(1, m + 1, 1, m + 1);
580 b = dvector(1, m + 1);
581 for(ipj = 0; ipj <= (m << 1); ipj++)
582 {
583 sum = (ipj ? 0.0 : 1.0);
584 for(k = 1; k <= nr; k++)
585 sum += pow((pappso_double)k, (pappso_double)ipj);
586 for(k = 1; k <= nl; k++)
587 sum += pow((pappso_double)-k, (pappso_double)ipj);
588 mm = (ipj < 2 * m - ipj ? ipj : 2 * m - ipj);
589 for(imj = -mm; imj <= mm; imj += 2)
590 a[1 + (ipj + imj) / 2][1 + (ipj - imj) / 2] = sum;
591 }
592 ludcmp(a, m + 1, indx, &d);
593 for(j = 1; j <= m + 1; j++)
594 b[j] = 0.0;
595 b[ld + 1] = 1.0;
596 lubksb(a, m + 1, indx, b);
597 for(kk = 1; kk <= np; kk++)
598 c[kk] = 0.0;
599 for(k = -nl; k <= nr; k++)
600 {
601 sum = b[1];
602 fac = 1.0;
603 for(mm = 1; mm <= m; mm++)
604 sum += b[mm + 1] * (fac *= k);
605 kk = ((np - k) % np) + 1;
606 c[kk] = sum;
607 }
608 free_dvector(b, 1, m + 1);
609 free_dmatrix(a, 1, m + 1, 1, m + 1);
610 free_ivector(indx, 1, m + 1);
611 return (0);
612}
void free_dmatrix(pappso_double **m, long nrl, long nrh, long ncl, long nch) const
pappso_double ** dmatrix(long nrl, long nrh, long ncl, long nch) const
void free_ivector(int *v, long nl, long nh) const
void lubksb(pappso_double **a, int n, int *indx, pappso_double b[]) const
int * ivector(long nl, long nh) const
void ludcmp(pappso_double **a, int n, int *indx, pappso_double *d) const

References pappso::a, pappso::b, pappso::c, dmatrix(), dvector(), free_dmatrix(), free_dvector(), free_ivector(), ivector(), lubksb(), and ludcmp().

Referenced by runFilter().

◆ toString()

QString pappso::FilterSavitzkyGolay::toString ( ) const
overridevirtual

Return a string with the textual representation of the configuration data.

Implements pappso::FilterNameInterface.

Definition at line 190 of file savgolfilter.cpp.

191{
192 return QString("%1|%2").arg(name()).arg(m_params.toString());
193}

References m_params, and name().

Referenced by filteredData().

◆ twofft()

void pappso::FilterSavitzkyGolay::twofft ( pappso_double data1[],
pappso_double data2[],
pappso_double fft1[],
pappso_double fft2[],
unsigned long n )
private

Definition at line 431 of file savgolfilter.cpp.

436{
437 unsigned long nn3, nn2, jj, j;
438 pappso_double rep, rem, aip, aim;
439
440 nn3 = 1 + (nn2 = 2 + n + n);
441 for(j = 1, jj = 2; j <= n; j++, jj += 2)
442 {
443 fft1[jj - 1] = data1[j];
444 fft1[jj] = data2[j];
445 }
446 four1(fft1, n, 1);
447 fft2[1] = fft1[2];
448 fft1[2] = fft2[2] = 0.0;
449 for(j = 3; j <= n + 1; j += 2)
450 {
451 rep = 0.5 * (fft1[j] + fft1[nn2 - j]);
452 rem = 0.5 * (fft1[j] - fft1[nn2 - j]);
453 aip = 0.5 * (fft1[j + 1] + fft1[nn3 - j]);
454 aim = 0.5 * (fft1[j + 1] - fft1[nn3 - j]);
455 fft1[j] = rep;
456 fft1[j + 1] = aim;
457 fft1[nn2 - j] = rep;
458 fft1[nn3 - j] = -aim;
459 fft2[j] = aip;
460 fft2[j + 1] = -rem;
461 fft2[nn2 - j] = aip;
462 fft2[nn3 - j] = rem;
463 }
464}

References four1().

Referenced by convlv().

Member Data Documentation

◆ m_params

SavGolParams pappso::FilterSavitzkyGolay::m_params
private

◆ m_x

pappso_double* pappso::FilterSavitzkyGolay::m_x
private

C array of keys of the Trace.

Definition at line 202 of file savgolfilter.h.

◆ m_yf

pappso_double* pappso::FilterSavitzkyGolay::m_yf
private

C array of filtered values after the computation has been performed.

Definition at line 208 of file savgolfilter.h.

◆ m_yr

pappso_double* pappso::FilterSavitzkyGolay::m_yr
private

C array of raw values of the Trace.

Definition at line 205 of file savgolfilter.h.


The documentation for this class was generated from the following files: