コード例 #1
0
import numpy as np
import pynoise

# --- Input ---
m = 10
n = 3

# Noise
SNR = 20

# --- Definitions ---
# Matrix
A = np.random.randint(-10, 10, (m, n))

# Corrupted signal
An, ns = pynoise.awgn(A, SNR, out='both', method='vectorized')

# --- Check actual SNR ---
# Signal power, dB
Ps = 10 * np.log10(np.sum(A**2))

# Noise power, dB
Pn = 10 * np.log10(np.sum(ns**2))

# Actual SNR
SNRa = Ps - Pn
print('Desired SNR: ', SNR)
print('Actual SNR: ', SNRa)
コード例 #2
0
import matplotlib.pyplot as plt
plt.ion()

# --- Input ---
N = 1000

# Noise
SNR = 30

# --- Signals ---
t = np.arange(N)

A = np.zeros((N, 3))
A[:, 0] = 0.8*t
A[:, 1] = 1.0*t
A[:, 2] = 1.3*t

# --- Noise ---
An = pynoise.awgn(A, SNR, method='max_en')
ns = A - An

# --- Check actual SNR ---
Em_dB = 10*np.log10(np.sum(A**2, axis=0))
En_dB = 10*np.log10(np.sum(ns**2, axis=0))
SNR_dB = Em_dB - En_dB

print('\nSNR 1st column: %.2f dB' % SNR_dB[0])
print('\nSNR 2nd column: %.2f dB' % SNR_dB[1])
print('\nSNR 3rd column: %.2f dB' % SNR_dB[2])
コード例 #3
0
cycles = 5
dc = 1
ac = 1

# Noise
SNR = 40

# --- Definitions ---
# Time
t = np.arange(0, cycles / f, 1 / fs)

# Signal
s = dc + ac * np.sin(2 * np.pi * f * t)

# Corrupted signal
sn, n = pynoise.awgn(s, SNR, out='both')

# --- Check actual SNR ---
# Signal power, dB
Ps = 10 * np.log10(sum(s**2 / len(s)))

# Noise power, dB
Pn = 10 * np.log10(sum(n**2 / len(n)))

# Actual SNR
SNRa = Ps - Pn
print('Desired SNR: ', SNR)
print('Actual SNR: ', SNRa)

# --- Difference ---
e = s - sn
コード例 #4
0
import numpy as np
import pynoise
import matplotlib.pyplot as plt

# --- Signal ---
t = np.arange(0, 1, 0.01)

x = t
xn = pynoise.awgn(x, 30)

# --- Plots ---
plt.figure(figsize=(10,6))
plt.plot(t, x, label='Original signal')
plt.plot(t, xn,  label='Corrupted signal')
plt.grid()
plt.xlabel('t')
plt.ylabel('x')
plt.legend()
plt.show()
コード例 #5
0
f_cos = 10
a_cos = 2
d_cos = -0.5

# Noise
SNR = 30

# --- Signals ---
t_ramp = np.arange(N)
x_ramp = a_ramp*t_ramp + b_ramp

t_cos = (1/fs_cos)*np.arange(N)
x_cos = d_cos + a_cos*np.cos(2*np.pi*f_cos*t_cos)

# --- Noise ---
xn_ramp = pynoise.awgn(x_ramp, SNR, method='vectorized')
n_ramp = x_ramp - xn_ramp

xn_cos = pynoise.awgn(x_cos, SNR, method='vectorized')
n_cos = x_cos - xn_cos

# --- Check actual SNR ---
print('\nDesired SNR: %.2f' % SNR)

# Ramp signal
Es_ramp_dB = 10*np.log10(np.sum(x_ramp**2))
En_ramp_dB = 10*np.log10(np.sum(n_ramp**2))
SNR_ramp_dB = Es_ramp_dB - En_ramp_dB
print('\nRamp signal SNR: %.2f dB' % SNR_ramp_dB)

# Cossine signal
コード例 #6
0
"""
import numpy as np
import pynoise

# --- Input ---
m = 100
n = 3

# Bounds
lower_b = -15
upper_b = 15

# Noise
SNR = 30

# --- Signals ---
A = np.random.randint(lower_b, upper_b, (m, n))

# --- Noise ---
An = pynoise.awgn(A, SNR, method='vectorized')
ns = A - An

# --- Check actual SNR ---
Em_dB = 10 * np.log10(np.sum(A**2))
En_dB = 10 * np.log10(np.sum(ns**2))
SNR_dB = Em_dB - En_dB

print('\nDesired SNR: %.2f dB' % SNR)
print('\nComputed SNR: %.2f dB' % SNR_dB)