Skip to content

[AUD-015][High] Compute finite-length window power for PSD normalization #308

Description

@gabrielsantosphilips

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

  • Power(N) equals the direct finite sum for every supported window and length.
  • Define and document periodic versus symmetric window semantics.
  • PSD integrated power agrees with an independent signal-variance reference.
  • Replace tests that only repeat the hardcoded constants.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions