コード例 #1
0
import numpy as np
from math import inf, pi, log2

t = np.linspace(0, 0.01, 1000000)
f = 1000

fs = srf.fft_fs(t)
ws = srf.f2w(fs)

v1 = srf.dBm2Vp(-100) * np.sin(srf.f2w(f) * t)
v2 = srf.Vt_noise(t)
v3 = srf.power_combine([v1, v2], t, out_Pf=True)
# print(srf.C(1e-9, ws))
R1 = 1e3
C1 = 10e-9
v4 = v3 * srf.Vdiv(srf.R(R1, ws), srf.C(C1, ws))

# print(srf.w2f(1/(R1*C1)))

# plt.subplot(4,1,1)
# srf.plot_power_spectrum(plt.gca(), t, v1, time = True)
# plt.subplot(4,1,2)
# srf.plot_power_spectrum(plt.gca(), t, v2, time = True)
plt.subplot(2, 1, 1)
srf.plot_power_spectrum(plt.gca(), fs, v3, time=False)
srf.plot_power_spectrum(plt.gca(), fs, v4, time=False)
plt.subplot(2, 1, 2)
plt.plot(t, srf.Pf2Vt(v3, len(t)))
plt.plot(t, srf.Pf2Vt(v4, len(t)))
plt.show()
コード例 #2
0
time = np.arange(N) / fs
# x = amp*np.sin(2*np.pi*freq*time)
x = np.random.normal(scale=np.sqrt(noise_power), size=time.shape)

f, Pxx_spec = signal.periodogram(x, fs, scaling='spectrum')
plt.plot(f, srf.W2dBm(Pxx_spec/50))
df = (f[1] - f[0])
mean_noise = np.mean(srf.mag(Pxx_spec/df))
print(mean_noise)
plt.axhline(srf.W2dBm(mean_noise * df/50), c = 'purple', ls = '-')


V1 = srf.Signal(ns, t_max)
# V1.update_Vt(amp*np.sin(2*np.pi*freq*time))
V1.add_noise(noise = 0.001 /(4 * srf.kB * V1.Z0))
srf.plot_power_spectrum(plt.gca(), V1.fs, V1.Pf)
mean_noise = np.mean(srf.mag(V1.Pf * V1.Z0 / V1.df))
print(mean_noise)
plt.axhline(srf.W2dBm(mean_noise * V1.df/V1.Z0), c = 'k', ls = '--')


# srf.plot_power_spectrum(plt.gca(), V1.ts, np.random.normal(0, 1, len(V1.ts)), time = True)

# f_ref =  [0, 4, 5, 8.3, 12] # log frequency
# Fa_ref = [270, 150, 80, 0, 0] # Fa = 10*log10(T_noise/t0)
#
# T_noise = srf.undB(np.interp(np.log10(np.maximum(V1.fs,np.ones(len(V1.fs)))), f_ref, Fa_ref)) * srf.t0 # weird thing with ones to avoid log(0)
# plt.plot(V1.fs, srf.W2dBm(srf.kB*T_noise))
#
# plt.subplot(2,1,2)
# plt.plot(V1.ts, V1.Vt)
コード例 #3
0
    syms, p_syms = srf.demod_fsk(v1.Vt, v1.ts, fc, f_sym, f_dev, n = n, f_sample = f_sample)#, quantize_func = srf.quantize_adc, V_full = V_pk, n_bits = 12)

    # print(random_data[:len(syms)])
    # print(syms)
    errs = ''.join(['0' if syms[i] == random_data[i] else '1' for i in range(len(syms))])
    print('{} / {}'.format(errs.count('1'), len(syms)))
    n_errs = n_errs + errs.count('1')
    # print(errs)

print('{} / {} ({:e})'.format(n_errs, n_tests * test_bits, n_errs/(n_tests * test_bits)))


###############

srf.plot_power_spectrum(plt.gca(), v1.ts, v1.Vt, time = True)
plt.show()

###############

# plt.subplot(2,1,1)
# plt.plot(np.arange(min(v1.ts), max(v1.ts), 1/f_sym) + 0.5/f_sym, p_syms)
#
# for i in range(len(random_data)):
#     plt.axvline((i+1)*(1/f_sym), color = 'black', ls = '--')
#
# plt.xlim(min(v1.ts), max(v1.ts))
#
# plt.subplot(2,1,2)
# plt.plot(v1.ts, v1.Vt)
# plt.show()
コード例 #4
0
f_dev = h / (2 * T_bit)
print(f_dev)

t = np.linspace(0, len(data) * T_bit - T_bit / 100, 100000)
fs = srf.fft_fs(t)
ws = srf.f2w(fs)

# v1, inverted, df, odd, even, plt_data = srf.V_msk(t, f, f_bit, data, -100)
v1 = srf.V_msk(t, f, f_bit, data, -100)
v2 = srf.Vt_noise(t)
v3 = srf.power_combine([v1, v2], t, out_Pf=True)

R1 = 1e3
C1 = 10e-9
v4 = v3 * srf.Pdiv(srf.R(R1, ws), srf.C(C1, ws))

plt.subplot(2, 1, 1)
srf.plot_power_spectrum(plt.gca(), t, v1, time=True)
# srf.plot_power_spectrum(plt.gca(), fs, v4, time = False)
plt.subplot(2, 1, 2)
plt.plot(t, v1)
# plt.plot(t,inverted, c = 'red')
# plt.plot(t,df*1.1, c = 'green')
# plt.plot(t,odd*1.2, c = 'purple')
# plt.plot(t,even*1.3, c = 'gold')
# plt.plot(t,plt_data*1.4, c = 'orange')

for i in range(len(data)):
    plt.axvline(T_bit * i, ls='--', c='black')
plt.show()