[Kst] extragear/graphics/kst/src/libkstmath

Duncan Hanson duncan.hanson at gmail.com
Thu Jun 22 20:19:28 CEST 2006


SVN commit 553979 by dhanson:

CCBUG:129168 let PSDCalculator interpolate holes.

 M  +20 -4     psdcalculator.cpp  


--- trunk/extragear/graphics/kst/src/libkstmath/psdcalculator.cpp #553978:553979
@@ -26,6 +26,7 @@
 
 #include "kstdebug.h"
 #include "psdcalculator.h"
+#include "kstvector.h"
 
 extern "C" void rdft(int n, int isgn, double *a);
 
@@ -153,8 +154,6 @@
   bool apodize, ApodizeFunction apodizeFxn, double gaussianSigma,
   PSDType outputType, double inputSamplingFreq) {
 
-  Q_UNUSED(interpolateHoles) // right now, interpolation for holes will be done to the input data before passing it in to calculatePowerSpectrum. we can get a speed increase if we change this in the future...
-
   if (outputLen != calculateOutputVectorLength(inputLen, average, averageLen)) {
     KstDebug::self()->log(i18n("in PSDCalculator::calculatePowerSpectrum: received output array with wrong length."), KstDebug::Error);
     return -1;
@@ -212,10 +211,23 @@
     }
 
     // apply the PSD options (removeMean, apodize, etc.)
-    if (removeMean && apodize) {
+    // separate cases for speed- although this shouldn't really matter- the rdft should be the most time consuming step by far for any large data set.
+    if (removeMean && apodize && interpolateHoles) {
       for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
+        _a[i_samp] = (kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen) - mean)*_w[i_samp];
+      }
+    } else if (removeMean && apodize) {
+      for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
         _a[i_samp] = (input[i_samp + ioffset] - mean)*_w[i_samp];
       }
+    } else if (removeMean && interpolateHoles) {
+      for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
+        _a[i_samp] = kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen) - mean;
+      }
+    } else if (apodize && interpolateHoles) {
+      for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
+        _a[i_samp] = kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen)*_w[i_samp];
+      }
     } else if (removeMean) {
       for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
         _a[i_samp] = input[i_samp + ioffset] - mean;
@@ -224,6 +236,10 @@
       for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
         _a[i_samp] = input[i_samp + ioffset]*_w[i_samp];
       }
+    } else if (interpolateHoles) {
+      for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
+        _a[i_samp] = kstInterpolateNoHoles(input, inputLen, i_samp + ioffset, inputLen);
+      }
     } else {
       for (i_samp = 0; i_samp < currentCopyLen; i_samp++) {
         _a[i_samp] = input[i_samp + ioffset];
@@ -239,7 +255,7 @@
     }
   }
 
-  double frequencyStep = inputSamplingFreq/_awLen;
+  double frequencyStep = .5*(double)inputSamplingFreq/(double)(outputLen-1);
 
   //normalization factors which were left out earlier for speed. 
   //    - 2.0 for the negative frequencies which were neglected by the rdft //FIXME: double check.


More information about the Kst mailing list