An optimized algorithm maximum a posteriori energy detection