A generalisation of the Wiener-Wintner theorem