  The measurement of a quantum two-level system, or a qubit in modern
terminology, often involves an electromagnetic field that interacts with the
qubit, before the field is measured continuously and the qubit state is
inferred from the noisy field measurement. During the measurement, the qubit
may undergo spontaneous transitions, further obscuring the initial qubit state
from the observer. Taking advantage of some well known techniques in stochastic
detection theory, here we propose a novel signal processing protocol that can
infer the initial qubit state optimally from the measurement in the presence of
noise and qubit dynamics. Assuming continuous quantum-nondemolition
measurements with Gaussian or Poissonian noise and a classical Markov model for
the qubit, we derive analytic solutions to the protocol in some special cases
of interest using It\={o} calculus. Our method is applicable to
multi-hypothesis testing for robust qubit readout and relevant to experiments
on qubits in superconducting microwave circuits, trapped ions, nitrogen-vacancy
centers in diamond, semiconductor quantum dots, or phosphorus donors in
silicon.
