refactored spectrum calculation