[Kst] branches/work/kst/1.5/kst/src/libkstmath

Duncan Hanson duncan.hanson at gmail.com
Thu Jun 21 18:48:47 CEST 2007


SVN commit 678547 by dhanson:

apply Barth's patch.

 M  +14 -1     psdcalculator.cpp  


--- branches/work/kst/1.5/kst/src/libkstmath/psdcalculator.cpp #678546:678547
@@ -84,6 +84,7 @@
         _w[i] = 0.42 + 0.5 * cos(M_PI * x / a) + 0.08 * cos(2 * M_PI * x/a);
         sW += _w[i] * _w[i];
       }
+      break;
 
     case WindowConnes: 
       for (int i = 0; i < _awLen; ++i) {
@@ -91,6 +92,7 @@
         _w[i] = pow(1.0 - (x * x) / (a * a), 2.0);
         sW += _w[i] * _w[i];
       }
+      break;
 
     case WindowCosine:
       for (int i = 0; i < _awLen; ++i) {
@@ -98,12 +100,14 @@
         _w[i] = cos(M_PI * x / (2.0 * a));
         sW += _w[i] * _w[i];
       }
+      break;
 
     case WindowGaussian:
       for (int i = 0; i < _awLen; ++i) {
         x = i - a;
         _w[i] = exp(-1.0 * x * x/(2.0 * gaussianSigma * gaussianSigma));
       }
+      break;
 
     case WindowHamming:
       for (int i = 0; i < _awLen; ++i) {
@@ -111,6 +115,7 @@
         _w[i] = 0.53836 + 0.46164 * cos(M_PI * x / a);
         sW += _w[i] * _w[i];
       }
+      break;
 
     case WindowHann:
       for (int i = 0; i < _awLen; ++i) {
@@ -118,6 +123,7 @@
         _w[i] = pow(cos(M_PI * x/(2.0 * a)), 2.0);
         sW += _w[i] * _w[i];
       }
+      break;
 
     case WindowWelch:
       for (int i = 0; i < _awLen; ++i) {
@@ -125,6 +131,7 @@
         _w[i] = 1.0 - x * x / (a * a);
         sW += _w[i] * _w[i];
       }
+      break;
 
     case WindowUniform:
     default:
@@ -185,8 +192,14 @@
   for (i_subset = 0; !done; i_subset++) {
     ioffset = i_subset*outputLen; //overlapping average => i_subset*outputLen
 
-    if (ioffset + _awLen < inputLen) {
+    // only zero pad if we really have to.  It is better to adjust the last chunk's
+    // overlap.
+    if (ioffset + _awLen*5/4 < inputLen) {
       currentCopyLen = _awLen; //will copy a complete window.
+    } else if (_awLen<inputLen) {  // count the last one from the end.
+      ioffset = inputLen-_awLen - 1;
+      currentCopyLen = _awLen; //will copy a complete window.
+      done = true;
     } else {
       currentCopyLen = inputLen - ioffset; //will copy a partial window.
       memset(&_a[currentCopyLen], 0, sizeof(double)*(_awLen - currentCopyLen)); //zero the leftovers.


More information about the Kst mailing list