Last active
November 18, 2021 02:09
-
-
Save jonashaag/677e1ddab99f3daba367de9ec022e942 to your computer and use it in GitHub Desktop.
Python cIRM (Complex Ideal Ratio Mask), ORM (Optimal Ratio Mask), IRM (Ideal Ratio Mask), PSM (Phase Sensitive Mask)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cirm(y, s, K=10, C=0.1, flat=True): | |
y = librosa.core.stft(y.astype('float64'), 256, 64).astype('complex128') | |
s = librosa.core.stft(s.astype('float64'), 256, 64).astype('complex128') | |
mr = (np.real(y) * np.real(s) + np.imag(y) * np.imag(s))/(np.real(y)**2 + np.imag(y)**2) | |
mi = (np.real(y) * np.imag(s) - np.imag(y) * np.real(s))/(np.real(y)**2 + np.imag(y)**2) | |
m = mr + 1j * mi | |
if flat: | |
return m | |
else: | |
return K * ((1 - np.exp(-C * m))/(1 + np.exp(-C * m))) | |
def inverse_mask(x, m, K=10, C=0.1, flat=True): | |
if flat: | |
return x * m | |
else: | |
return -1/C * np.log((K - x)/(K+x)) | |
def psm(y, s): | |
y = librosa.core.stft(y.astype('float64'), 256, 64).astype('complex128') | |
s = librosa.core.stft(s.astype('float64'), 256, 64).astype('complex128') | |
return np.abs(y) / np.abs(s) * np.cos(np.angle(y) + np.angle(s)) | |
def orm(y, n, K=10, C=0.1, flat=False): | |
y = librosa.core.stft(y.astype('float64'), 256, 64).astype('complex128') | |
n = librosa.core.stft(n.astype('float64'), 256, 64).astype('complex128') | |
m = (np.abs(y)**2 + np.real(y * np.conj(n))) / (np.abs(y)**2 + np.abs(n)**2 + 2 * np.real(y * np.conj(n))) | |
if flat: | |
return m | |
else: | |
return K * ((1 - np.exp(-C * m))/(1 + np.exp(-C * m))) | |
def irm(y, n): | |
y = librosa.core.stft(y.astype('float64'), 256, 64).astype('complex128') | |
n = librosa.core.stft(n.astype('float64'), 256, 64).astype('complex128') | |
return (np.abs(y) ** 2 / (np.abs(y) ** 2 + np.abs(n) ** 2)) ** 0.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment