Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get phase fft of a signal &-- can i get phase in time domain?

i can get magnitude of signal coming from .wav file , but how to get the phase of that signal too ,,, Here is the where i browse for .wav file and extract the signal

def browse_wav(self):

    filepath = QtGui.QFileDialog.getOpenFileName(self, 'Single File', "C:\Users\Hanna Nabil\Documents",'*.wav')
    f= str(filepath)
    if f != "":
        spf = wave.open(f, 'r')
    import contextlib

    with contextlib.closing(wave.open(f, 'r')) as f:
        frames = f.getnframes()
        rate = f.getframerate()
        duration = frames / float(rate)
        print "Duration is " , duration

    # Extract Raw Audio from Wav File
    self.signal = spf.readframes(-1)
    self.signal = np.fromstring(self.signal, 'Int16')
    self.fs = spf.getframerate()
    print "Sampling Rate is " ,self.fs

    # If Stereo
    if spf.getnchannels() == 2:
        print 'Just mono files'
        sys.exit(0)

    #self.time = np.linspace(0, len(self.signal) / fs, num=len(self.signal))
    self.time = np.linspace(0, duration, self.fs * duration)

    self.xfourier = fftfreq(self.signal.size, d=self.time[1] - self.time[0])
    self.yfourier = np.abs(fft(self.signal))  # signal magnitude

    self.zico = self.yfourier
    self.cut_signal = ifft(self.zico)
like image 333
Hanna Avatar asked Mar 09 '23 12:03

Hanna


1 Answers

The complex spectrum contains both the magnitude and phase. You get the magnitude by calculating the absolute value and you get the phase by calculating the angle. You can use numpy.angle() to get the phase:

spectrum = fft(self.signal)
magnitude = np.abs(spectrum)
phase = np.angle(spectrum)
like image 121
Lukáš Lalinský Avatar answered Apr 06 '23 18:04

Lukáš Lalinský