how to get phase fft of a signal &-- can i get phase in time domain?
13,886
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)
Author by
Hanna
Updated on June 17, 2022Comments
-
Hanna almost 2 years
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)