def test_ntf_butt_bp8_vs_legacy(self):
     # Compute q0 in two ways
     ir = impulse_response(self.hz, db=80)
     ntf1 = ntf_fir_weighting(self.order, self.hz, show_progress=False)
     q0 = q0_from_filter_ir(self.order, ir)
     ntf2 = ntf_fir_from_q0(q0, show_progress=False)
     mf1 = quantization_noise_gain(ntf1, self.hz)
     mf2 = quantization_noise_gain(ntf2, self.hz)
     np.testing.assert_allclose(mf2, mf1, rtol=1e-7)
     mf3 = quantization_noise_gain_by_conv(ntf1, self.hz)
     np.testing.assert_allclose(mf3, mf1, rtol=5e-6)
 def test_ntf_butt_bp8_vs_legacy(self):
     # Compute q0 in two ways
     ir = impulse_response(self.hz, db=80)
     ntf1 = ntf_fir_weighting(self.order, self.hz, show_progress=False)
     q0 = q0_from_filter_ir(self.order, ir)
     ntf2 = ntf_fir_from_q0(q0, show_progress=False)
     mf1 = quantization_noise_gain(ntf1, self.hz)
     mf2 = quantization_noise_gain(ntf2, self.hz)
     np.testing.assert_allclose(mf2, mf1, rtol=1e-7)
     mf3 = quantization_noise_gain_by_conv(ntf1, self.hz)
     np.testing.assert_allclose(mf3, mf1, rtol=5e-6)
 def bench_ntf_fir_weighting_cvxpy_cvxopt(self):
     try:
         import cvxpy     # analysis:ignore
     except:
         raise SkipTest("Modeler 'cvxpy' not installed")
     print("Benchmarking NTF FIR synthesis with 'cvxpy' modeler + `cvxopt`")
     tic = time.clock()
     ntf = ntf_fir_weighting(self.order, self.hz, self.H_inf,
                             modeler='cvxpy', show_progress=False)
     timing = time.clock()-tic
     mf = quantization_noise_gain(ntf, self.hz)
     vv = np.abs(evalTF(ntf, np.exp(2j*np.pi*self.ff)))
     pe = np.max(vv)-self.H_inf
     print("Timing: {:6.2f}".format(timing))
     print("Accuracy on constraint: {:e}".format(pe))
     print("Accuracy on goal: {:e}".format(mf))
 def bench_ntf_fir_weighting_cvxpy_cvxopt(self):
     try:
         import cvxpy     # analysis:ignore
     except:
         raise SkipTest("Modeler 'cvxpy' not installed")
     print("Benchmarking NTF FIR synthesis with 'cvxpy' modeler + `cvxopt`")
     tic = time.clock()
     ntf = ntf_fir_weighting(self.order, self.hz, self.H_inf,
                             modeler='cvxpy', show_progress=False)
     timing = time.clock()-tic
     mf = quantization_noise_gain(ntf, self.hz)
     vv = np.abs(evalTF(ntf, np.exp(2j*np.pi*self.ff)))
     pe = np.max(vv)-self.H_inf
     print("Timing: {:6.2f}".format(timing))
     print("Accuracy on constraint: {:e}".format(pe))
     print("Accuracy on goal: {:e}".format(mf))
Beispiel #5
0
 def test_q0_equiv(self):
     fir = np.asarray([
         1.00000000e+00, -7.63387347e-01, -4.02004111e-01, -1.53885083e-01,
         -2.76434316e-04, 7.91252937e-02, 1.03165832e-01, 8.83276154e-02,
         4.92894661e-02
     ])
     hz = (np.asarray([-1., -1., -1.]),
           np.asarray([
               0.99382681 + 0.01056265j, 0.98780284 + 0.j,
               0.99382681 - 0.01056265j
           ]), 2.2820568419526305e-07)
     gain1 = quantization_noise_gain((fir, np.hstack((1, np.zeros(8)))), hz)
     q0 = q0_weighting(8, hz)
     Q = la.toeplitz(q0)
     fir_coeff = fir.reshape((1, 9))
     gain2 = fir_coeff.dot(Q).dot(fir_coeff.T)
     np.testing.assert_allclose(gain2, gain1)
Beispiel #6
0
plt.figure()
plt.semilogx(ff, dbv(np.abs(nyz0043)), 'b', label='opt @ $\sigma=0.043$')
plt.semilogx(ff, dbv(np.abs(nyz02)), 'r', label='opt @ $\sigma=0.2$')
plt.semilogx(ff, dbv(np.abs(nyz06)), 'g', label='opt @ $\sigma=0.6$')
plt.semilogx(ff, dbv(np.abs(delsig_ny)), 'y', label='benchmark')
plt.xlabel('$f$ [Hz]')
plt.ylabel('[dB]')
plt.suptitle("NTF magnitude response")
plt.xlim(xmax=10**fmax_log10)
plt.ylim(-225, 5)
plt.legend(loc=4)

print("Computing the SNR in the various cases")
noise_power = 1. / 3  # Quantization noise is power is Delta^2/12
# low slip
n_pow_0043_0043 = noise_power * quantization_noise_gain(hz0043, ntf0043)
n_pow_0043_02 = noise_power * quantization_noise_gain(hz0043, ntf02)
n_pow_0043_06 = noise_power * quantization_noise_gain(hz0043, ntf06)
n_pow_0043_delsig = noise_power * quantization_noise_gain(hz0043, delsig_ntf)
# mid slip
n_pow_02_0043 = noise_power * quantization_noise_gain(hz02, ntf0043)
n_pow_02_02 = noise_power * quantization_noise_gain(hz02, ntf02)
n_pow_02_06 = noise_power * quantization_noise_gain(hz02, ntf06)
n_pow_02_delsig = noise_power * quantization_noise_gain(hz02, delsig_ntf)
# high slip
n_pow_06_0043 = noise_power * quantization_noise_gain(hz06, ntf0043)
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
Beispiel #7
0
plt.semilogx(ff, dbv(resp_opti), 'r', label="Optimal NTF")
plt.legend(loc="lower right")
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
Beispiel #8
0
# 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))))
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))))
Beispiel #9
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()
Beispiel #10
0
plt.semilogx(ff, dbv(np.abs(nyz02)), 'r',
             label='opt @ $\sigma=0.2$')
plt.semilogx(ff, dbv(np.abs(nyz06)), 'g',
             label='opt @ $\sigma=0.6$')
plt.semilogx(ff, dbv(np.abs(delsig_ny)), 'y', label='benchmark')
plt.xlabel('$f$ [Hz]')
plt.ylabel('[dB]')
plt.suptitle("NTF magnitude response")
plt.xlim(xmax=10**fmax_log10)
plt.ylim(-225, 5)
plt.legend(loc=4)

print("Computing the SNR in the various cases")
noise_power = 1./3  # Quantization noise is power is Delta^2/12
# low slip
n_pow_0043_0043 = noise_power*quantization_noise_gain(hz0043, ntf0043)
n_pow_0043_02 = noise_power*quantization_noise_gain(hz0043, ntf02)
n_pow_0043_06 = noise_power*quantization_noise_gain(hz0043, ntf06)
n_pow_0043_delsig = noise_power*quantization_noise_gain(hz0043, delsig_ntf)
# mid slip
n_pow_02_0043 = noise_power*quantization_noise_gain(hz02, ntf0043)
n_pow_02_02 = noise_power*quantization_noise_gain(hz02, ntf02)
n_pow_02_06 = noise_power*quantization_noise_gain(hz02, ntf06)
n_pow_02_delsig = noise_power*quantization_noise_gain(hz02, delsig_ntf)
# high slip
n_pow_06_0043 = noise_power*quantization_noise_gain(hz06, ntf0043)
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