Audit finding
- ID:
AUD-015
- Status: Verified defect
- Severity: High
- Confidence: High
- Audited revision:
2f479320d805a1f9f35ebe4afaaeeded48913a94
Problem
Hann, Hamming, and Blackman windows return hardcoded asymptotic power constants, while PSD normalization requires the actual finite-length mean-square power U = sum(w[n]^2)/N for the implemented window convention.
Source:
|
class HammingWindow |
|
: public Window<QNumberType> |
|
{ |
|
public: |
|
QNumberType operator()(std::size_t n, std::size_t order) override |
|
{ |
|
return QNumberType((0.54f - 0.46f * static_cast<float>(math::Cos(2.0 * math::pi * static_cast<double>(n) / static_cast<double>(order)))) * 0.9999f); |
|
} |
|
|
|
QNumberType Power([[maybe_unused]] std::size_t order) override |
|
{ |
|
return QNumberType(0.397f); |
|
} |
|
}; |
|
|
|
template<typename QNumberType> |
|
class HanningWindow |
|
: public Window<QNumberType> |
|
{ |
|
public: |
|
QNumberType operator()(std::size_t n, std::size_t order) override |
|
{ |
|
return QNumberType(0.5f * (1.0f - static_cast<float>(math::Cos(2.0 * math::pi * static_cast<double>(n) / static_cast<double>(order)))) * 0.9999f); |
|
} |
|
|
|
QNumberType Power([[maybe_unused]] std::size_t order) override |
|
{ |
|
return QNumberType(0.375f); |
|
} |
|
}; |
|
|
|
template<typename QNumberType> |
|
class BlackmanWindow |
|
: public Window<QNumberType> |
|
{ |
|
public: |
|
QNumberType operator()(std::size_t n, std::size_t order) override |
|
{ |
|
return QNumberType( |
|
(0.42f - 0.5f * static_cast<float>(math::Cos(2.0 * math::pi * static_cast<double>(n) / static_cast<double>(order))) + 0.08f * static_cast<float>(math::Cos(4.0 * math::pi * static_cast<double>(n) / static_cast<double>(order)))) * 0.9999f); |
|
} |
|
|
|
QNumberType Power([[maybe_unused]] std::size_t order) override |
|
{ |
|
return QNumberType(0.305f); |
|
} |
|
}; |
Reproduction
For the implemented two-point Hann window, direct mean-square power is 0.499899983; Power(2) returns 0.375. Welch density is therefore about 33.3% high for this valid segment length.
Acceptance criteria
Audit finding
AUD-0152f479320d805a1f9f35ebe4afaaeeded48913a94Problem
Hann, Hamming, and Blackman windows return hardcoded asymptotic power constants, while PSD normalization requires the actual finite-length mean-square power
U = sum(w[n]^2)/Nfor the implemented window convention.Source:
numerical-toolbox-cpp/numerical/analysis/windowing/Windowing.hpp
Lines 26 to 72 in 2f47932
Reproduction
For the implemented two-point Hann window, direct mean-square power is
0.499899983;Power(2)returns0.375. Welch density is therefore about 33.3% high for this valid segment length.Acceptance criteria
Power(N)equals the direct finite sum for every supported window and length.