Refactored periodogram function to have two separate variants