Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.27 KB | None | 0 0
  1. # Created by Edgar Cuevas w/ Paris Smaragdis & Shrikant Venkataramani
  2. # © 2019 UIUC VoiceLab. All Rights Reserved
  3. # This file creates a basic ideal binary mask using a noise and signal processing of the same sampling rate
  4.  
  5.  
  6. import os
  7. import ntpath
  8. import scipy.signal
  9. import scipy.io.wavfile
  10. import matplotlib.pyplot as plt
  11. from scipy.io.wavfile import read as wavread
  12. from matplotlib.pylab import *
  13. from scipy import signal
  14. import numpy as np
  15. from matplotlib import rcParams
  16. import shutil
  17. from tkinter import filedialog
  18. import tkinter
  19. from numpy import dot, linalg, log10
  20. from IPython import get_ipython
  21. from numpy.fft import irfft, fft
  22. from scipy.signal import stft, istft, lfilter
  23. from numpy import mean, var
  24. import numpy as np
  25. from numpy.linalg import norm
  26. import pandas as pd
  27. import random
  28. import pdb
  29. import pickle
  30. import seaborn as sns
  31. import io
  32.  
  33.  
  34.  
  35.  
  36. # creates a given cmap to make the image look more professional for publication
  37. rcParams["image.cmap"] = "Greys"
  38.  
  39.  
  40. def mean_var_normalize( x):
  41. return (x - np.mean( x))/( np.std( x))
  42.  
  43. def bss_eval(sep, i, sources):
  44. min_len = min([len(sep), len(sources[i])])
  45. sources = sources[:, :min_len]
  46. sep = sep[:min_len]
  47. target = sources[i]
  48. # Target contribution
  49. s_target = target * dot(target, sep.T) / dot(target, target.T)
  50. # Interference contribution
  51. pse = dot(dot(sources, sep.T), linalg.inv(dot(sources, sources.T))).T.dot(sources)
  52. e_interf = pse - s_target
  53. # Artifact contribution
  54. e_artif = sep - pse
  55. # Interference + artifacts contribution
  56. e_total = e_interf + e_artif
  57. # Computation of the log energy ratios
  58. sdr = 10 * log10(sum(s_target ** 2) / sum(e_total ** 2))
  59. sir = 10 * log10(sum(s_target ** 2) / sum(e_interf ** 2))
  60. sar = 10 * log10(sum((s_target + e_interf) ** 2) / sum(e_artif ** 2))
  61. # Done!
  62. return (sdr, sir, sar)
  63.  
  64.  
  65. def folderCreator(SNR):
  66. string_SNR = str(SNR)
  67. SNR_FName = string_SNR + "db"
  68. healthy_results_path = "~/Desktop/idbm/healthy_r"
  69. hoarse_results_path = "~/Desktop/idbm/hoarse_r"
  70. healthy_dB_path = "~/Desktop/idbm/healthy_r/" + SNR_FName
  71. hoarse_dB_path = "~/Desktop/idbm/hoarse_r/" + SNR_FName
  72. healthy_recovered_noise_path = "~/Desktop/idbm/healthy_r/" + SNR_FName + "/EstNoise"
  73. hoarse_recovered_noise_path = "~/Desktop/idbm/hoarse_r/" + SNR_FName + "/EstNoise"
  74. healthy_recovered_signal_path = (
  75. "~/Desktop/idbm/healthy_r/" + SNR_FName + "/EstSignal"
  76. )
  77. hoarse_recovered_signal_path = "~/Desktop/idbm/hoarse_r/" + SNR_FName + "/EstSignal"
  78. healthy_mix_path = "~/Desktop/idbm/healthy_r/" + SNR_FName + "/Mix"
  79. hoarse_mix_path = "~/Desktop/idbm/hoarse_r/" + SNR_FName + "/Mix"
  80. healthy_sig_path = "~/Desktop/idbm/healthy_r/" + SNR_FName + "/Sig"
  81. hoarse_sig_path = "~/Desktop/idbm/hoarse_r/" + SNR_FName + "/Sig"
  82. healthy_noise_path = "~/Desktop/idbm/healthy_r/" + SNR_FName + "/Noise"
  83. hoarse_noise_path = "~/Desktop/idbm/hoarse_r/" + SNR_FName + "/Noise"
  84.  
  85. # Creates Healthy
  86.  
  87. healthy_folder = os.path.expanduser(healthy_results_path)
  88. if not os.path.exists(healthy_folder):
  89. os.makedirs(healthy_folder)
  90. hoarse_folder = os.path.expanduser(hoarse_results_path)
  91. if not os.path.exists(hoarse_folder):
  92. os.makedirs(hoarse_folder)
  93. hoarse_folder_db = os.path.expanduser(hoarse_dB_path)
  94. if not os.path.exists(hoarse_folder_db):
  95. os.makedirs(hoarse_folder_db)
  96. healthy_folder_db = os.path.expanduser(healthy_dB_path)
  97. if not os.path.exists(healthy_folder_db):
  98. os.makedirs(healthy_folder_db)
  99. healthy_folder_db_estnoise = os.path.expanduser(healthy_recovered_noise_path)
  100. if not os.path.exists(healthy_folder_db_estnoise):
  101. os.makedirs(healthy_folder_db_estnoise)
  102. hoarse_folder_db_estnoise = os.path.expanduser(hoarse_recovered_noise_path)
  103. if not os.path.exists(hoarse_folder_db_estnoise):
  104. os.makedirs(hoarse_folder_db_estnoise)
  105.  
  106. healthy_folder_db_estsignal = os.path.expanduser(healthy_recovered_signal_path)
  107. if not os.path.exists(healthy_folder_db_estsignal):
  108. os.makedirs(healthy_folder_db_estsignal)
  109. hoarse_folder_db_estsignal = os.path.expanduser(hoarse_recovered_signal_path)
  110. if not os.path.exists(hoarse_folder_db_estsignal):
  111. os.makedirs(hoarse_folder_db_estsignal)
  112.  
  113. healthy_folder_mix = os.path.expanduser(healthy_mix_path)
  114. if not os.path.exists(healthy_folder_mix):
  115. os.makedirs(healthy_folder_mix)
  116. hoarse_folder_mix = os.path.expanduser(hoarse_mix_path)
  117. if not os.path.exists(hoarse_folder_mix):
  118. os.makedirs(hoarse_folder_mix)
  119.  
  120. healthy_folder_sig = os.path.expanduser(healthy_sig_path)
  121. if not os.path.exists(healthy_folder_sig):
  122. os.makedirs(healthy_folder_sig)
  123. hoarse_folder_sig = os.path.expanduser(hoarse_sig_path)
  124. if not os.path.exists(hoarse_folder_sig):
  125. os.makedirs(hoarse_folder_sig)
  126.  
  127. healthy_folder_noise = os.path.expanduser(healthy_noise_path)
  128. if not os.path.exists(healthy_folder_noise):
  129. os.makedirs(healthy_folder_noise)
  130. hoarse_folder_noise = os.path.expanduser(hoarse_noise_path)
  131. if not os.path.exists(hoarse_folder_noise):
  132. os.makedirs(hoarse_folder_noise)
  133. arr = [
  134. healthy_recovered_noise_path,
  135. hoarse_recovered_noise_path,
  136. healthy_recovered_signal_path,
  137. hoarse_recovered_signal_path,
  138. healthy_mix_path,
  139. hoarse_mix_path,
  140. healthy_sig_path,
  141. hoarse_sig_path,
  142. healthy_noise_path,
  143. hoarse_noise_path,
  144. ]
  145. return arr
  146.  
  147. def getResults():
  148. healthy_Folder = os.path.expanduser("." + os.sep + "Healthy")
  149. hoarse_Folder = os.path.expanduser("." + os.sep + "Hoarse")
  150. noise_Folder = os.path.expanduser("." + os.sep + "Noise")
  151.  
  152. healthy_files = [f for f in os.listdir(healthy_Folder) if f.endswith(".wav")]
  153. hoarse_files = [f for f in os.listdir(hoarse_Folder) if f.endswith(".wav")]
  154. noise_files = [f for f in os.listdir(noise_Folder) if f.endswith(".wav")]
  155. SDR_healthy_overall, SDR_hoarse_overall = [], []
  156. SIR_healthy_overall, SIR_hoarse_overall = [], []
  157. SAR_healthy_overall, SAR_hoarse_overall = [], []
  158.  
  159. SNR_values = [-10,-8,-6,-4,-2,0,2,4,6,8,10]
  160.  
  161. for SNR in SNR_values:
  162. string_SNR = str(SNR)
  163. arr = folderCreator(SNR)
  164. SDR_healthy, SDR_hoarse = [], []
  165. SIR_healthy, SIR_hoarse = [], []
  166. SAR_healthy, SAR_hoarse = [], []
  167. healthy_name_arr = []
  168. hoarse_name_arr = []
  169. noise_name_arr = []
  170.  
  171.  
  172. print('Starting for SNR: ', SNR, ' dB')
  173.  
  174.  
  175. alpha = 10 ** (-SNR/20)
  176.  
  177. for idx in arange(40):
  178.  
  179. #gets a random selection from the healthy_files, hoarse_files, noise_files
  180. healthy_selection = random.choice( healthy_files)
  181. hoarse_selection = random.choice( hoarse_files)
  182. noise_selection = random.choice (noise_files)
  183.  
  184. #gets the names without .wav ending
  185. healthy_Stripped = healthy_selection.strip(".wav")
  186. hoarse_Stripped = hoarse_selection.strip(".wav")
  187. noise_Stripped = noise_selection.strip(".wav")
  188.  
  189. sr, healthy_sig = wavread(healthy_Folder + os.sep + healthy_selection)
  190. sr2, hoarse_sig = wavread(hoarse_Folder + os.sep + hoarse_selection)
  191. sr3, noise = wavread(noise_Folder + os.sep + noise_selection)
  192.  
  193. # Load 'em'
  194. healthy_sig = healthy_sig.astype( float)/32768
  195. hoarse_sig = hoarse_sig.astype( float)/32768
  196. noise = noise.astype( float)/32768
  197.  
  198. # Trim them to the same length
  199. l = min( [len( healthy_sig), len( hoarse_sig), len( noise)])
  200. healthy_sig = healthy_sig[:l]
  201. hoarse_sig = hoarse_sig[:l]
  202.  
  203. # Use random starting point for noise
  204. noise_start = random.choice( arange( len( noise)-l-1))
  205. noise = noise[int( noise_start):int(noise_start+l)]
  206.  
  207. # Normalize to zero mean and unit variance
  208. healthy_sig = ( healthy_sig - np.mean( healthy_sig))/np.std( healthy_sig)
  209. hoarse_sig = ( hoarse_sig - np.mean( hoarse_sig))/np.std( hoarse_sig)
  210. noise = ( noise - np.mean( noise))/np.std( noise)
  211.  
  212. #Naming Convention for Saving Original Noise and Signal at given dB values
  213. saveNoiseSTR = healthy_Stripped + "_" + hoarse_Stripped + "_healthy_orignoise.wav"
  214. saveNoiseSTR2 = healthy_Stripped + "_" + hoarse_Stripped + "_hoarse_orignoise.wav"
  215. saveSigSTR = healthy_Stripped + "_" + hoarse_Stripped + "_origsig.wav"
  216. saveSigSTR2 = healthy_Stripped + "_" + hoarse_Stripped + "_origsig2.wav"
  217.  
  218. # saves the noise files used
  219. scipy.io.wavfile.write(
  220. saveNoiseSTR,
  221. sr,
  222. noise / max(abs(noise) + 0.01),
  223. )
  224. scipy.io.wavfile.write(
  225. saveNoiseSTR2, sr, noise / max(abs(noise) + 0.01)
  226. )
  227. # saves all the signal files used
  228. scipy.io.wavfile.write(
  229. saveSigSTR, sr, healthy_sig / max(abs(healthy_sig) + 0.01)
  230. )
  231. scipy.io.wavfile.write(
  232. saveSigSTR2, sr, hoarse_sig / max(abs(hoarse_sig) + 0.01)
  233. )
  234.  
  235. # Make mixture
  236. healthy_mix = healthy_sig + alpha*noise
  237. hoarse_mix = hoarse_sig + alpha*noise
  238.  
  239. # saves mixtures
  240. saveMixtureSTR = (
  241. healthy_Stripped + "_" + noise_Stripped + "_healthy_mixture.wav"
  242. )
  243. saveMixtureSTR2 = (
  244. hoarse_Stripped + "_" + noise_Stripped + "_hoarse_mixture.wav"
  245. )
  246. scipy.io.wavfile.write(
  247. saveMixtureSTR, sr, healthy_mix / max(abs(healthy_mix) + 0.01)
  248. )
  249. scipy.io.wavfile.write(
  250. saveMixtureSTR2, sr, hoarse_mix / max(abs(hoarse_mix) + 0.01)
  251. )
  252.  
  253.  
  254. # stft params
  255. sz = int( 2**rint( log2(sr/16)))
  256. hp = sz//4
  257. win = hanning( sz+1)[:-1]
  258. eps = 1e-4
  259.  
  260. # Transform mixtures
  261. healthy_mix_stft = stft( healthy_mix, nperseg=sz, noverlap=sz-hp, window=win)[2]
  262. healthy_mix_a, healthy_mix_p = abs( healthy_mix_stft), healthy_mix_stft/( abs( healthy_mix_stft) + eps)
  263.  
  264. hoarse_mix_stft = stft( hoarse_mix, nperseg=sz, noverlap=sz-hp, window=win)[2]
  265. hoarse_mix_a, hoarse_mix_p = abs( hoarse_mix_stft), hoarse_mix_stft/( abs( hoarse_mix_stft) + eps)
  266.  
  267. # Transform ground truths
  268. healthy_sig_stft = stft( healthy_sig, nperseg=sz, noverlap=sz-hp, window=win)[2]
  269. healthy_sig_a, healthy_sig_p = abs( healthy_sig_stft), healthy_sig_stft/( abs( healthy_sig_stft) + eps)
  270.  
  271. hoarse_sig_stft = stft( hoarse_sig, nperseg=sz, noverlap=sz-hp, window=win)[2]
  272. hoarse_sig_a, hoarse_sig_p = abs( hoarse_sig_stft), hoarse_sig_stft/( abs( hoarse_sig_stft) + eps)
  273.  
  274. ########################## Possible change here.... are you doing this correctly......???????????????? ###############################
  275. noise_stft = stft( alpha*noise, nperseg=sz, noverlap=sz-hp, window=win)[2]
  276. noise_a, noise_p = abs( noise_stft), noise_stft/( abs( noise_stft) + eps)
  277.  
  278. # Estimate Ideal Binary Masks
  279. healthy_mask = ( healthy_sig_a > noise_a)
  280. hoarse_mask = ( hoarse_sig_a > noise_a)
  281.  
  282. # Invert 'em'
  283. healthy_sig_denoised = istft( healthy_mask * healthy_mix_stft, nperseg=sz, noverlap=sz-hp, window=win)[1]
  284. hoarse_sig_denoised = istft( hoarse_mask * hoarse_mix_stft, nperseg=sz, noverlap=sz-hp, window=win)[1]
  285.  
  286. #Naming Convention for saved files
  287. saveProcessedSTR = (
  288. healthy_Stripped + "_" + noise_Stripped + "_healthy_processed.wav"
  289. )
  290. saveProcessedSTR2 = (
  291. hoarse_Stripped + "_" + noise_Stripped + "_hoarse_processed.wav"
  292. )
  293. # saves the files
  294. scipy.io.wavfile.write(
  295. saveProcessedSTR,
  296. sr,
  297. healthy_sig_denoised / max(abs(healthy_sig_denoised) + 0.01),
  298. )
  299. scipy.io.wavfile.write(
  300. saveProcessedSTR2,
  301. sr,
  302. hoarse_sig_denoised / max(abs(hoarse_sig_denoised) + 0.01),
  303. )
  304.  
  305. # Take the shortest lenght of arr to get estimated Noise
  306. l2 = min(len(healthy_mix), len(healthy_sig_denoised))
  307. l3 = min(len(hoarse_mix), len(hoarse_sig_denoised))
  308. healthy_sig_length = healthy_mix[:l2]
  309. healthy_noise_length = healthy_sig_denoised[:l2]
  310. hoarse_sig_length = hoarse_mix[:l3]
  311. hoarse_noise_length = hoarse_sig_denoised[:l3]
  312. # Calculate the Estimated Noise
  313. recHealthy = healthy_sig_length - healthy_noise_length
  314. recNoise = hoarse_sig_length - hoarse_noise_length
  315.  
  316. # Saves Estimated Noise
  317. saveRecNoiseSTR = (
  318. healthy_Stripped + "_" + noise_Stripped + "_healthy_noise_recovered.wav"
  319. )
  320. saveRecNoiseSTR2 = (
  321. hoarse_Stripped + "_" + noise_Stripped + "_hoarse_noise_recovered.wav"
  322. )
  323.  
  324. # Saves the Estimated Noise Files
  325. scipy.io.wavfile.write(
  326. saveRecNoiseSTR, sr, recHealthy / max(abs(recHealthy) + 0.01)
  327. )
  328. scipy.io.wavfile.write(
  329. saveRecNoiseSTR2, sr, recNoise / max(abs(recNoise) + 0.01)
  330. )
  331.  
  332. ####### Moves all of the files ####################
  333. saveOne = arr[0] + os.sep + saveRecNoiseSTR
  334. saveTwo = arr[1] + os.sep + saveRecNoiseSTR2
  335. saveThree = arr[2] + os.sep + saveProcessedSTR
  336. saveFour = arr[3] + os.sep + saveProcessedSTR2
  337. saveFive = arr[4] + os.sep + saveMixtureSTR
  338. saveSix = arr[5] + os.sep + saveMixtureSTR2
  339. saveSeven = arr[6] + os.sep + saveSigSTR
  340. saveEight = arr[7] + os.sep + saveSigSTR2
  341. saveNine = arr[8] + os.sep + saveNoiseSTR
  342. saveTen = arr[9] + os.sep + saveNoiseSTR2
  343. # Moves the Recovered Noise Files to Correct Place
  344. original = os.path.expanduser("~/Desktop/idbm/" + saveRecNoiseSTR)
  345. newlocation = os.path.expanduser(saveOne)
  346. shutil.move(original, newlocation)
  347. original2 = os.path.expanduser("~/Desktop/idbm/" + saveRecNoiseSTR2)
  348. newlocation2 = os.path.expanduser(saveTwo)
  349. shutil.move(original2, newlocation2)
  350. # Moves the Recovered Sig Files to Correct Place
  351. original3 = os.path.expanduser("~/Desktop/idbm/" + saveProcessedSTR)
  352. newlocation3 = os.path.expanduser(saveThree)
  353. shutil.move(original3, newlocation3)
  354. original4 = os.path.expanduser("~/Desktop/idbm/" + saveProcessedSTR2)
  355. newlocation4 = os.path.expanduser(saveFour)
  356. shutil.move(original4, newlocation4)
  357. # Moves the Mixture Files to Correct Place
  358. original5 = os.path.expanduser("~/Desktop/idbm/" + saveMixtureSTR)
  359. newlocation5 = os.path.expanduser(saveFive)
  360. shutil.move(original5, newlocation5)
  361. original6 = os.path.expanduser("~/Desktop/idbm/" + saveMixtureSTR2)
  362. newlocation6 = os.path.expanduser(saveSix)
  363. shutil.move(original6, newlocation6)
  364. # Moves the Sig Files to Correct Place
  365. original7 = os.path.expanduser("~/Desktop/idbm/" + saveSigSTR)
  366. newlocation7 = os.path.expanduser(saveSeven)
  367. shutil.move(original7, newlocation7)
  368. original8 = os.path.expanduser("~/Desktop/idbm/" + saveSigSTR2)
  369. newlocation8 = os.path.expanduser(saveEight)
  370. shutil.move(original8, newlocation8)
  371. # Moves the Noise Files to Correct Place
  372. original9 = os.path.expanduser("~/Desktop/idbm/" + saveNoiseSTR)
  373. newlocation9 = os.path.expanduser(saveNine)
  374. shutil.move(original9, newlocation9)
  375. original10 = os.path.expanduser("~/Desktop/idbm/" + saveNoiseSTR2)
  376. newlocation10 = os.path.expanduser(saveTen)
  377. shutil.move(original10, newlocation10)
  378.  
  379.  
  380. #Does all of the bss_eval calculations
  381. sources_healthy = [healthy_sig, alpha*noise]
  382. sources_healthy = np.array(sources_healthy)
  383. sdr_healthy, sir_healthy, sar_healthy = bss_eval(sep = healthy_sig_denoised, i=0, sources = sources_healthy)
  384.  
  385. sources_hoarse = [hoarse_sig, alpha*noise]
  386. sources_hoarse = np.array(sources_hoarse)
  387. sdr_hoarse, sir_hoarse, sar_hoarse = bss_eval(sep = hoarse_sig_denoised, i=0, sources = sources_hoarse)
  388.  
  389. # Store the values
  390. SDR_healthy.append( sdr_healthy)
  391. SDR_hoarse.append( sdr_hoarse)
  392. SIR_healthy.append( sir_healthy)
  393. SIR_hoarse.append( sir_hoarse)
  394. SAR_healthy.append( sar_healthy)
  395. SAR_hoarse.append( sar_hoarse)
  396.  
  397. #Save the Values
  398. sigTxt = "Healthy Sound File:" + healthy_selection
  399. noiseTxt = "Noise Sound File:" + noise_selection
  400. sdrVal = "The sdr value is:" + str(sdr_healthy)
  401. sirVal = "The sir value is:" + str(sir_healthy)
  402. sarVal = "The sar value is:" + str(sar_healthy)
  403. txt_file_name = "Results for Healthy at " + string_SNR + "dB.txt"
  404.  
  405.  
  406. txtFile = [sigTxt, noiseTxt,sdrVal,sarVal,sirVal]
  407. if (idx == 0):
  408. text_file = open(txt_file_name, "w")
  409. text_file.close()
  410. text_file_append = open(txt_file_name, "a")
  411.  
  412. for item in txtFile:
  413. text_file_append.write(item)
  414. text_file_append.write('\n')
  415. #Close text file for writing
  416. text_file_append.close()
  417.  
  418. #Creates a string with the name of the folder in which files will be relocated
  419. sigTxt2 = "Hoarse Sound File:" + hoarse_selection
  420. noiseTxt2 = "Noise Sound File:" + noise_selection
  421. sdrVal2 = "The sdr value is:" + str(sdr_hoarse)
  422. sirVal2 = "The sir value is:" + str(sir_hoarse)
  423. sarVal2 = "The sar value is:" + str(sar_hoarse)
  424. txt_file_name2 = "Results for Hoarse at " + string_SNR + "dB.txt"
  425.  
  426. txtFile2 = [sigTxt2, noiseTxt2,sdrVal2,sarVal2,sirVal2]
  427. if (idx == 0):
  428. text_file2 = open(txt_file_name2, "w")
  429. text_file2.close()
  430. text_file2_append = open(txt_file_name2, "a")
  431. for item2 in txtFile2:
  432. text_file2_append.write(item2)
  433. text_file2_append.write('\n')
  434. #Close text file for writing
  435. text_file2_append.close()
  436.  
  437.  
  438. print ("Overall SDR for SNR = ", SNR," dB :", np.median( SDR_healthy), np.median(SDR_hoarse))
  439. print ("Overall SIR for SNR = ", SNR," dB :", np.median( SIR_healthy), np.median(SIR_hoarse))
  440. print ("Overall SAR for SNR = ", SNR," dB :", np.median( SAR_healthy), np.median(SAR_hoarse))
  441.  
  442. # Store to overall lists
  443. SDR_healthy_overall.append( SDR_healthy)
  444. SIR_healthy_overall.append( SIR_healthy)
  445. SAR_healthy_overall.append( SAR_healthy)
  446. SDR_hoarse_overall.append( SDR_hoarse)
  447. SIR_hoarse_overall.append( SIR_hoarse)
  448. SAR_hoarse_overall.append( SAR_hoarse)
  449. with open('bss_evals.pkl', 'wb') as f: # Python 3: open(..., 'wb')
  450. pickle.dump([SDR_healthy_overall, SIR_healthy_overall, SAR_healthy_overall, SDR_hoarse_overall, SIR_hoarse_overall, SAR_hoarse_overall], f)
  451. sns.palplot(sns.color_palette())
  452. df = pd.DataFrame(
  453. {"Speaker": 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] \
  454. + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"], \
  455. "SDR": SDR_healthy_overall[0] + SDR_hoarse_overall[0] + SDR_healthy_overall[1] + SDR_hoarse_overall[1] + SDR_healthy_overall[2] + SDR_hoarse_overall[2] + SDR_healthy_overall[3] + SDR_hoarse_overall[3] + \
  456. SDR_healthy_overall[4] + SDR_hoarse_overall[4] + SDR_healthy_overall[5] + SDR_hoarse_overall[5] + SDR_healthy_overall[6] + SDR_hoarse_overall[6] + SDR_healthy_overall[7] + SDR_hoarse_overall[7] + \
  457. SDR_healthy_overall[8] + SDR_hoarse_overall[8] + SDR_healthy_overall[9] + SDR_hoarse_overall[9] + SDR_healthy_overall[10] + SDR_hoarse_overall[10] , \
  458. "SNR": 80 * [-10] + 80 * [-8] + 80 * [-6] + 80 * [-4] + 80 * [-2] + 80 * [0] + 80 * [2] + 80 * [4] + 80 * [6] + 80 * [8] + 80 * [10]}
  459. )
  460. fig, axs = plt.subplots(nrows=3,figsize=(15,15))
  461.  
  462. ax = sns.pointplot(x='SNR', y='SDR', hue='Speaker', data=df, ax=axs[0], estimator = np.median, dodge = .15, ci = 67)
  463.  
  464. ax.set(ylim=(0, 26))
  465. ax.set(xlabel= 'SNR of mixture (dB)')
  466. ax.set(ylabel= 'SDR ( dB)')
  467.  
  468. df2 = pd.DataFrame(
  469. {"Speaker": 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] \
  470. + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"], \
  471. "SAR": SAR_healthy_overall[0] + SAR_hoarse_overall[0] + SAR_healthy_overall[1] + SAR_hoarse_overall[1] + SAR_healthy_overall[2] + SAR_hoarse_overall[2] + SAR_healthy_overall[3] + SAR_hoarse_overall[3] + \
  472. SAR_healthy_overall[4] + SAR_hoarse_overall[4] + SAR_healthy_overall[5] + SAR_hoarse_overall[5] + SAR_healthy_overall[6] + SAR_hoarse_overall[6] + SAR_healthy_overall[7] + SAR_hoarse_overall[7] + \
  473. SAR_healthy_overall[8] + SAR_hoarse_overall[8] + SAR_healthy_overall[9] + SAR_hoarse_overall[9] + SAR_healthy_overall[10] + SAR_hoarse_overall[10] , \
  474. "SNR": 80 * [-10] + 80 * [-8] + 80 * [-6] + 80 * [-4] + 80 * [-2] + 80 * [0] + 80 * [2] + 80 * [4] + 80 * [6] + 80 * [8] + 80 * [10]}
  475. )
  476.  
  477. # Show me
  478. ax2 = sns.pointplot(x='SNR', y='SAR', hue='Speaker', data=df2, ax=axs[1], estimator = np.median, dodge = .15 , ci = 67)
  479.  
  480. ax2.set(ylim=(0, 26))
  481. ax2.set(xlabel= 'SNR of mixture (dB)')
  482. ax2.set(ylabel= 'SAR ( dB)')
  483.  
  484. df3 = pd.DataFrame(
  485. {"Speaker": 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] \
  486. + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"], \
  487. "SIR": SIR_healthy_overall[0] + SIR_hoarse_overall[0] + SIR_healthy_overall[1] + SIR_hoarse_overall[1] + SIR_healthy_overall[2] + SIR_hoarse_overall[2] + SIR_healthy_overall[3] + SIR_hoarse_overall[3] + \
  488. SIR_healthy_overall[4] + SIR_hoarse_overall[4] + SIR_healthy_overall[5] + SIR_hoarse_overall[5] + SIR_healthy_overall[6] + SIR_hoarse_overall[6] + SIR_healthy_overall[7] + SIR_hoarse_overall[7] + \
  489. SIR_healthy_overall[8] + SIR_hoarse_overall[8] + SIR_healthy_overall[9] + SIR_hoarse_overall[9] + SIR_healthy_overall[10] + SIR_hoarse_overall[10] , \
  490. "SNR": 80 * [-10] + 80 * [-8] + 80 * [-6] + 80 * [-4] + 80 * [-2] + 80 * [0] + 80 * [2] + 80 * [4] + 80 * [6] + 80 * [8] + 80 * [10]}
  491. )
  492.  
  493. # Show me
  494. ax3 = sns.pointplot(x='SNR', y='SIR', hue='Speaker', data=df3, ax=axs[2], estimator = np.median, dodge = .15, ci = 67)
  495.  
  496. ax3.set(ylim=(23, 29))
  497. ax3.set(xlabel= 'SNR of mixture (dB)')
  498. ax3.set(ylabel= 'SIR ( dB)')
  499.  
  500.  
  501.  
  502. fig.savefig("output.eps")
  503. fig.savefig("output.pdf")
  504.  
  505.  
  506.  
  507. getResults()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement