Working version with spectrum plotting