def getDft(data, sampleRate=None, wantPhase=False):
 samples = (2 ** int(np.log2(len(data))))
 samplesHalf = (samples // 2)
 dataSlice = data[:samples]
 dft = np.fft.fft(dataSlice)
 dftHalf = (dft[:samplesHalf] / samples)
 magn = (abs(dftHalf) * 2)
 magn[0] /= 2.0
 if wantPhase:
  phase = np.arctan2(dftHalf.real, dftHalf.imag)
 if sampleRate:
  deltaf = ((sampleRate / samplesHalf) / 2.0)
  freq = np.linspace(0, (samplesHalf * deltaf), samplesHalf, endpoint=False)
  if wantPhase:
   return (magn, freq, phase)
  return (magn, freq)
 else:
  if wantPhase:
   return (magn, phase)
  return magn

def getDft ( data , sampleRate = None , wantPhase = False ) : samples = ( 2 ** int ( np . log2 ( len ( data ) ) ) ) samplesHalf = ( samples // 2 ) dataSlice = data [ : samples ] dft = np . fft . fft ( dataSlice ) dftHalf = ( dft [ : samplesHalf ] / samples ) magn = ( abs ( dftHalf ) * 2 ) magn [ 0 ] /= 2.0 if wantPhase : phase = np . arctan2 ( dftHalf . real , dftHalf . imag ) if sampleRate : deltaf = ( ( sampleRate / samplesHalf ) / 2.0 ) freq = np . linspace ( 0 , ( samplesHalf * deltaf ) , samplesHalf , endpoint = False ) if wantPhase : return ( magn , freq , phase ) return ( magn , freq ) else : if wantPhase : return ( magn , phase ) return magn
compute and return magnitudes of numpy .