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

2

5

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)
Pellegrini answered 25/3, 2017 at 16:48 Comment(0)
G
12

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)
Gametangium answered 25/3, 2017 at 18:54 Comment(0)
A
-1

For the answer from Lukas Lalinsky I find I have to add pi/2 for some reason to get the correct answer.

Also for points:

N = len(t)
Amplitude = 2/N *  np.abs(magnitude)
Annabelle answered 18/12, 2021 at 0:32 Comment(1)
You shouldn’t add pi/2. This likely stems from a misconception.Displayed

© 2022 - 2024 — McMap. All rights reserved.