Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/python
  2. from scikits.audiolab import wavread
  3. from pylab import *
  4.  
  5. signal, fs, enc = wavread('XC124158.wav')
  6. specgram(signal)
  7. show()
  8.  
  9. import os
  10. from subprocess import check_call
  11. from tempfile import mktemp
  12. from scikits.audiolab import wavread, play
  13. from scipy.signal import remez, lfilter
  14. from pylab import *
  15.  
  16. # convert mp3, read wav
  17. mp3filename = 'XC124158.mp3'
  18. wname = mktemp('.wav')
  19. check_call(['avconv', '-i', mp3filename, wname])
  20. sig, fs, enc = wavread(wname)
  21. os.unlink(wname)
  22.  
  23. # bandpass filter
  24. bands = array([0,3500,4000,5500,6000,fs/2.0]) / fs
  25. desired = [0, 1, 0]
  26. b = remez(513, bands, desired)
  27. sig_filt = lfilter(b, 1, sig)
  28. sig_filt /= 1.05 * max(abs(sig_filt)) # normalize
  29.  
  30. subplot(211)
  31. specgram(sig, Fs=fs, NFFT=1024, noverlap=0)
  32. axis('tight'); axis(ymax=8000)
  33. title('Original')
  34. subplot(212)
  35. specgram(sig_filt, Fs=fs, NFFT=1024, noverlap=0)
  36. axis('tight'); axis(ymax=8000)
  37. title('Filtered')
  38. show()
  39.  
  40. play(sig_filt, fs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement