谱减法(二)
由于第一种谱减法中存在音乐噪声难以去除,故利用过减法来进一步去除噪声。
#subtract the noise power from the noisy power
#use over_subtraction method to enhance the signal
alpha = 4
gamma = 1
beta = 0.0001
power_enhanc = np.power(power_noisy, gamma) - alpha * np.power(power_noise, gamma)
power_enhanc = np.power(power_enhanc, 1/gamma)
#use beta*power_noise to instead of small negative values
mask = (power_enhanc >= beta * power_noise) - 0
print(mask.shape)
power_enhanc = mask * power_enhanc + (1-mask) * beta * power_noise
Mag_enhanc = np.sqrt(power_enhanc)
主要实现如图所示


由于过减,造成其谱线不连续,所以要进行平滑机制
最大噪声残差
## introduce the smoothing method to enhance the signal
Mag_noisy_new = np.copy(Mag_noisy)
k = 1
for t in range(k,T-k):
Mag_noisy_new[:,t] = np.mean(Mag_noisy[:,t-k:t+k+1], axis=1)
power_noisy = Mag_noisy_new**2
# compute the max
Mag_enhanc_new = np.copy(Mag_enhanc)
maxnr = np.max(np.abs(noisy_stft[:,:31])-Mag_noise,axis = 1)
k = 1
for t in range(k,T-k):
index =np.where(Mag_enhanc[:,t] < maxnr)[0]
temp =np.min(Mag_enhanc[:,t-k:t+k+1], axis=1)
Mag_enhanc_new[index,t] = temp[index]
enhanc_stft = Mag_enhanc_new * np.exp(1j*Phase_noisy)
enhanc = librosa.istft(enhanc_stft, hop_length=128,win_length=256)
sf.write("enhanc3.wav", enhanc, fs)
print(fs)


降噪效果得到明显改善