Advertisement
Guest User

Untitled

a guest
Nov 12th, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import wave
  2. import pyaudio
  3. import numpy as np
  4. import os, copy
  5. import math
  6. from scipy.io.wavfile import write
  7. from scipy.io.wavfile import read
  8. from numpy import cos, sin, pi, absolute, arange, log10
  9. from scipy.signal import kaiserord, lfilter, firwin, freqz, hilbert
  10. from pylab import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show, semilogx, xticks
  11. import numpy as np
  12. import matplotlib.pyplot as plt
  13.  
  14. INT16_FAC = (2**15)-1
  15. INT32_FAC = (2**31)-1
  16. INT64_FAC = (2**63)-1
  17. norm_fact = {'int16':INT16_FAC, 'int32':INT32_FAC, 'int64':INT64_FAC,'float32':1.0,'float64':1.0}
  18.    
  19. def wavread(filename):
  20.     (fs, x) = read(filename)    # read a sound file and return an array with the sound and the sampling rate
  21.     x = np.float32(x)/norm_fact[x.dtype.name]  #scaling down and converting audio into floating point number between range -1 to 1
  22.     return fs, x
  23.      
  24.  
  25. if __name__ == '__main__':
  26.     (fs, xin) = wavread('test.wav')
  27.    
  28.     if (len(xin.shape) == 1):
  29.      print('Mono files unsupported.')
  30.      exit()
  31.    
  32.     x = xin[:,0]
  33.     N = len(x)  
  34.  
  35.     env1 = 0.0        # lowpass
  36.     y1 = []
  37.     for n in range(N):
  38.       tmp1 = x[n]
  39.       env1 = 0.95 * (env1 - tmp1) + tmp1
  40.       y1.append (env1)
  41.      
  42.     H = abs(hilbert(y1))     # module of hilbert transform
  43.  
  44.     plot(range(N),H)
  45.     show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement