Precision spectroscopy of a charged particle in an imperfect Penning trap