libpappsomspp
Library for mass spectrometry
pappso::FilterSavitzkyGolay Class Reference

uses Savitsky-Golay filter on trace More...

#include <savgolfilter.h>

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

Public Member Functions

 FilterSavitzkyGolay (int nL, int nR, int m, int lD, bool convolveWithNr=false)
 
 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. More...
 
void filteredData (std::vector< pappso_double > &data)
 

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
 
QString toString () const
 Return a string with the textual representation of the configuration data. More...
 

Private Attributes

int m_nL = 15
 number of data points on the left of the filtered point More...
 
int m_nR = 15
 number of data points on the right of the filtered point More...
 
int m_m = 4
 
int m_lD = 0
 
bool m_convolveWithNr = false
 set to false for best results More...
 
pappso_doublem_x
 C array of keys of the Trace. More...
 
pappso_doublem_yr
 C array of raw values of the Trace. More...
 
pappso_doublem_yf
 C array of filtered values after the computation has been performed. More...
 

Detailed Description

uses Savitsky-Golay filter on trace

Definition at line 110 of file savgolfilter.h.

Constructor & Destructor Documentation

◆ FilterSavitzkyGolay() [1/2]

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 54 of file savgolfilter.cpp.

56 {
57  m_nL = nL;
58  m_nR = nR;
59  m_m = m;
60  m_lD = lD;
61  m_convolveWithNr = convolveWithNr;
62 }

References m_convolveWithNr, m_lD, m_m, m_nL, and m_nR.

◆ FilterSavitzkyGolay() [2/2]

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

Copy constructor

Parameters
otherTODO

Definition at line 65 of file savgolfilter.cpp.

66 {
67  // This function only copies the parameters, not the data.
68 
69  m_nL = other.m_nL;
70  m_nR = other.m_nR;
71  m_m = other.m_m;
72  m_lD = other.m_lD;
73  m_convolveWithNr = other.m_convolveWithNr;
74 }

References m_convolveWithNr, m_lD, m_m, m_nL, and m_nR.

◆ ~FilterSavitzkyGolay()

pappso::FilterSavitzkyGolay::~FilterSavitzkyGolay ( )
virtual

Destructor

Definition at line 77 of file savgolfilter.cpp.

78 {
79 }

Member Function Documentation

◆ 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 485 of file savgolfilter.cpp.

491 {
492  unsigned long i, no2;
493  pappso_double dum, mag2, *fft;
494 
495  fft = dvector(1, n << 1);
496  for(i = 1; i <= (m - 1) / 2; i++)
497  respns[n + 1 - i] = respns[m + 1 - i];
498  for(i = (m + 3) / 2; i <= n - (m - 1) / 2; i++)
499  respns[i] = 0.0;
500  twofft(data, respns, fft, ans, n);
501  no2 = n >> 1;
502  for(i = 2; i <= n + 2; i += 2)
503  {
504  if(isign == 1)
505  {
506  ans[i - 1] =
507  (fft[i - 1] * (dum = ans[i - 1]) - fft[i] * ans[i]) / no2;
508  ans[i] = (fft[i] * dum + fft[i - 1] * ans[i]) / no2;
509  }
510  else if(isign == -1)
511  {
512  if((mag2 = ans[i - 1] * ans[i - 1] + ans[i] * ans[i]) == 0.0)
513  {
514  qDebug("Attempt of deconvolving at zero response in convlv().");
515  return (1);
516  }
517  ans[i - 1] =
518  (fft[i - 1] * (dum = ans[i - 1]) + fft[i] * ans[i]) / mag2 / no2;
519  ans[i] = (fft[i] * dum - fft[i - 1] * ans[i]) / mag2 / no2;
520  }
521  else
522  {
523  qDebug("No meaning for isign in convlv().");
524  return (1);
525  }
526  }
527  ans[2] = ans[n + 1];
528  realft(ans, n, -1);
529  free_dvector(fft, 1, n << 1);
530  return (0);
531 }

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 191 of file savgolfilter.cpp.

192 {
193  long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
194  pappso_double **m;
195  m = (pappso_double **)malloc((size_t)((nrow + 1) * sizeof(pappso_double *)));
196  if(!m)
197  {
198  qFatal("Error: Allocation failure.");
199  }
200  m += 1;
201  m -= nrl;
202  m[nrl] = (pappso_double *)malloc(
203  (size_t)((nrow * ncol + 1) * sizeof(pappso_double)));
204  if(!m[nrl])
205  {
206  qFatal("Error: Allocation failure.");
207  }
208  m[nrl] += 1;
209  m[nrl] -= ncl;
210  for(i = nrl + 1; i <= nrh; i++)
211  m[i] = m[i - 1] + ncol;
212  return m;
213 }

Referenced by sgcoeff().

◆ dvector()

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

Definition at line 175 of file savgolfilter.cpp.

176 {
177  pappso_double *v;
178  long k;
179  v = (pappso_double *)malloc((size_t)((nh - nl + 2) * sizeof(pappso_double)));
180  if(!v)
181  {
182  qFatal("Error: Allocation failure.");
183  }
184  for(k = nl; k <= nh; k++)
185  v[k] = 0.0;
186  return v - nl + 1;
187 }

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

◆ filter()

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

Implements pappso::FilterInterface.

Definition at line 100 of file savgolfilter.cpp.

101 {
102  // Initialize data:
103 
104  // We want the filter to stay constant so we create a local copy of the data.
105 
106  int data_point_count = data_points.size();
107 
108  pappso_double *x_data_p = dvector(1, data_point_count);
109  pappso_double *y_initial_data_p = dvector(1, data_point_count);
110  pappso_double *y_filtered_data_p = nullptr;
111 
112  if(m_convolveWithNr)
113  y_filtered_data_p = dvector(1, 2 * data_point_count);
114  else
115  y_filtered_data_p = dvector(1, data_point_count);
116 
117  for(int iter = 0; iter < data_point_count; ++iter)
118  {
119  x_data_p[iter] = data_points.at(iter).x;
120  y_initial_data_p[iter] = data_points.at(iter).y;
121  }
122 
123  // Now run the filter.
124 
125  runFilter(y_initial_data_p, y_filtered_data_p, data_point_count);
126 
127  // Put back the modified y values into the trace.
128  auto iter_yf = y_filtered_data_p;
129  for(auto &data_point : data_points)
130  {
131  data_point.y = *iter_yf;
132  iter_yf++;
133  }
134 
135  return data_points;
136 }

References dvector(), m_convolveWithNr, 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 342 of file savgolfilter.cpp.

343 {
344  unsigned long n, mmax, m, j, istep, i;
345  pappso_double wtemp, wr, wpr, wpi, wi, theta;
346  pappso_double tempr, tempi;
347 
348  n = nn << 1;
349  j = 1;
350  for(i = 1; i < n; i += 2)
351  {
352  if(j > i)
353  {
354  SWAP(data[j], data[i]);
355  SWAP(data[j + 1], data[i + 1]);
356  }
357  m = n >> 1;
358  while(m >= 2 && j > m)
359  {
360  j -= m;
361  m >>= 1;
362  }
363  j += m;
364  }
365  mmax = 2;
366  while(n > mmax)
367  {
368  istep = mmax << 1;
369  theta = isign * (6.28318530717959 / mmax);
370  wtemp = sin(0.5 * theta);
371  wpr = -2.0 * wtemp * wtemp;
372  wpi = sin(theta);
373  wr = 1.0;
374  wi = 0.0;
375  for(m = 1; m < mmax; m += 2)
376  {
377  for(i = m; i <= n; i += istep)
378  {
379  j = i + mmax;
380  tempr = wr * data[j] - wi * data[j + 1];
381  tempi = wr * data[j + 1] + wi * data[j];
382  data[j] = data[i] - tempr;
383  data[j + 1] = data[i + 1] - tempi;
384  data[i] += tempr;
385  data[i + 1] += tempi;
386  }
387  wr = (wtemp = wr) * wpr - wi * wpi + wr;
388  wi = wi * wpr + wtemp * wpi + wi;
389  }
390  mmax = istep;
391  }
392 }

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 231 of file savgolfilter.cpp.

233 {
234  free((char *)(m[nrl] + ncl - 1));
235  free((char *)(m + nrl - 1));
236 }

Referenced by sgcoeff().

◆ free_dvector()

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

Definition at line 224 of file savgolfilter.cpp.

225 {
226  free((char *)(v + nl - 1));
227 }

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 217 of file savgolfilter.cpp.

218 {
219  free((char *)(v + nl - 1));
220 }

Referenced by sgcoeff().

◆ getParameters()

SavGolParams pappso::FilterSavitzkyGolay::getParameters ( ) const

Definition at line 140 of file savgolfilter.cpp.

141 {
142  return SavGolParams(m_nL, m_nR, m_m, m_lD, m_convolveWithNr);
143 }

References m_convolveWithNr, m_lD, m_m, m_nL, and m_nR.

◆ ivector()

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

Definition at line 162 of file savgolfilter.cpp.

163 {
164  int *v;
165  v = (int *)malloc((size_t)((nh - nl + 2) * sizeof(int)));
166  if(!v)
167  {
168  qFatal("Error: Allocation failure.");
169  }
170  return v - nl + 1;
171 }

Referenced by sgcoeff().

◆ lubksb()

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

Definition at line 240 of file savgolfilter.cpp.

244 {
245  int i, ii = 0, ip, j;
246  pappso_double sum;
247 
248  for(i = 1; i <= n; i++)
249  {
250  ip = indx[i];
251  sum = b[ip];
252  b[ip] = b[i];
253  if(ii)
254  for(j = ii; j <= i - 1; j++)
255  sum -= a[i][j] * b[j];
256  else if(sum)
257  ii = i;
258  b[i] = sum;
259  }
260  for(i = n; i >= 1; i--)
261  {
262  sum = b[i];
263  for(j = i + 1; j <= n; j++)
264  sum -= a[i][j] * b[j];
265  b[i] = sum / a[i][i];
266  }
267 }

Referenced by sgcoeff().

◆ ludcmp()

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

Definition at line 271 of file savgolfilter.cpp.

275 {
276  int i, imax = 0, j, k;
277  pappso_double big, dum, sum, temp;
278  pappso_double *vv;
279 
280  vv = dvector(1, n);
281  *d = 1.0;
282  for(i = 1; i <= n; i++)
283  {
284  big = 0.0;
285  for(j = 1; j <= n; j++)
286  if((temp = fabs(a[i][j])) > big)
287  big = temp;
288  if(big == 0.0)
289  {
290  qFatal("Error: Singular matrix found in routine ludcmp().");
291  }
292  vv[i] = 1.0 / big;
293  }
294  for(j = 1; j <= n; j++)
295  {
296  for(i = 1; i < j; i++)
297  {
298  sum = a[i][j];
299  for(k = 1; k < i; k++)
300  sum -= a[i][k] * a[k][j];
301  a[i][j] = sum;
302  }
303  big = 0.0;
304  for(i = j; i <= n; i++)
305  {
306  sum = a[i][j];
307  for(k = 1; k < j; k++)
308  sum -= a[i][k] * a[k][j];
309  a[i][j] = sum;
310  if((dum = vv[i] * fabs(sum)) >= big)
311  {
312  big = dum;
313  imax = i;
314  }
315  }
316  if(j != imax)
317  {
318  for(k = 1; k <= n; k++)
319  {
320  dum = a[imax][k];
321  a[imax][k] = a[j][k];
322  a[j][k] = dum;
323  }
324  *d = -(*d);
325  vv[imax] = vv[j];
326  }
327  indx[j] = imax;
328  if(a[j][j] == 0.0)
329  a[j][j] = std::numeric_limits<pappso_double>::epsilon();
330  if(j != n)
331  {
332  dum = 1.0 / (a[j][j]);
333  for(i = j + 1; i <= n; i++)
334  a[i][j] *= dum;
335  }
336  }
337  free_dvector(vv, 1, n);
338 }

References dvector(), and free_dvector().

Referenced by sgcoeff().

◆ operator=()

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

Definition at line 82 of file savgolfilter.cpp.

83 {
84  if(&other == this)
85  return *this;
86 
87  // This function only copies the parameters, not the data.
88 
89  m_nL = other.m_nL;
90  m_nR = other.m_nR;
91  m_m = other.m_m;
92  m_lD = other.m_lD;
93  m_convolveWithNr = other.m_convolveWithNr;
94 
95  return *this;
96 }

References m_convolveWithNr, m_lD, m_m, m_nL, and m_nR.

◆ realft()

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

Definition at line 433 of file savgolfilter.cpp.

434 {
435  unsigned long i, i1, i2, i3, i4, np3;
436  pappso_double c1 = 0.5, c2, h1r, h1i, h2r, h2i;
437  pappso_double wr, wi, wpr, wpi, wtemp, theta;
438 
439  theta = 3.141592653589793 / (pappso_double)(n >> 1);
440  if(isign == 1)
441  {
442  c2 = -0.5;
443  four1(data, n >> 1, 1);
444  }
445  else
446  {
447  c2 = 0.5;
448  theta = -theta;
449  }
450  wtemp = sin(0.5 * theta);
451  wpr = -2.0 * wtemp * wtemp;
452  wpi = sin(theta);
453  wr = 1.0 + wpr;
454  wi = wpi;
455  np3 = n + 3;
456  for(i = 2; i <= (n >> 2); i++)
457  {
458  i4 = 1 + (i3 = np3 - (i2 = 1 + (i1 = i + i - 1)));
459  h1r = c1 * (data[i1] + data[i3]);
460  h1i = c1 * (data[i2] - data[i4]);
461  h2r = -c2 * (data[i2] + data[i4]);
462  h2i = c2 * (data[i1] - data[i3]);
463  data[i1] = h1r + wr * h2r - wi * h2i;
464  data[i2] = h1i + wr * h2i + wi * h2r;
465  data[i3] = h1r - wr * h2r + wi * h2i;
466  data[i4] = -h1i + wr * h2i + wi * h2r;
467  wr = (wtemp = wr) * wpr - wi * wpi + wr;
468  wi = wi * wpr + wtemp * wpi + wi;
469  }
470  if(isign == 1)
471  {
472  data[1] = (h1r = data[1]) + data[2];
473  data[2] = h1r - data[2];
474  }
475  else
476  {
477  data[1] = c1 * ((h1r = data[1]) + data[2]);
478  data[2] = c1 * (h1r - data[2]);
479  four1(data, n >> 1, -1);
480  }
481 }

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 588 of file savgolfilter.cpp.

591 {
592  int np = m_nL + 1 + m_nR;
593  pappso_double *c;
594  char retval;
595 
596 #if CONVOLVE_WITH_NR_CONVLV
597  c = dvector(1, data_point_count);
598  retval = sgcoeff(c, np, m_nL, m_nR, m_lD, m_m);
599  if(retval == 0)
600  convlv(y_data_p, data_point_count, c, np, 1, y_filtered_data_p);
601  free_dvector(c, 1, data_point_count);
602 #else
603  int j;
604  long int k;
605  c = dvector(1, m_nL + m_nR + 1);
606  retval = sgcoeff(c, np, m_nL, m_nR, m_lD, m_m);
607  if(retval == 0)
608  {
609  qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
610  << "retval is 0";
611 
612  for(k = 1; k <= m_nL; k++)
613  {
614  for(y_filtered_data_p[k] = 0.0, j = -m_nL; j <= m_nR; j++)
615  {
616  if(k + j >= 1)
617  {
618  y_filtered_data_p[k] +=
619  c[(j >= 0 ? j + 1 : m_nR + m_nL + 2 + j)] * y_data_p[k + j];
620  }
621  }
622  }
623  for(k = m_nL + 1; k <= data_point_count - m_nR; k++)
624  {
625  for(y_filtered_data_p[k] = 0.0, j = -m_nL; j <= m_nR; j++)
626  {
627  y_filtered_data_p[k] +=
628  c[(j >= 0 ? j + 1 : m_nR + m_nL + 2 + j)] * y_data_p[k + j];
629  }
630  }
631  for(k = data_point_count - m_nR + 1; k <= data_point_count; k++)
632  {
633  for(y_filtered_data_p[k] = 0.0, j = -m_nL; j <= m_nR; j++)
634  {
635  if(k + j <= data_point_count)
636  {
637  y_filtered_data_p[k] +=
638  c[(j >= 0 ? j + 1 : m_nR + m_nL + 2 + j)] * y_data_p[k + j];
639  }
640  }
641  }
642  }
643 
644  free_dvector(c, 1, m_nR + m_nL + 1);
645 #endif
646 
647  return (retval);
648 }

References pappso::b, convlv(), dvector(), free_dvector(), m_lD, m_m, m_nL, m_nR, 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 535 of file savgolfilter.cpp.

537 {
538  int imj, ipj, j, k, kk, mm, *indx;
539  pappso_double d, fac, sum, **a, *b;
540 
541  if(np < nl + nr + 1 || nl < 0 || nr < 0 || ld > m || nl + nr < m)
542  {
543  qDebug("Inconsistent arguments detected in routine sgcoeff.");
544  return (1);
545  }
546  indx = ivector(1, m + 1);
547  a = dmatrix(1, m + 1, 1, m + 1);
548  b = dvector(1, m + 1);
549  for(ipj = 0; ipj <= (m << 1); ipj++)
550  {
551  sum = (ipj ? 0.0 : 1.0);
552  for(k = 1; k <= nr; k++)
553  sum += pow((pappso_double)k, (pappso_double)ipj);
554  for(k = 1; k <= nl; k++)
555  sum += pow((pappso_double)-k, (pappso_double)ipj);
556  mm = (ipj < 2 * m - ipj ? ipj : 2 * m - ipj);
557  for(imj = -mm; imj <= mm; imj += 2)
558  a[1 + (ipj + imj) / 2][1 + (ipj - imj) / 2] = sum;
559  }
560  ludcmp(a, m + 1, indx, &d);
561  for(j = 1; j <= m + 1; j++)
562  b[j] = 0.0;
563  b[ld + 1] = 1.0;
564  lubksb(a, m + 1, indx, b);
565  for(kk = 1; kk <= np; kk++)
566  c[kk] = 0.0;
567  for(k = -nl; k <= nr; k++)
568  {
569  sum = b[1];
570  fac = 1.0;
571  for(mm = 1; mm <= m; mm++)
572  sum += b[mm + 1] * (fac *= k);
573  kk = ((np - k) % np) + 1;
574  c[kk] = sum;
575  }
576  free_dvector(b, 1, m + 1);
577  free_dmatrix(a, 1, m + 1, 1, m + 1);
578  free_ivector(indx, 1, m + 1);
579  return (0);
580 }

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

Referenced by runFilter().

◆ toString()

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

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

Definition at line 148 of file savgolfilter.cpp.

149 {
150  return QString::asprintf(
151  "Savitzy-Golay filter parameters:\n"
152  "nL: %d ; nR: %d ; m: %d ; lD: %d ; convolveWithNr : %s",
153  m_nL,
154  m_nR,
155  m_m,
156  m_lD,
157  (m_convolveWithNr ? "true" : "false"));
158 }

References m_convolveWithNr, m_lD, m_m, m_nL, and m_nR.

◆ twofft()

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

Definition at line 396 of file savgolfilter.cpp.

401 {
402  unsigned long nn3, nn2, jj, j;
403  pappso_double rep, rem, aip, aim;
404 
405  nn3 = 1 + (nn2 = 2 + n + n);
406  for(j = 1, jj = 2; j <= n; j++, jj += 2)
407  {
408  fft1[jj - 1] = data1[j];
409  fft1[jj] = data2[j];
410  }
411  four1(fft1, n, 1);
412  fft2[1] = fft1[2];
413  fft1[2] = fft2[2] = 0.0;
414  for(j = 3; j <= n + 1; j += 2)
415  {
416  rep = 0.5 * (fft1[j] + fft1[nn2 - j]);
417  rem = 0.5 * (fft1[j] - fft1[nn2 - j]);
418  aip = 0.5 * (fft1[j + 1] + fft1[nn3 - j]);
419  aim = 0.5 * (fft1[j + 1] - fft1[nn3 - j]);
420  fft1[j] = rep;
421  fft1[j + 1] = aim;
422  fft1[nn2 - j] = rep;
423  fft1[nn3 - j] = -aim;
424  fft2[j] = aip;
425  fft2[j + 1] = -rem;
426  fft2[nn2 - j] = aip;
427  fft2[nn3 - j] = rem;
428  }
429 }

References four1().

Referenced by convlv().

Member Data Documentation

◆ m_convolveWithNr

bool pappso::FilterSavitzkyGolay::m_convolveWithNr = false
private

set to false for best results

Definition at line 160 of file savgolfilter.h.

Referenced by FilterSavitzkyGolay(), filter(), getParameters(), operator=(), and toString().

◆ m_lD

int pappso::FilterSavitzkyGolay::m_lD = 0
private

specifies the order of the derivative to extract from the Savitzky-Golay smoothing algorithm (for regular smoothing, use 0)

Definition at line 157 of file savgolfilter.h.

Referenced by FilterSavitzkyGolay(), getParameters(), operator=(), runFilter(), and toString().

◆ m_m

int pappso::FilterSavitzkyGolay::m_m = 4
private

order of the polynomial to use in the regression analysis leading to the Savitzky-Golay coefficients (typically between 2 and 6)

Definition at line 154 of file savgolfilter.h.

Referenced by FilterSavitzkyGolay(), getParameters(), operator=(), runFilter(), and toString().

◆ m_nL

int pappso::FilterSavitzkyGolay::m_nL = 15
private

number of data points on the left of the filtered point

Definition at line 150 of file savgolfilter.h.

Referenced by FilterSavitzkyGolay(), getParameters(), operator=(), runFilter(), and toString().

◆ m_nR

int pappso::FilterSavitzkyGolay::m_nR = 15
private

number of data points on the right of the filtered point

Definition at line 152 of file savgolfilter.h.

Referenced by FilterSavitzkyGolay(), getParameters(), operator=(), runFilter(), and toString().

◆ m_x

pappso_double* pappso::FilterSavitzkyGolay::m_x
private

C array of keys of the Trace.

Definition at line 166 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 172 of file savgolfilter.h.

◆ m_yr

pappso_double* pappso::FilterSavitzkyGolay::m_yr
private

C array of raw values of the Trace.

Definition at line 169 of file savgolfilter.h.


The documentation for this class was generated from the following files:
pappso::FilterSavitzkyGolay::runFilter
char runFilter(double *y_data_p, double *y_filtered_data_p, int data_point_count) const
Perform the Savitzky-Golay filtering process.
Definition: savgolfilter.cpp:588
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::FilterSavitzkyGolay::convlv
char convlv(pappso_double data[], unsigned long n, pappso_double respns[], unsigned long m, int isign, pappso_double ans[])
Definition: savgolfilter.cpp:485
pappso::FilterSavitzkyGolay::sgcoeff
char sgcoeff(pappso_double c[], int np, int nl, int nr, int ld, int m) const
Definition: savgolfilter.cpp:535
pappso::FilterSavitzkyGolay::lubksb
void lubksb(pappso_double **a, int n, int *indx, pappso_double b[]) const
Definition: savgolfilter.cpp:240
pappso::FilterSavitzkyGolay::m_nR
int m_nR
number of data points on the right of the filtered point
Definition: savgolfilter.h:152
pappso::FilterSavitzkyGolay::ludcmp
void ludcmp(pappso_double **a, int n, int *indx, pappso_double *d) const
Definition: savgolfilter.cpp:271
pappso::FilterSavitzkyGolay::free_dvector
void free_dvector(pappso_double *v, long nl, long nh) const
Definition: savgolfilter.cpp:224
pappso::FilterSavitzkyGolay::free_ivector
void free_ivector(int *v, long nl, long nh) const
Definition: savgolfilter.cpp:217
pappso::FilterSavitzkyGolay::m_lD
int m_lD
Definition: savgolfilter.h:157
pappso::FilterSavitzkyGolay::realft
void realft(pappso_double data[], unsigned long n, int isign)
Definition: savgolfilter.cpp:433
pappso::FilterSavitzkyGolay::m_nL
int m_nL
number of data points on the left of the filtered point
Definition: savgolfilter.h:150
pappso::FilterSavitzkyGolay::dvector
pappso_double * dvector(long nl, long nh) const
Definition: savgolfilter.cpp:175
pappso::FilterSavitzkyGolay::m_convolveWithNr
bool m_convolveWithNr
set to false for best results
Definition: savgolfilter.h:160
pappso::FilterSavitzkyGolay::twofft
void twofft(pappso_double data1[], pappso_double data2[], pappso_double fft1[], pappso_double fft2[], unsigned long n)
Definition: savgolfilter.cpp:396
pappso::PeptideIonNter::b
@ b
pappso::FilterSavitzkyGolay::free_dmatrix
void free_dmatrix(pappso_double **m, long nrl, long nrh, long ncl, long nch) const
Definition: savgolfilter.cpp:231
pappso::FilterSavitzkyGolay::four1
void four1(pappso_double data[], unsigned long nn, int isign)
Definition: savgolfilter.cpp:342
pappso::FilterSavitzkyGolay::m_m
int m_m
Definition: savgolfilter.h:154
pappso::FilterSavitzkyGolay::ivector
int * ivector(long nl, long nh) const
Definition: savgolfilter.cpp:162
SWAP
#define SWAP(a, b)
Definition: savgolfilter.cpp:48
pappso::FilterSavitzkyGolay::dmatrix
pappso_double ** dmatrix(long nrl, long nrh, long ncl, long nch) const
Definition: savgolfilter.cpp:191