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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With