Example #1
0
                          Fs=fphi,
                          NFFT=NFFT,
                          noverlap=NFFT / 2,
                          scale_by_freq=True)
print('@2nd signal)')

print("Check overall power from psd")
print(" (should be 1): ", end="")
df = freqs[1] - freqs[0]
print(np.sum(psd) * df)

# Plot PDS of signal at modulator output
# This is the same as in Fig. 5b
# Try to express quantities in dBm (referred to 1 mW over a 50 Ohm resistor)
plt.figure()
plt.plot(freqs, dbp(psd) + 30 - 10 * np.log10(50))
plt.xlim(0, fphi / 2)
plt.xlabel(r'$f$ [MHz]', x=1.)
plt.ylabel(r'PDS [dBm/Hz]')
plt.gca().set_xticks([0, fphi / 2])
plt.gca().set_xticklabels(['$0$', r'$2.56$'])
plt.suptitle('PSD at modulator output')

# Plot PDS of first reconstructed signal
plt.figure()
plt.plot(freqs1, dbp(psd1))
plt.xscale('log', base=10)
plt.suptitle('PSD of reconstructed signal - 1st signal')

# Plot PDS of second reconstructed signal
plt.figure()
Example #2
0
sig_pow = A**2 / 2  # Input signal power
# Output signal power at 3 slip conditions
sig_pow_0043 = sig_pow * np.abs(
    evalTF(hz0043, np.exp(2j * np.pi * fmot / fphi)))**2
sig_pow_02 = sig_pow * np.abs(evalTF(hz02, np.exp(
    2j * np.pi * fmot / fphi)))**2
sig_pow_06 = sig_pow * np.abs(evalTF(hz06, np.exp(
    2j * np.pi * fmot / fphi)))**2

print("Noise power and SNR for motor at slip=0.043")
print("ntf0043\tntf02\tntf06\tdelsig")
print("{:.4e}\t{:.4e}\t{:.4e}\t{:.4e}".format(n_pow_0043_0043, n_pow_0043_02,
                                              n_pow_0043_06,
                                              n_pow_0043_delsig))
print("{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB".format(
    dbp(sig_pow_0043 / n_pow_0043_0043), dbp(sig_pow_0043 / n_pow_0043_02),
    dbp(sig_pow_0043 / n_pow_0043_06), dbp(sig_pow_0043 / n_pow_0043_delsig)))
print("Noise power and SNR for motor at slip=0.2")
print("ntf0043\tntf02\tntf06\tdelsig")
print("{:.4e}\t{:.4e}\t{:.4e}\t{:.4e}".format(n_pow_02_0043, n_pow_02_02,
                                              n_pow_02_06, n_pow_02_delsig))
print("{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB".format(
    dbp(sig_pow_02 / n_pow_02_0043), dbp(sig_pow_02 / n_pow_02_02),
    dbp(sig_pow_02 / n_pow_02_06), dbp(sig_pow_02 / n_pow_02_delsig)))
print("Noise power and SNR for motor at slip=0.6")
print("ntf0043\tntf02\tntf06\tdelsig")
print("{:.4e}\t{:.4e}\t{:.4e}\t{:.4e}".format(n_pow_06_0043, n_pow_06_02,
                                              n_pow_06_06, n_pow_06_delsig))
print("{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB".format(
    dbp(sig_pow_06 / n_pow_06_0043), dbp(sig_pow_06 / n_pow_06_02),
    dbp(sig_pow_06 / n_pow_06_06), dbp(sig_pow_06 / n_pow_06_delsig)))
# Prepare frequency axis for plotting
fmin = 10**np.ceil(np.log10(B/OSR/100))
fmax = fphi/2
ff = np.logspace(np.log10(fmin), np.log10(fmax), 1000)

resp_w1 = np.asarray(map(w1, ff/fphi))
resp_ntf1 = np.abs(evalTF(ntf1, np.exp(1j*2*np.pi*ff/fphi)))
resp_w2 = np.asarray(map(w2, ff/fphi))
resp_ntf2 = np.abs(evalTF(ntf2, np.exp(1j*2*np.pi*ff/fphi)))

ffa = np.logspace(np.log10(0.5E-5), np.log10(0.5), 1024)
vv_a2 = dbv(np.abs(evalTF(ntf2, np.exp(1j*2*np.pi*ffa))))

fig0 = plt.figure()
l = plt.plot(ff/fphi, dbp(resp_w1), 'b', label='on-off weighting')
plt.plot(ff/fphi, dbp(resp_w2), 'r', label='low-dc-noise weighting')
l = plt.plot(ff/fphi, dbv(resp_ntf1), 'b--', label='NTF - on-off')
plt.plot(ff/fphi, dbv(resp_ntf2), 'r--', label='NTF - low-dc-noise')
plt.xlim(1e-5, 1./2)
plt.xscale('log', basex=10)
plt.gca().set_xticks([1E-5, 1./2])
plt.gca().set_xticklabels(['$10^{-5}$', r'$\frac{1}{2}$'])
plt.xlabel('$f$', x=1.)
plt.ylabel((r'$w(f)$, ' +
            r'$\left|\mathit{NTF}\,\left(\mathrm{e}^{\mathrm{i} 2\pi f}' +
            r'\right)\right|$ [dB]'), y=0.5)
plt.grid(True, 'both')
plt.suptitle('Noise weighting and NTF magnitude response')
plt.legend(loc='lower right')
plt.tight_layout(rect=[0, 0, 1, 0.98])
Example #4
0
                          noverlap=NFFT/2, scale_by_freq=True)
print('@1st signal, ', end="")
(psd2, freqs2) = mlab.psd((yy2)[Tsp_start:Tsp_stop], Fs=fphi, NFFT=NFFT,
                          noverlap=NFFT/2, scale_by_freq=True)
print('@2nd signal)')

print("Check overall power from psd")
print(" (should be 1): ", end="")
df = freqs[1]-freqs[0]
print(np.sum(psd)*df)

# Plot PDS of signal at modulator output
# This is the same as in Fig. 5b, but with a single band
# Try to express quantities in dBm (referred to 1 mW over a 50 Ohm resistor)
plt.figure()
plt.plot(freqs, dbp(psd)+30-10*np.log10(50))
plt.xlim(0, fphi/2)
plt.xlabel(r'$f$ [MHz]', x=1.)
plt.ylabel(r'PDS [dBm/Hz]')
plt.gca().set_xticks([0, fphi/2])
plt.gca().set_xticklabels(['$0$', r'$2.56$'])
plt.suptitle('PSD at modulator output')

# Plot PDS of first reconstructed signal
plt.figure()
plt.plot(freqs1, dbp(psd1))
plt.xscale('log', base=10)
plt.suptitle('PSD of reconstructed signal - 1st signal')

# Plot PDS of second reconstructed signal
plt.figure()
Example #5
0
plt.suptitle("Output filter and NTFs")

# Check merit factors
ffl = np.linspace(fmin, fmax, 1000)
pg_opti = (np.abs(evalTF(ntf_opti, np.exp(1j*2*np.pi*ffl/fphi))) *
           np.abs(evalTF(hz, np.exp(1j*2*np.pi*ffl/fphi))))
plt.figure()
plt.plot(ffl, pg_opti**2, 'r', label="Optimal NTF")
# plt.legend(loc="upper right")
plt.suptitle("Merit factor integrand")

# Compute expected behavior
sigma2_e = 1./3
noise_power_opti_1 = quantization_noise_gain(hz, ntf_opti)*sigma2_e
print("Expected optimal noise level {} ({} dB)\nExpected SNR {} dB".format(
    noise_power_opti_1, dbp(noise_power_opti_1),
    dbp(0.5*A1**2+0.5*A2**2)-dbp(noise_power_opti_1)))

# Start and stop time for DS simulation
Tstop = 100E3
Tstart = 40E3
dither_sigma = 1e-6

# Set up DSM simulation
tt = np.asarray(range(int(Tstop)))
uu = A1*np.sin(2*np.pi*fsig1/fphi*tt)+A2*np.sin(2*np.pi*fsig2/fphi*tt)
dither = np.random.randn(len(uu))*dither_sigma
uud = uu+dither

# Simulate the DSM
print("Simulating optimal NTF")
Example #6
0
                                       'feastol': 1E-2
                                   })

dunn_ntf = ntf_dunn(3, osr, H_inf)

fmin = 10
fmax = fphi / 2
ff = np.logspace(np.log10(fmin), np.log10(fmax), 1000)

resp_w = f_weighting(ff)
resp_opti = np.abs(evalTF(opti_ntf, np.exp(1j * 2 * np.pi * ff / fphi)))
resp_ref = np.abs(evalTF(dunn_ntf, np.exp(1j * 2 * np.pi * ff / fphi)))

# First figure. This provides the weighting function and the NTFs
fig0 = plt.figure()
plt.plot(ff / fphi, dbp(resp_w), 'b', label='audio weighting')
plt.plot(ff / fphi, dbv(resp_opti), 'r', label='proposed NTF')
l = plt.plot(ff / fphi, dbv(resp_ref), 'g', label="Dunn's NTF")
plt.suptitle('Audio weighting and NTF magnitude response')
plt.xlim(10E-5, 1. / 2)
plt.ylim(-140, 20)
plt.xscale('log', basex=10)
plt.gca().set_xticks([1E-5, 1. / 2])
plt.gca().set_xticklabels(['$10^{-5}$', r'$\frac{1}{2}$'])
plt.xlabel('$f$', x=1.)
plt.ylabel((r'$w(f)$, ' +
            r'$\left|\mathit{NTF}\,\left(\mathrm{e}^{\mathrm{i} 2\pi f}' +
            r'\right)\right|$ [dB]'),
           y=0.5)
plt.grid(True, 'both')
plt.legend(loc='lower right')
Example #7
0
pg_opti = (np.abs(evalTF(ntf_opti, np.exp(1j*2*np.pi*ffl/fphi))) *
           np.abs(evalTF(hz, np.exp(1j*2*np.pi*ffl/fphi))))
pg_delsig = (np.abs(evalTF(ntf_delsig, np.exp(1j*2*np.pi*ffl/fphi))) *
             np.abs(evalTF(hz, np.exp(1j*2*np.pi*ffl/fphi))))
plt.figure()
plt.plot(ffl, pg_opti**2, 'r', label="Optimal NTF")
plt.plot(ffl, pg_delsig**2, 'g', label="Delsig NTF")
plt.legend(loc="upper right")
plt.suptitle("Merit factor integrand")

# Compute expected behavior
sigma2_e = 1./3
noise_power_opti_1 = quantization_noise_gain(hz, ntf_opti)*sigma2_e
noise_power_delsig_1 = quantization_noise_gain(hz, ntf_delsig)*sigma2_e
print("Expected optimal noise level {} ({} dB).\nExpected SNR {} dB".format(
    noise_power_opti_1, dbp(noise_power_opti_1),
    dbp(0.5*A**2)-dbp(noise_power_opti_1)))
print("Expected delsig noise level {} ({} dB).\nExpected SNR {} dB".format(
    noise_power_delsig_1, dbp(noise_power_delsig_1),
    dbp(0.5*A**2)-dbp(noise_power_delsig_1)))

# Start and stop time for DS simulation
Tstop = 100E3
Tstart = 40E3
dither_sigma = 1e-6

# Set up DSM simulation
tt = np.asarray(range(int(Tstop)))
uu = A*np.sin(2*np.pi*fsig/fphi*tt)
dither = np.random.randn(len(uu))*dither_sigma
uud = uu+dither
Example #8
0
# Synthesize the NTF for all the orders and OSR values at h_inf=1.5
for i, osr in enumerate(osrs):
    for j, order in enumerate(orders):
        ntf1 = synthesizeNTF(order, osr=osr, opt=3, H_inf=1.5)
        f1, f2 = ds_f1f2(osr)
        g0 = quantization_weighted_noise_gain(ntf1, None, (f1, f2))
        # print order, osr, f1, f2, g0, dbp(g0)
        g0s[j, i] = g0
# Make the plot: quantization noise gain versus OSR for the different
# orders
plt.figure()
plt.xscale('log')
markers = 'ov^<>'
for i, order in enumerate(orders):
    plt.plot(osrs, dbp(g0s[i]), "-"+markers[i], label='%d' % order)
plt.legend(loc='upper right', fontsize=9)
plt.xlabel("OSR")
plt.ylabel("$P_N$ [dB]")
# Print some interesting data from the designs
print("Analysis of data for varying OSR")
for i, order in enumerate(orders):
    print("Order: %d. Average slope: %f dB per OSR doubling." %
          (order, (dbp(g0s[i, -1])-dbp(g0s[i, 0]))/(orders.size-1)))

# Prepare a vector to store the noise gain for obtained at the many
# test conditions
g0s = np.zeros((orders.size, hinfs.size))

# Synthesize the NTF for all the orders and h_inf values at OSR=64
for i, hinf in enumerate(hinfs):
Example #9
0
pg_opti = (np.abs(evalTF(ntf_opti, np.exp(1j * 2 * np.pi * ffl / fphi))) *
           np.abs(evalTF(hz, np.exp(1j * 2 * np.pi * ffl / fphi))))
pg_delsig = (np.abs(evalTF(ntf_delsig, np.exp(1j * 2 * np.pi * ffl / fphi))) *
             np.abs(evalTF(hz, np.exp(1j * 2 * np.pi * ffl / fphi))))
plt.figure()
plt.plot(ffl, pg_opti**2, 'r', label="Optimal NTF")
plt.plot(ffl, pg_delsig**2, 'g', label="Delsig NTF")
plt.legend(loc="upper right")
plt.suptitle("Merit factor integrand")

# Compute expected behavior
sigma2_e = 1. / 3
noise_power_opti_1 = quantization_noise_gain(hz, ntf_opti) * sigma2_e
noise_power_delsig_1 = quantization_noise_gain(hz, ntf_delsig) * sigma2_e
print("Expected optimal noise level {} ({} dB).\nExpected SNR {} dB".format(
    noise_power_opti_1, dbp(noise_power_opti_1),
    dbp(0.5 * A**2) - dbp(noise_power_opti_1)))
print("Expected delsig noise level {} ({} dB).\nExpected SNR {} dB".format(
    noise_power_delsig_1, dbp(noise_power_delsig_1),
    dbp(0.5 * A**2) - dbp(noise_power_delsig_1)))

# Start and stop time for DS simulation
Tstop = 100E3
Tstart = 40E3
dither_sigma = 1e-6

# Set up DSM simulation
tt = np.asarray(list(range(int(Tstop))))
uu = A * np.sin(2 * np.pi * fsig / fphi * tt)
dither = np.random.randn(len(uu)) * dither_sigma
uud = uu + dither
Example #10
0
print("... plotting optimal NTF amplitude response")
vv_mag = dbv(ntf_opti_mag(ff))
vv_ref = dbv(ntf_delsig_mag(ff))
plt.figure()
plt.plot(ff, vv_mag, 'b', label='proposed')
l = plt.plot(ff, vv_ref, 'r', label='reference')
plt.xlim(1e-5, 1. / 2)
plt.ylim(-100, 5)
plt.xscale('log', basex=10)
plt.gca().set_xticks([1E-5, 1. / 2])
plt.gca().set_xticklabels(['$10^{-5}$', r'$\frac{1}{2}$'])
plt.xlabel('$f$', x=1.)
plt.ylabel((r'$\left|\mathit{NTF}\,\left(\mathrm{e}^{\mathrm{i} 2\pi f}' +
            r'\right)\right|$ [dB]'),
           y=0.59)
plt.grid(True, 'both')
plt.suptitle('Noise transfer function (magnitude)')
plt.legend(loc="lower right")
plt.tight_layout(rect=[0, 0, 1, 0.98])

print("... computing some interesting data")
p1 = quantization_noise_gain(ntf_opti, hz)
p2 = quantization_noise_gain(ntf_delsig, hz)

print("Overall noise power amplification/attenuation")
print("Proposed", p1, "(", dbp(p1), "dB)")
print("Reference", p2, "(", dbp(p2), "dB)")

plt.show()
Example #11
0
# Prepare frequency axis for plotting
fmin = 10**np.ceil(np.log10(B / OSR / 100))
fmax = fphi / 2
ff = np.logspace(np.log10(fmin), np.log10(fmax), 1000)

resp_w1 = np.fromiter(list(map(w1, ff / fphi)), np.double)
resp_ntf1 = np.abs(evalTF(ntf1, np.exp(1j * 2 * np.pi * ff / fphi)))
resp_w2 = np.fromiter(list(map(w2, ff / fphi)), np.double)
resp_ntf2 = np.abs(evalTF(ntf2, np.exp(1j * 2 * np.pi * ff / fphi)))

ffa = np.logspace(np.log10(0.5E-5), np.log10(0.5), 1024)
vv_a2 = dbv(np.abs(evalTF(ntf2, np.exp(1j * 2 * np.pi * ffa))))

fig0 = plt.figure()
l = plt.plot(ff / fphi, dbp(resp_w1), 'b', label='on-off weighting')
plt.plot(ff / fphi, dbp(resp_w2), 'r', label='low-dc-noise weighting')
l = plt.plot(ff / fphi, dbv(resp_ntf1), 'b--', label='NTF - on-off')
plt.plot(ff / fphi, dbv(resp_ntf2), 'r--', label='NTF - low-dc-noise')
plt.xlim(1e-5, 1. / 2)
plt.xscale('log', basex=10)
plt.gca().set_xticks([1E-5, 1. / 2])
plt.gca().set_xticklabels(['$10^{-5}$', r'$\frac{1}{2}$'])
plt.xlabel('$f$', x=1.)
plt.ylabel((r'$w(f)$, ' +
            r'$\left|\mathit{NTF}\,\left(\mathrm{e}^{\mathrm{i} 2\pi f}' +
            r'\right)\right|$ [dB]'),
           y=0.5)
plt.grid(True, 'both')
plt.suptitle('Noise weighting and NTF magnitude response')
plt.legend(loc='lower right')
Example #12
0
# Synthesize the NTF for all the orders and OSR values at h_inf=1.5
for i, osr in enumerate(osrs):
    for j, order in enumerate(orders):
        ntf1 = synthesizeNTF(order, osr=osr, opt=3, H_inf=1.5)
        f1, f2 = ds_f1f2(osr)
        g0 = quantization_weighted_noise_gain(ntf1, None, (f1, f2))
        # print order, osr, f1, f2, g0, dbp(g0)
        g0s[j, i] = g0
# Make the plot: quantization noise gain versus OSR for the different
# orders
plt.figure()
plt.xscale('log')
markers = 'ov^<>'
for i, order in enumerate(orders):
    plt.plot(osrs, dbp(g0s[i]), "-" + markers[i], label='%d' % order)
plt.legend(loc='upper right', fontsize=9)
plt.xlabel("OSR")
plt.ylabel("$P_N$ [dB]")
# Print some interesting data from the designs
print("Analysis of data for varying OSR")
for i, order in enumerate(orders):
    print("Order: %d. Average slope: %f dB per OSR doubling." %
          (order, (dbp(g0s[i, -1]) - dbp(g0s[i, 0])) / (orders.size - 1)))

# Prepare a vector to store the noise gain for obtained at the many
# test conditions
g0s = np.zeros((orders.size, hinfs.size))

# Synthesize the NTF for all the orders and h_inf values at OSR=64
for i, hinf in enumerate(hinfs):
Example #13
0
n_pow_06_02 = noise_power*quantization_noise_gain(hz06, ntf02)
n_pow_06_06 = noise_power*quantization_noise_gain(hz06, ntf06)
n_pow_06_delsig = noise_power*quantization_noise_gain(hz06, delsig_ntf)

sig_pow = A**2/2  # Input signal power
# Output signal power at 3 slip conditions
sig_pow_0043 = sig_pow*np.abs(evalTF(hz0043, np.exp(2j*np.pi*fmot/fphi)))**2
sig_pow_02 = sig_pow*np.abs(evalTF(hz02, np.exp(2j*np.pi*fmot/fphi)))**2
sig_pow_06 = sig_pow*np.abs(evalTF(hz06, np.exp(2j*np.pi*fmot/fphi)))**2

print("Noise power and SNR for motor at slip=0.043")
print("ntf0043\tntf02\tntf06\tdelsig")
print("{:.4e}\t{:.4e}\t{:.4e}\t{:.4e}".format(
    n_pow_0043_0043, n_pow_0043_02, n_pow_0043_06, n_pow_0043_delsig))
print("{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB".format(
    dbp(sig_pow_0043/n_pow_0043_0043), dbp(sig_pow_0043/n_pow_0043_02),
    dbp(sig_pow_0043/n_pow_0043_06), dbp(sig_pow_0043/n_pow_0043_delsig)))
print("Noise power and SNR for motor at slip=0.2")
print("ntf0043\tntf02\tntf06\tdelsig")
print("{:.4e}\t{:.4e}\t{:.4e}\t{:.4e}".format(
    n_pow_02_0043, n_pow_02_02, n_pow_02_06, n_pow_02_delsig))
print("{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB".format(
    dbp(sig_pow_02/n_pow_02_0043), dbp(sig_pow_02/n_pow_02_02),
    dbp(sig_pow_02/n_pow_02_06), dbp(sig_pow_02/n_pow_02_delsig)))
print("Noise power and SNR for motor at slip=0.6")
print("ntf0043\tntf02\tntf06\tdelsig")
print("{:.4e}\t{:.4e}\t{:.4e}\t{:.4e}".format(
    n_pow_06_0043, n_pow_06_02, n_pow_06_06, n_pow_06_delsig))
print("{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB\t{:2.2f}dB".format(
    dbp(sig_pow_06/n_pow_06_0043), dbp(sig_pow_06/n_pow_06_02),
    dbp(sig_pow_06/n_pow_06_06), dbp(sig_pow_06/n_pow_06_delsig)))
Example #14
0
plt.suptitle("Output filter and NTFs")

# Check merit factors
ffl = np.linspace(fmin, fmax, 1000)
pg_opti = (np.abs(evalTF(ntf_opti, np.exp(1j*2*np.pi*ffl/fphi))) *
           np.abs(evalTF(hz, np.exp(1j*2*np.pi*ffl/fphi))))
plt.figure()
plt.plot(ffl, pg_opti**2, 'r', label="Optimal NTF")
# plt.legend(loc="upper right")
plt.suptitle("Merit factor integrand")

# Compute expected behavior
sigma2_e = 1./3
noise_power_opti_1 = quantization_noise_gain(hz, ntf_opti)*sigma2_e
print("Expected optimal noise level {} ({} dB)\nExpected SNR {} dB".format(
    noise_power_opti_1, dbp(noise_power_opti_1),
    dbp(0.5*A1**2+0.5*A2**2)-dbp(noise_power_opti_1)))

# Start and stop time for DS simulation
Tstop = 100E3
Tstart = 40E3
dither_sigma = 1e-6

# Set up DSM simulation
tt = np.asarray(list(range(int(Tstop))))
uu = A1*np.sin(2*np.pi*fsig1/fphi*tt)+A2*np.sin(2*np.pi*fsig2/fphi*tt)
dither = np.random.randn(len(uu))*dither_sigma
uud = uu+dither

# Simulate the DSM
print("Simulating optimal NTF")