Python code for frequency spectrum analysis