|
const T gain{ T{ 1 } }; |
|
BuildSections(bz, numB, az, numA, gain, sections, sectionCount); |
|
return sectionCount; |
|
} |
|
|
|
template<typename T, std::size_t MaxOrder> |
|
OPTIMIZE_FOR_SPEED std::size_t IirFilterDesign<T, MaxOrder>::DesignBandStop(std::size_t order, T wc, T fs, |
|
const std::array<ComplexT, 16>& protoPoles) noexcept |
|
{ |
|
const T bw{ wc }; |
|
const T wc0{ wc }; |
|
std::array<ComplexT, 32> az{}; |
|
std::array<ComplexT, 32> bz{}; |
|
std::size_t numA{ 0 }; |
|
std::size_t numB{ 0 }; |
|
|
|
for (std::size_t k{ 0 }; k < order; ++k) |
|
{ |
|
const T mag2{ protoPoles[k].Real() * protoPoles[k].Real() + protoPoles[k].Imaginary() * protoPoles[k].Imaginary() }; |
|
const ComplexT invLp{ protoPoles[k].Real() / mag2, -protoPoles[k].Imaginary() / mag2 }; |
|
const ComplexT bsLp{ invLp.Real() * bw / T{ 2 }, invLp.Imaginary() * bw / T{ 2 } }; |
|
|
|
const T discRe{ bsLp.Real() * bsLp.Real() - bsLp.Imaginary() * bsLp.Imaginary() - wc0 * wc0 }; |
|
const T discIm{ T{ 2 } * bsLp.Real() * bsLp.Imaginary() }; |
|
const T discMag{ math::Sqrt(math::Sqrt(discRe * discRe + discIm * discIm)) }; |
|
const T discAngle{ math::Atan2(discIm, discRe) / T{ 2 } }; |
|
const ComplexT sqrtDisc{ discMag * math::Cos(discAngle), discMag * math::Sin(discAngle) }; |
|
|
|
az[numA++] = BilinearS2Z(bsLp + sqrtDisc, fs); |
|
az[numA++] = BilinearS2Z(bsLp - sqrtDisc, fs); |
|
bz[numB++] = BilinearS2Z({ T{ 0 }, wc0 }, fs); |
|
bz[numB++] = BilinearS2Z({ T{ 0 }, -wc0 }, fs); |
|
} |
|
|
|
const T gain{ T{ 1 } }; |
Audit finding
AUD-0082f479320d805a1f9f35ebe4afaaeeded48913a94Problem
Band transforms create
2 * orderpoles, but storage remainsceil(MaxOrder/2)sections.BuildSections()silently stops at capacity. Band-pass and band-stop also hardcode scalar gain1.Source:
numerical-toolbox-cpp/numerical/filters/passive/IirFilterDesign.hpp
Lines 47 to 49 in 2f47932
numerical-toolbox-cpp/numerical/filters/passive/IirFilterDesign.hpp
Lines 246 to 278 in 2f47932
numerical-toolbox-cpp/numerical/filters/passive/IirFilterDesign.hpp
Lines 375 to 409 in 2f47932
Reproduction
4.4026, not unity.Acceptance criteria
orderis prototype or final digital order.