Summary: | psd normalization is wrong | ||
---|---|---|---|
Product: | [Applications] kst | Reporter: | Enzo Pascale <enzo> |
Component: | general | Assignee: | kst |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | 1.x | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | Proposed patch |
Description
Enzo Pascale
2006-03-23 22:03:01 UTC
Created attachment 15327 [details]
Proposed patch
Barth, could you confirm I'm on the right track here.
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.
I apply the same normalization for each of the available apodizations as was already applied for the default case. Barth, have you had a chance to look at this yet? 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 Enzo, could you give more details as to why you believe the normalization is incorrect for everything other than the default. Thanks. 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: '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. 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; } |