summaryrefslogtreecommitdiff
path: root/log-fourier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'log-fourier.cpp')
-rw-r--r--log-fourier.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/log-fourier.cpp b/log-fourier.cpp
index e8404d7..11edfcb 100644
--- a/log-fourier.cpp
+++ b/log-fourier.cpp
@@ -186,12 +186,43 @@ Real estimateZ(LogarithmicFourierTransform& fft, const std::vector<Real>& C, con
Real energy(const LogarithmicFourierTransform& fft, std::vector<Real>& C, const std::vector<Real>& R, unsigned p, unsigned s, Real λ, Real β) {
Real E = fft.t(0) * (df(λ, p, s, 1) + R[0] * df(λ, p, s, C[0])) / 2;
for (unsigned n = 0; n < C.size()/2-1; n++) {
- if (C[2*n+2] < 0 || R[2*n+2] < 0) break;
+ Real R₂ₙ = R[2*n];
+ Real R₂ₙ₊₁ = R[2*n+1];
+ Real R₂ₙ₊₂ = R[2*n+2];
+ Real C₂ₙ = C[2*n];
+ Real C₂ₙ₊₁ = C[2*n+1];
+ Real C₂ₙ₊₂ = C[2*n+2];
+
+ if (R₂ₙ > 1 || R₂ₙ₊₁ > 1 || R₂ₙ₊₂ > 1) {
+ R₂ₙ = 1;
+ R₂ₙ₊₁ = 1;
+ R₂ₙ₊₂ = 1;
+ }
+
+ if (C₂ₙ > 1 || C₂ₙ₊₁ > 1 || C₂ₙ₊₂ > 1) {
+ C₂ₙ = 1;
+ C₂ₙ₊₁ = 1;
+ C₂ₙ₊₂ = 1;
+ }
+
+ if (R₂ₙ < 0 || R₂ₙ₊₁ < 0 || R₂ₙ₊₂ < 0) {
+ R₂ₙ = 0;
+ R₂ₙ₊₁ = 0;
+ R₂ₙ₊₂ = 0;
+ }
+
+ if (C₂ₙ < 0 || C₂ₙ₊₁ < 0 || C₂ₙ₊₂ < 0) {
+ C₂ₙ = 0;
+ C₂ₙ₊₁ = 0;
+ C₂ₙ₊₂ = 0;
+ }
+
Real h₂ₙ = fft.t(2*n+1) - fft.t(2*n);
Real h₂ₙ₊₁ = fft.t(2*n+2) - fft.t(2*n+1);
- Real f₂ₙ = R[2*n] * df(λ, p, s, C[2*n]);
- Real f₂ₙ₊₁ = R[2*n+1] * df(λ, p, s, C[2*n+1]);
- Real f₂ₙ₊₂ = R[2*n+2] * df(λ, p, s, C[2*n+2]);
+ Real f₂ₙ = R₂ₙ * df(λ, p, s, C₂ₙ);
+ Real f₂ₙ₊₁ = R₂ₙ₊₁ * df(λ, p, s, C₂ₙ₊₁);
+ Real f₂ₙ₊₂ = R₂ₙ₊₂ * df(λ, p, s, C₂ₙ₊₂);
+
E += (h₂ₙ + h₂ₙ₊₁) / 6 * (
(2 - h₂ₙ₊₁ / h₂ₙ) * f₂ₙ
+ std::pow(h₂ₙ + h₂ₙ₊₁, 2) / (h₂ₙ * h₂ₙ₊₁) * f₂ₙ₊₁