-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoise_comp.py
More file actions
25 lines (16 loc) · 798 Bytes
/
noise_comp.py
File metadata and controls
25 lines (16 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
from scipy.io.wavfile import write, read
file, audio = read('Data\\test\\something-1.wav')
RMS_noise = math.sqrt(np.mean(signal ** 2)) # Root mean squred of signal
def get_white_noise(audio, Signal_to_noise_ratio):
RMS_s = math.sqrt(np.mean(signal ** 2))
RMS_n = math.sqrt(RMS_s ** 2 / (pow(10, Signal_to_noise_ratio / 10)))
STD_n = RMS_n
white_noise = np.random.normal(0, STD_n, audio.shape[0])
return white_noise
# Additive White Gaussian Noise (AWGN)
audio = np.interp(audio, (audio.min(), audio.max()), (-1, 1))
white_noise = get_white_noise(audio, Signal_to_noise_ratio=10)
# analyze the frequency components in the signal
audio_white_noise = audio + white_noise
write("something_Noise-1.wav", file, audio_white_noise)