code: def calc_spectrum(signal, rate):
      
      npts = len(signal)
      padto = 1 << (npts - 1).bit_length()
      # print 'length of signal {}, pad to {}'.format(npts, padto)
      npts = padto
  
      sp = np.fft.rfft(signal, n=padto) / npts
      # print('sp len ', len(sp))
      freq = np.arange((npts / 2) + 1) / (npts / rate)
      # print('freq len ', len(freq))
      return freq, abs(sp)
docs: Return the spectrum and frequency indexes for real-valued input signal