2017-03-25 7 views
1

내가 .WAV 파일에서 나오는 신호의 크기를 얻을 수 있지만, 어떻게 그것도 신호의 위상을 얻기 위해 ,,, 여기 내가 .wav 파일을 찾아 및 신호신호의 위상 fft를 얻는 방법 & - 시간 영역에서 위상을 얻을 수 있습니까?

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) 

답변

1

를 추출 곳입니다 복잡한 스펙트럼은 크기와 위상을 모두 포함합니다. 절대 값을 계산하여 크기를 얻고 각도를 계산하여 위상을 얻습니다. numpy.angle()을 사용하면 위상을 얻을 수 있습니다.

spectrum = fft(self.signal) 
magnitude = np.abs(spectrum) 
phase = np.angle(spectrum)