Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.17 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.  
  168. print('Starting for SNR: ', SNR, ' dB')
  169.  
  170.  
  171. alpha = 10 ** (-SNR/20)
  172.  
  173. for idx in arange(40):
  174.  
  175. #gets a random selection from the healthy_files, hoarse_files, noise_files
  176. healthy_selection = random.choice( healthy_files)
  177. hoarse_selection = random.choice( hoarse_files)
  178. noise_selection = random.choice (noise_files)
  179.  
  180. #gets the names without .wav ending
  181. healthy_Stripped = healthy_selection.strip(".wav")
  182. hoarse_Stripped = hoarse_selection.strip(".wav")
  183. noise_Stripped = noise_selection.strip(".wav")
  184.  
  185. sr, healthy_sig = wavread(healthy_Folder + os.sep + healthy_selection)
  186. sr2, hoarse_sig = wavread(hoarse_Folder + os.sep + hoarse_selection)
  187. sr3, noise = wavread(noise_Folder + os.sep + noise_selection)
  188.  
  189. # Load 'em'
  190. healthy_sig = healthy_sig.astype( float)/32768
  191. hoarse_sig = hoarse_sig.astype( float)/32768
  192. noise = noise.astype( float)/32768
  193.  
  194. # Trim them to the same length
  195. l = min( [len( healthy_sig), len( hoarse_sig), len( noise)])
  196. healthy_sig = healthy_sig[:l]
  197. hoarse_sig = hoarse_sig[:l]
  198.  
  199. # Use random starting point for noise
  200. noise_start = random.choice( arange( len( noise)-l-1))
  201. noise = noise[int( noise_start):int(noise_start+l)]
  202.  
  203. # Normalize to zero mean and unit variance
  204. healthy_sig = ( healthy_sig - np.mean( healthy_sig))/np.std( healthy_sig)
  205. hoarse_sig = ( hoarse_sig - np.mean( hoarse_sig))/np.std( hoarse_sig)
  206. noise = ( noise - np.mean( noise))/np.std( noise)
  207.  
  208. #Naming Convention for Saving Original Noise and Signal at given dB values
  209. saveNoiseSTR = healthy_Stripped + "_" + hoarse_Stripped + "_healthy_orignoise.wav"
  210. saveNoiseSTR2 = healthy_Stripped + "_" + hoarse_Stripped + "_hoarse_orignoise.wav"
  211. saveSigSTR = healthy_Stripped + "_" + hoarse_Stripped + "_origsig.wav"
  212. saveSigSTR2 = healthy_Stripped + "_" + hoarse_Stripped + "_origsig2.wav"
  213.  
  214. # saves the noise files used
  215. scipy.io.wavfile.write(
  216. saveNoiseSTR,
  217. sr,
  218. noise / max(abs(noise) + 0.01),
  219. )
  220. scipy.io.wavfile.write(
  221. saveNoiseSTR2, sr, noise / max(abs(noise) + 0.01)
  222. )
  223. # saves all the signal files used
  224. scipy.io.wavfile.write(
  225. saveSigSTR, sr, healthy_sig / max(abs(healthy_sig) + 0.01)
  226. )
  227. scipy.io.wavfile.write(
  228. saveSigSTR2, sr, hoarse_sig / max(abs(hoarse_sig) + 0.01)
  229. )
  230.  
  231. # Make mixture
  232. healthy_mix = healthy_sig + alpha*noise
  233. hoarse_mix = hoarse_sig + alpha*noise
  234.  
  235. # saves mixtures
  236. saveMixtureSTR = (
  237. healthy_Stripped + "_" + noise_Stripped + "_healthy_mixture.wav"
  238. )
  239. saveMixtureSTR2 = (
  240. hoarse_Stripped + "_" + noise_Stripped + "_hoarse_mixture.wav"
  241. )
  242. scipy.io.wavfile.write(
  243. saveMixtureSTR, sr, healthy_mix / max(abs(healthy_mix) + 0.01)
  244. )
  245. scipy.io.wavfile.write(
  246. saveMixtureSTR2, sr, hoarse_mix / max(abs(hoarse_mix) + 0.01)
  247. )
  248.  
  249.  
  250. # stft params
  251. sz = int( 2**rint( log2(sr/16)))
  252. hp = sz//4
  253. win = hanning( sz+1)[:-1]
  254. eps = 1e-4
  255.  
  256. # Transform mixtures
  257. healthy_mix_stft = stft( healthy_mix, nperseg=sz, noverlap=sz-hp, window=win)[2]
  258. healthy_mix_a, healthy_mix_p = abs( healthy_mix_stft), healthy_mix_stft/( abs( healthy_mix_stft) + eps)
  259.  
  260. hoarse_mix_stft = stft( hoarse_mix, nperseg=sz, noverlap=sz-hp, window=win)[2]
  261. hoarse_mix_a, hoarse_mix_p = abs( hoarse_mix_stft), hoarse_mix_stft/( abs( hoarse_mix_stft) + eps)
  262.  
  263. # Transform ground truths
  264. healthy_sig_stft = stft( healthy_sig, nperseg=sz, noverlap=sz-hp, window=win)[2]
  265. healthy_sig_a, healthy_sig_p = abs( healthy_sig_stft), healthy_sig_stft/( abs( healthy_sig_stft) + eps)
  266.  
  267. hoarse_sig_stft = stft( hoarse_sig, nperseg=sz, noverlap=sz-hp, window=win)[2]
  268. hoarse_sig_a, hoarse_sig_p = abs( hoarse_sig_stft), hoarse_sig_stft/( abs( hoarse_sig_stft) + eps)
  269.  
  270. ########################## Possible change here.... are you doing this correctly......???????????????? ###############################
  271. noise_stft = stft( alpha*noise, nperseg=sz, noverlap=sz-hp, window=win)[2]
  272. noise_a, noise_p = abs( noise_stft), noise_stft/( abs( noise_stft) + eps)
  273.  
  274. # Estimate Ideal Binary Masks
  275. healthy_mask = ( healthy_sig_a > noise_a)
  276. hoarse_mask = ( hoarse_sig_a > noise_a)
  277.  
  278. # Invert 'em'
  279. healthy_sig_denoised = istft( healthy_mask * healthy_mix_stft, nperseg=sz, noverlap=sz-hp, window=win)[1]
  280. hoarse_sig_denoised = istft( hoarse_mask * hoarse_mix_stft, nperseg=sz, noverlap=sz-hp, window=win)[1]
  281.  
  282. #Naming Convention for saved files
  283. saveProcessedSTR = (
  284. healthy_Stripped + "_" + noise_Stripped + "_healthy_processed.wav"
  285. )
  286. saveProcessedSTR2 = (
  287. hoarse_Stripped + "_" + noise_Stripped + "_hoarse_processed.wav"
  288. )
  289. # saves the files
  290. scipy.io.wavfile.write(
  291. saveProcessedSTR,
  292. sr,
  293. healthy_sig_denoised / max(abs(healthy_sig_denoised) + 0.01),
  294. )
  295. scipy.io.wavfile.write(
  296. saveProcessedSTR2,
  297. sr,
  298. hoarse_sig_denoised / max(abs(hoarse_sig_denoised) + 0.01),
  299. )
  300.  
  301. # Take the shortest lenght of arr to get estimated Noise
  302. l2 = min(len(healthy_mix), len(healthy_sig_denoised))
  303. l3 = min(len(hoarse_mix), len(hoarse_sig_denoised))
  304. healthy_sig_length = healthy_mix[:l2]
  305. healthy_noise_length = healthy_sig_denoised[:l2]
  306. hoarse_sig_length = hoarse_mix[:l3]
  307. hoarse_noise_length = hoarse_sig_denoised[:l3]
  308. # Calculate the Estimated Noise
  309. recHealthy = healthy_sig_length - healthy_noise_length
  310. recNoise = hoarse_sig_length - hoarse_noise_length
  311.  
  312. # Saves Estimated Noise
  313. saveRecNoiseSTR = (
  314. healthy_Stripped + "_" + noise_Stripped + "_healthy_noise_recovered.wav"
  315. )
  316. saveRecNoiseSTR2 = (
  317. hoarse_Stripped + "_" + noise_Stripped + "_hoarse_noise_recovered.wav"
  318. )
  319.  
  320. # Saves the Estimated Noise Files
  321. scipy.io.wavfile.write(
  322. saveRecNoiseSTR, sr, recHealthy / max(abs(recHealthy) + 0.01)
  323. )
  324. scipy.io.wavfile.write(
  325. saveRecNoiseSTR2, sr, recNoise / max(abs(recNoise) + 0.01)
  326. )
  327.  
  328. ####### Moves all of the files ####################
  329. saveOne = arr[0] + os.sep + saveRecNoiseSTR
  330. saveTwo = arr[1] + os.sep + saveRecNoiseSTR2
  331. saveThree = arr[2] + os.sep + saveProcessedSTR
  332. saveFour = arr[3] + os.sep + saveProcessedSTR2
  333. saveFive = arr[4] + os.sep + saveMixtureSTR
  334. saveSix = arr[5] + os.sep + saveMixtureSTR2
  335. saveSeven = arr[6] + os.sep + saveSigSTR
  336. saveEight = arr[7] + os.sep + saveSigSTR2
  337. saveNine = arr[8] + os.sep + saveNoiseSTR
  338. saveTen = arr[9] + os.sep + saveNoiseSTR2
  339. # Moves the Recovered Noise Files to Correct Place
  340. original = os.path.expanduser("~/Desktop/idbm/" + saveRecNoiseSTR)
  341. newlocation = os.path.expanduser(saveOne)
  342. shutil.move(original, newlocation)
  343. original2 = os.path.expanduser("~/Desktop/idbm/" + saveRecNoiseSTR2)
  344. newlocation2 = os.path.expanduser(saveTwo)
  345. shutil.move(original2, newlocation2)
  346. # Moves the Recovered Sig Files to Correct Place
  347. original3 = os.path.expanduser("~/Desktop/idbm/" + saveProcessedSTR)
  348. newlocation3 = os.path.expanduser(saveThree)
  349. shutil.move(original3, newlocation3)
  350. original4 = os.path.expanduser("~/Desktop/idbm/" + saveProcessedSTR2)
  351. newlocation4 = os.path.expanduser(saveFour)
  352. shutil.move(original4, newlocation4)
  353. # Moves the Mixture Files to Correct Place
  354. original5 = os.path.expanduser("~/Desktop/idbm/" + saveMixtureSTR)
  355. newlocation5 = os.path.expanduser(saveFive)
  356. shutil.move(original5, newlocation5)
  357. original6 = os.path.expanduser("~/Desktop/idbm/" + saveMixtureSTR2)
  358. newlocation6 = os.path.expanduser(saveSix)
  359. shutil.move(original6, newlocation6)
  360. # Moves the Sig Files to Correct Place
  361. original7 = os.path.expanduser("~/Desktop/idbm/" + saveSigSTR)
  362. newlocation7 = os.path.expanduser(saveSeven)
  363. shutil.move(original7, newlocation7)
  364. original8 = os.path.expanduser("~/Desktop/idbm/" + saveSigSTR2)
  365. newlocation8 = os.path.expanduser(saveEight)
  366. shutil.move(original8, newlocation8)
  367. # Moves the Noise Files to Correct Place
  368. original9 = os.path.expanduser("~/Desktop/idbm/" + saveNoiseSTR)
  369. newlocation9 = os.path.expanduser(saveNine)
  370. shutil.move(original9, newlocation9)
  371. original10 = os.path.expanduser("~/Desktop/idbm/" + saveNoiseSTR2)
  372. newlocation10 = os.path.expanduser(saveTen)
  373. shutil.move(original10, newlocation10)
  374.  
  375.  
  376. #Does all of the bss_eval calculations
  377. sources_healthy = [healthy_sig, alpha*noise]
  378. sources_healthy = np.array(sources_healthy)
  379. sdr_healthy, sir_healthy, sar_healthy = bss_eval(sep = healthy_sig_denoised, i=0, sources = sources_healthy)
  380.  
  381. sources_hoarse = [hoarse_sig, alpha*noise]
  382. sources_hoarse = np.array(sources_hoarse)
  383. sdr_hoarse, sir_hoarse, sar_hoarse = bss_eval(sep = hoarse_sig_denoised, i=0, sources = sources_hoarse)
  384.  
  385. # Store the values
  386. SDR_healthy.append( sdr_healthy)
  387. SDR_hoarse.append( sdr_hoarse)
  388. SIR_healthy.append( sir_healthy)
  389. SIR_hoarse.append( sir_hoarse)
  390. SAR_healthy.append( sar_healthy)
  391. SAR_hoarse.append( sar_hoarse)
  392.  
  393. #Save the Values
  394. sigTxt = "Healthy Sound File:" + healthy_selection
  395. noiseTxt = "Noise Sound File:" + noise_selection
  396. sdrVal = "The sdr value is:" + str(sdr_healthy)
  397. sirVal = "The sir value is:" + str(sir_healthy)
  398. sarVal = "The sar value is:" + str(sar_healthy)
  399. txt_file_name = "Results for Healthy at " + string_SNR + "dB.txt"
  400.  
  401.  
  402. txtFile = [sigTxt, noiseTxt,sdrVal,sarVal,sirVal]
  403. if (idx == 0):
  404. text_file = open(txt_file_name, "w")
  405. text_file.close()
  406. text_file_append = open(txt_file_name, "a")
  407.  
  408. for item in txtFile:
  409. text_file_append.write(item)
  410. text_file_append.write('\n')
  411. #Close text file for writing
  412. text_file_append.close()
  413.  
  414. #Creates a string with the name of the folder in which files will be relocated
  415. sigTxt2 = "Hoarse Sound File:" + hoarse_selection
  416. noiseTxt2 = "Noise Sound File:" + noise_selection
  417. sdrVal2 = "The sdr value is:" + str(sdr_hoarse)
  418. sirVal2 = "The sir value is:" + str(sir_hoarse)
  419. sarVal2 = "The sar value is:" + str(sar_hoarse)
  420. txt_file_name2 = "Results for Hoarse at " + string_SNR + "dB.txt"
  421.  
  422. txtFile2 = [sigTxt2, noiseTxt2,sdrVal2,sarVal2,sirVal2]
  423. if (idx == 0):
  424. text_file2 = open(txt_file_name2, "w")
  425. text_file2.close()
  426. text_file2_append = open(txt_file_name2, "a")
  427. for item2 in txtFile2:
  428. text_file2_append.write(item2)
  429. text_file2_append.write('\n')
  430. #Close text file for writing
  431. text_file2_append.close()
  432.  
  433.  
  434. print ("Overall SDR for SNR = ", SNR," dB :", np.median( SDR_healthy), np.median(SDR_hoarse))
  435. print ("Overall SIR for SNR = ", SNR," dB :", np.median( SIR_healthy), np.median(SIR_hoarse))
  436. print ("Overall SAR for SNR = ", SNR," dB :", np.median( SAR_healthy), np.median(SAR_hoarse))
  437.  
  438. # Store to overall lists
  439. SDR_healthy_overall.append( SDR_healthy)
  440. SIR_healthy_overall.append( SIR_healthy)
  441. SAR_healthy_overall.append( SAR_healthy)
  442. SDR_hoarse_overall.append( SDR_hoarse)
  443. SIR_hoarse_overall.append( SIR_hoarse)
  444. SAR_hoarse_overall.append( SAR_hoarse)
  445. with open('bss_evals.pkl', 'wb') as f: # Python 3: open(..., 'wb')
  446. pickle.dump([SDR_healthy_overall, SIR_healthy_overall, SAR_healthy_overall, SDR_hoarse_overall, SIR_hoarse_overall, SAR_hoarse_overall], f)
  447. sns.palplot(sns.color_palette())
  448. df = pd.DataFrame(
  449. {"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"] \
  450. + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"], \
  451. "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] + \
  452. 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] + \
  453. SDR_healthy_overall[8] + SDR_hoarse_overall[8] + SDR_healthy_overall[9] + SDR_hoarse_overall[9] + SDR_healthy_overall[10] + SDR_hoarse_overall[10] , \
  454. "SNR": 80 * [-10] + 80 * [-8] + 80 * [-6] + 80 * [-4] + 80 * [-2] + 80 * [0] + 80 * [2] + 80 * [4] + 80 * [6] + 80 * [8] + 80 * [10]}
  455. )
  456. fig, axs = plt.subplots(nrows=3,figsize=(15,15))
  457.  
  458. ax = sns.pointplot(x='SNR', y='SDR', hue='Speaker', data=df, ax=axs[0], estimator = np.median, dodge = .15, ci = 67)
  459.  
  460. ax.set(ylim=(0, 26))
  461. ax.set(xlabel= 'SNR of mixture (dB)')
  462. ax.set(ylabel= 'SDR ( dB)')
  463.  
  464. df2 = pd.DataFrame(
  465. {"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"] \
  466. + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"], \
  467. "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] + \
  468. 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] + \
  469. SAR_healthy_overall[8] + SAR_hoarse_overall[8] + SAR_healthy_overall[9] + SAR_hoarse_overall[9] + SAR_healthy_overall[10] + SAR_hoarse_overall[10] , \
  470. "SNR": 80 * [-10] + 80 * [-8] + 80 * [-6] + 80 * [-4] + 80 * [-2] + 80 * [0] + 80 * [2] + 80 * [4] + 80 * [6] + 80 * [8] + 80 * [10]}
  471. )
  472.  
  473. # Show me
  474. ax2 = sns.pointplot(x='SNR', y='SAR', hue='Speaker', data=df2, ax=axs[1], estimator = np.median, dodge = .15 , ci = 67)
  475.  
  476. ax2.set(ylim=(0, 26))
  477. ax2.set(xlabel= 'SNR of mixture (dB)')
  478. ax2.set(ylabel= 'SAR ( dB)')
  479.  
  480. df3 = pd.DataFrame(
  481. {"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"] \
  482. + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"] + 40 * ["Healthy"] + 40 * ["Hoarse"], \
  483. "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] + \
  484. 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] + \
  485. SIR_healthy_overall[8] + SIR_hoarse_overall[8] + SIR_healthy_overall[9] + SIR_hoarse_overall[9] + SIR_healthy_overall[10] + SIR_hoarse_overall[10] , \
  486. "SNR": 80 * [-10] + 80 * [-8] + 80 * [-6] + 80 * [-4] + 80 * [-2] + 80 * [0] + 80 * [2] + 80 * [4] + 80 * [6] + 80 * [8] + 80 * [10]}
  487. )
  488.  
  489. # Show me
  490. ax3 = sns.pointplot(x='SNR', y='SIR', hue='Speaker', data=df3, ax=axs[2], estimator = np.median, dodge = .15, ci = 67)
  491.  
  492. ax3.set(ylim=(23, 29))
  493. ax3.set(xlabel= 'SNR of mixture (dB)')
  494. ax3.set(ylabel= 'SIR ( dB)')
  495.  
  496.  
  497.  
  498. fig.savefig("output.eps")
  499. fig.savefig("output.pdf")
  500.  
  501.  
  502.  
  503. getResults()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement