import numpy as np

#SNR in dB
#given a signal and desired SNR, this gives the required AWGN what should be added to the signal to get the desired SNR
def get_white_noise(signal,SNR, sampling_rate) :
    #signal's power
    signal_power = signal**2

    # we know that SNR = 10*log(P_signal/P_noise) so P_noise = P_signal/(10**(SNR/10))
    # As we just need the variance of the noise for our numpy function, we take the square root of the noise Power

    k = np.sqrt(signal_power/10**(SNR/10))

    #Like that we'll have a problem when we'll listen to the noised signal. We need to get the useful frequency band (UB) of the signal and multiply k by Fe/UB where Fe is the sampling frequency. For now we put an arbitrary value of 10kHz
    UB=10000

    k= k*(sampling_rate/UB)
    

    noise=np.random.normal(0, k, signal.shape[0])
    return noise



