  Using first-principles density functional theory, we investigate the
dynamical properties of the room-temperature $P2_1/n$ and ground-state $P2_1/c$
phases of WO$_3$. As a preliminary step, we assess the validity of various
standard and hybrid functionals, concluding that the best description is
achieved with the B1-WC hybrid functional while a reliable description can also
be provided using the standard LDA functional. We also carefully rediscuss the
structure and energetics of all experimentally observed and a few hypothetical
metastable phases in order to provide deeper insight into the unusual phase
diagram of WO$_3$. Then, we provide a comprehensive theoretical study of the
lattice dynamical properties of the $P2_1/n$ and $P2_1/c$ phases, reporting
zone-center phonons, infrared and Raman spectra as well as the full phonon
dispersion curves, which attest for the dynamical stability of both phases. We
carefully discuss the spectra, explaining the physical origin of their main
features and evolution from one phase to another. We reveal a systematic
connection between the dynamical and structural properties of WO$_3$,
highlighting that the number of peaks in the high-frequency range of the Raman
spectrum appears as a fingerprint of the number of antipolar distortions that
are present in the structure and a practical way to discriminate between the
different phases.
