spkit.add_noise

spkit.add_noise(x, snr_db=10, return_noise=False)

Add Gaussian Noise to Signal

Add Gaussian Noise to Signal

SNR = sig_pw/noise_pw SNR_db = sig_pw_db - noise_pw_db

noise_pw = sig_pw/SNR noise_pw = 10**( (sig_pw_db-SNR_db)/10 )

noise ~ N(0, sqrt(noise_pw))

Parameters:
x: nd array
  • input signal, 1d or multi-dimensional

snr_db: scalar
  • Desired Signal to Noise Ratio (SNR) in Decible (dB)

return_noise: bool, default=False
  • if True, returns the added noise

Returns:
y: array, same shape as x
  • Noisy signal

Notes

#TODO

Examples

import numpy as np
import matplotlib.pyplot as plt
import spkit as sp
np.random.seed(1)
t = np.linspace(0,2,200)
x = np.cos(2*np.pi*1*t)
SNRs = [30,20,10,5,0]
plt.figure(figsize=(10,5))
plt.plot(t,x,label=f'x: signal')
for i,snr in enumerate(SNRs):
    plt.plot(t,sp.add_noise(x,snr)-(i+1)*2,label=f'SNR = {snr} dB')

plt.xlim([t[0],t[-1]])
plt.legend(bbox_to_anchor=(1,1))
plt.grid()
plt.yticks([])
np.random.seed(None)
plt.tight_layout()
plt.show()
../../_images/spkit-add_noise-1.png

Examples using spkit.add_noise

Ramanujan Dictionary - with sparse penalty

Ramanujan Dictionary - with sparse penalty

Ramanujan Filter Banks Example

Ramanujan Filter Banks Example