Bug 124158 - psd normalization is wrong
Summary: psd normalization is wrong
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-23 22:03 UTC by Enzo Pascale
Modified: 2006-06-13 23:40 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Proposed patch (3.57 KB, patch)
2006-03-28 01:22 UTC, Andrew Walker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Enzo Pascale 2006-03-23 22:03:01 UTC
Version:           1.2.0_svn_489756 (using KDE 3.3.2,  (3.1))
Compiler:          gcc version 3.3.5 (Debian 1:3.3.5-13)
OS:                Linux (i686) release 2.6.8-2-686-smp

PSD normalization is fine when used with the default apodization option.

As soon as the apodization is changed to use one of the available apodization function, the normalization is calculated wrong.
Comment 1 Andrew Walker 2006-03-28 01:22:38 UTC
Created attachment 15327 [details]
Proposed patch

Barth, could you confirm I'm on the right track here.
Comment 2 Netterfield 2006-03-28 02:09:57 UTC
I don't have time right not to look at it carefully at the moment.  Maybe next 
week.  What definition are you using for normalization?

On Monday 27 March 2006 15:22, Andrew Walker wrote:
> Barth, could you confirm I'm on the right track here.

Comment 3 Andrew Walker 2006-03-28 02:26:54 UTC
I apply the same normalization for each of the available apodizations as was already applied for the default case.
Comment 4 Andrew Walker 2006-05-03 01:32:00 UTC
Barth, have you had a chance to look at this yet?
Comment 5 Andrew Walker 2006-05-25 01:03:25 UTC
SVN commit 544476 by arwalker:

CCBUG:124158 Combine code for window generation so that it later only needs to be fixed in one place.

 M  +1 -0      kstcsd.cpp  
 M  +0 -1      kstcsd.h  
 M  +85 -81    kstpsd.cpp  
 M  +3 -1      kstpsd.h  
 M  +5 -84     kstpsdgenerator.cpp  
 M  +2 -1      kstpsdgenerator.h  
Comment 6 Andrew Walker 2006-05-25 01:51:29 UTC
Enzo, could you give more details as to why you believe the normalization is incorrect for everything other than the default. Thanks.
Comment 7 Andrew Walker 2006-05-25 18:51:26 UTC
SVN commit 544645 by arwalker:

BUG:124158 Normalize not just the default window, but all the others as well.

 M  +31 -0     kstpsd.cpp  


--- trunk/extragear/graphics/kst/src/libkstmath/kstpsd.cpp #544644:544645
@@ -236,28 +236,44 @@
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = (1.0 - fabs(x)/a);
+        sW += w[i] * w[i];
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // Blackman function 
     case 2:
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = 0.42 + 0.5*cos(M_PI*x/a) + 0.08*cos(2*M_PI*x/a);
+        sW += w[i] * w[i];
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // Connes function
     case 3: 
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = pow(1.0-(x*x)/(a*a), 2.0);
+        sW += w[i] * w[i];
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // cosine function
     case 4:
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = cos((M_PI*x)/(2.0*a));
+        sW += w[i] * w[i];
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // Gaussian function
     case 5:
@@ -265,27 +281,42 @@
         x = i-a;
         w[i] = exp((-1.0*x*x)/(2.0*gaussianSigma*gaussianSigma));
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // Hamming function
     case 6:
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = 0.53836 + 0.46164*cos(M_PI*x/a);
+        sW += w[i] * w[i];
       }  
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // Hann function
     case 7:
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = pow(cos((M_PI*x)/(2.0*a)), 2.0);
+        sW += w[i] * w[i];
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // Welch function
     case 8:
       for (i = 0; i < len; i++) {
         x = i-a;
         w[i] = 1.0 - (x*x)/(a*a);
+        sW += w[i] * w[i];
       }
+      for (i = 0; i < len; i++) {
+        w[i] /= sW;
+      }
       break;
     // uniform/rectangular function
     default:
Comment 8 Duncan Hanson 2006-06-13 23:36:35 UTC
'wrong' in that there are no 

sW = sqrt(sW / double(len));

calls, although this probably shouldn't have to be done here.

i'll commit a quick fix.
Comment 9 Duncan Hanson 2006-06-13 23:40:53 UTC
SVN commit 551186 by dhanson:

BUG:124158 sqrt(sW/len) for all apodizations.

 M  +9 -1      kstpsdgenerator.cpp  


--- trunk/extragear/graphics/kst/src/libkstmath/kstpsdgenerator.cpp #551185:551186
@@ -126,6 +126,7 @@
         w[i] = 1.0 - fabs(x) / a;
         sW += w[i] * w[i];
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -137,6 +138,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];
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -148,6 +150,7 @@
         w[i] = pow(1.0 - (x * x) / (a * a), 2.0);
         sW += w[i] * w[i];
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -159,6 +162,7 @@
         w[i] = cos(M_PI * x / (2.0 * a));
         sW += w[i] * w[i];
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -169,6 +173,7 @@
         x = i - a;
         w[i] = exp(-1.0 * x * x/(2.0 * gaussianSigma * gaussianSigma));
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -179,7 +184,8 @@
         x = i - a;
         w[i] = 0.53836 + 0.46164 * cos(M_PI * x / a);
         sW += w[i] * w[i];
-      }  
+      }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -191,6 +197,7 @@
         w[i] = pow(cos(M_PI * x/(2.0 * a)), 2.0);
         sW += w[i] * w[i];
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }
@@ -202,6 +209,7 @@
         w[i] = 1.0 - x * x / (a * a);
         sW += w[i] * w[i];
       }
+      sW = sqrt(sW / double(len));
       for (int i = 0; i < len; ++i) {
         w[i] /= sW;
       }