예제 #1
0
 def test_default(self):
     z, p, k = synthesizeNTF()
     e_k = 1
     e_z = np.ones(3)
     e_p = [0.7654 - 0.2793j, 0.7654 + 0.2793j, 0.6694]
     e_p = cplxpair(e_p)
     np.testing.assert_almost_equal(k, e_k, 6)
     np.testing.assert_almost_equal(z, e_z, 6)
     np.testing.assert_almost_equal(p, e_p, 4)
예제 #2
0
 def test_opt3(self):
     z, p, k = synthesizeNTF(opt=3)
     e_k = 1
     e_z = [1.0000, 0.9993 - 0.0382j, 0.9993 + 0.0382j]
     e_z = cplxpair(e_z)
     e_p = [0.6692, 0.7652 - 0.2795j, 0.7652 + 0.2795j]
     e_p = cplxpair(e_p)
     np.testing.assert_almost_equal(k, e_k, 6)
     np.testing.assert_almost_equal(z, e_z, 4)
     np.testing.assert_almost_equal(p, e_p, 4)
예제 #3
0
 def test_BP6(self):
     z, p, k = synthesizeNTF(order=6, f0=0.3)
     e_k = 1
     e_z = np.concatenate(((-0.3090 + 0.9511j) * np.ones(3),
                           (-0.3090 - 0.9511j) * np.ones(3)))
     e_z = cplxpair(e_z)
     e_p = [
         -0.4238 - 0.7906j, -0.4238 + 0.7906j, -0.2480 - 0.7802j,
         -0.2480 + 0.7802j, -0.1290 - 0.8985j, -0.1290 + 0.8985j
     ]
     e_p = cplxpair(e_p)
     np.testing.assert_almost_equal(k, e_k, 6)
     np.testing.assert_almost_equal(z, e_z, 4)
     np.testing.assert_almost_equal(p, e_p, 4)
예제 #4
0
A1 = 0.2      # Amplitude of first signal
A2 = 0.44     # Amplitude of the second signal
f1 = 1003     # Frequency used to test the first test signal with a tone
f2 = 3193     # Frequency used to test the second test signal with a tone

Amax = 0.64   # Max amplitude used for testing

# Clock frequency of modulator
fphi = 2*OSR*(B1)

# Cut off frequency of reconstruction filter
# ...set twice as wide as it should to better see artifacts
brk = B1/fphi

# Create NTF with DELSIG synthesizeNTF
ntf_a = synthesizeNTF(order=4, osr=OSR, opt=3, H_inf=1.5)

# Prepare frequency grid
ff_log = np.logspace(np.log10(0.5E-5), np.log10(0.5), 4096)
ff_lin = np.linspace(0, 0.5, 1024)

# Compute magnitude responses of NTF for plotting
ntf_a_mag = lambda f: np.abs(evalTF(ntf_a, np.exp(-2j*np.pi*f)))
vv_ntf_a_log = ntf_a_mag(ff_log)
vv_ntf_a_lin = ntf_a_mag(ff_lin)

# Design output filter
hz = signal.butter(4, 2*brk, btype='low')

# Compute magnitude responses of output filter for plotting
hz_mag = lambda f: np.abs(evalTF(hz, np.exp(-2j*np.pi*f)))
예제 #5
0
plt.ylim(0, 1.1)
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('$w(f)$', y=0.9)
plt.grid(True, 'both')
plt.suptitle('Weighting function')
plt.tight_layout(rect=[0, 0, 1, 0.98])

print("... computing optimal NTF")
ntf_opti = ntf_fir_weighting(order, w1, H_inf=H_inf)
ntf_opti_mag = lambda f: np.abs(evalTF(ntf_opti, np.exp(-2j * np.pi * f)))

print("... computing delsig NTF")
ntf_delsig = synthesizeNTF(delsig_order, OSR, 3, H_inf, 0)
ntf_delsig_mag = lambda f: np.abs(evalTF(ntf_delsig, np.exp(-2j * np.pi * f)))

print("... plotting optimal NTF amplitude response")
vv_mag = dbv(ntf_opti_mag(ff))
vv_mag_delsig = dbv(ntf_delsig_mag(ff))
plt.figure()
plt.plot(ff, vv_mag, label='Proposed')
plt.plot(ff,
         vv_mag_delsig,
         'r-o',
         linewidth=0.5,
         markevery=24,
         markersize=3,
         label='Reference')
plt.xlim(1e-5, 1. / 2)
예제 #6
0
A1 = 0.2  # Amplitude of first signal
A2 = 0.44  # Amplitude of the second signal
f1 = 1003  # Frequency used to test the first test signal with a tone
f2 = 3193  # Frequency used to test the second test signal with a tone

Amax = 0.64  # Max amplitude used for testing

# Clock frequency of modulator
fphi = 2 * OSR * (B1)

# Cut off frequency of reconstruction filter
# ...set twice as wide as it should to better see artifacts
brk = B1 / fphi

# Create NTF with DELSIG synthesizeNTF
ntf_a = synthesizeNTF(order=4, osr=OSR, opt=3, H_inf=1.5)

# Prepare frequency grid
ff_log = np.logspace(np.log10(0.5E-5), np.log10(0.5), 4096)
ff_lin = np.linspace(0, 0.5, 1024)

# Compute magnitude responses of NTF for plotting
ntf_a_mag = lambda f: np.abs(evalTF(ntf_a, np.exp(-2j * np.pi * f)))
vv_ntf_a_log = ntf_a_mag(ff_log)
vv_ntf_a_lin = ntf_a_mag(ff_lin)

# Design output filter
hz = signal.butter(4, 2 * brk, btype='low')

# Compute magnitude responses of output filter for plotting
hz_mag = lambda f: np.abs(evalTF(hz, np.exp(-2j * np.pi * f)))
예제 #7
0
plt.ylim(0, 1.1)
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('$w(f)$', y=0.9)
plt.grid(True, 'both')
plt.suptitle('Weighting function')
plt.tight_layout(rect=[0, 0, 1, 0.98])

print("... computing optimal NTF")
ntf_opti = ntf_fir_weighting(order, w1, H_inf=H_inf)
ntf_opti_mag = lambda f: np.abs(evalTF(ntf_opti, np.exp(-2j*np.pi*f)))

print("... computing delsig NTF")
ntf_delsig = synthesizeNTF(delsig_order, OSR, 3, H_inf, 0)
ntf_delsig_mag = lambda f: np.abs(evalTF(ntf_delsig, np.exp(-2j*np.pi*f)))

print("... plotting optimal NTF amplitude response")
vv_mag = dbv(ntf_opti_mag(ff))
vv_mag_delsig = dbv(ntf_delsig_mag(ff))
plt.figure()
plt.plot(ff, vv_mag, label='Proposed')
plt.plot(ff, vv_mag_delsig, 'r-o', linewidth=0.5, markevery=24, markersize=3,
         label='Reference')
plt.xlim(1e-5, 1./2)
# plt.ylim(0,1.1)
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.)
예제 #8
0
# Set the OSRs and the h_inf (gamma) values used for the plots
# OSR values are arranged so that each one is twice the previous one
# hinf values are arranged so that each value is the square root of the
# previous one. Also set the orders used for testing.
osrs = np.asarray([16, 32, 64, 128, 256])
hinfs = np.asarray([2.25**(1 / (2.**i)) for i in range(5)])
orders = np.asarray([1, 2, 3, 4, 5])

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

# 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
예제 #9
0
# Care: in butter the cut of frequency is specified as a number from 0 to 1
# where 1 is fphi/2, not fphi
hz = sp.signal.butter(1, 2 * (2 * B) / fphi, btype='low')

# Compute impulse response
print("...computing impulse response of filter")
hz_ir = impulse_response(hz, db=60)

# Compute the optimal NTF
print("... computing optimal NTF")
q0 = q0_from_filter_ir(order, hz_ir)
ntf_opti = ntf_fir_from_q0(q0, H_inf=H_inf)

# Compute an NTF with DELSIG, for comparison
print("... computing delsig NTF")
ntf_delsig = synthesizeNTF(4, OSR, 3, H_inf, 0)

# Determine freq values for which plots are created
fmin = 10**np.ceil(np.log10(2 * B / OSR))
fmax = 10**np.floor(np.log10(fphi / 2))
ff = np.logspace(np.log10(fmin), np.log10(fmax), 1000)

# Compute frequency response data
resp_filt = np.abs(evalTF(hz, np.exp(1j * 2 * np.pi * ff / fphi)))
resp_opti = np.abs(evalTF(ntf_opti, np.exp(1j * 2 * np.pi * ff / fphi)))
resp_delsig = np.abs(evalTF(ntf_delsig, np.exp(1j * 2 * np.pi * ff / fphi)))

# Plot frequency response
plt.figure()
plt.semilogx(ff, dbv(resp_filt), 'b', label="Output filter")
plt.semilogx(ff, dbv(resp_opti), 'r', label="Optimal NTF")
예제 #10
0
 def test_default(self):
     ntf = synthesizeNTF()
     plotPZ(ntf)
예제 #11
0
 def test_default(self):
     ntf = synthesizeNTF()
     plotPZ(ntf)
예제 #12
0
# Set the OSRs and the h_inf (gamma) values used for the plots
# OSR values are arranged so that each one is twice the previous one
# hinf values are arranged so that each value is the square root of the
# previous one. Also set the orders used for testing.
osrs = np.asarray([16, 32, 64, 128, 256])
hinfs = np.asarray([2.25**(1/(2.**i)) for i in range(5)])
orders = np.asarray([1, 2, 3, 4, 5])

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

# 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
예제 #13
0
A2 = 0.44     # Amplitude of the second signal
f1 = 1003     # Frequency used to test the first test signal with a tone
f2 = 3193     # Frequency used to test the second test signal with a tone

Amax = 0.34   # Max amplitude used for testing

# Clock frequency of modulator
fphi = 2*OSR*(B1+B2)

# Cut off frequency of reconstruction filters
# ...set twice as wide as they should to better see artifacts
brk1 = B1/fphi
brk2 = 0.5-B2/fphi

# Create NTF with DELSIG synthesizeNTF
ntf_a = synthesizeNTF(order=4, osr=2*OSR, opt=3, H_inf=np.sqrt(1.5))
ntf_dual_a = mirroredNTF(ntf_a)

# Prepare frequency grid
ff_log = np.logspace(np.log10(0.5E-5), np.log10(0.5), 4096)
ff_lin = np.linspace(0, 0.5, 1024)

# Compute magnitude responses of NTF for plotting
ntf_a_mag = lambda f: np.abs(evalTF(ntf_a, np.exp(-2j*np.pi*f)))
vv_ntf_a_log = ntf_a_mag(ff_log)
vv_ntf_a_lin = ntf_a_mag(ff_lin)
ntf_dual_a_mag = lambda f: np.abs(evalTF(ntf_dual_a, np.exp(-2j*np.pi*f)))
vv_ntf_dual_a_log = ntf_dual_a_mag(ff_log)
vv_ntf_dual_a_lin = ntf_dual_a_mag(ff_lin)

# Design output filter
예제 #14
0
plt.legend()
plt.ion()
plt.show()
plt.ioff()

# Compute optimal and benchmark NTFs
hz0043_ir = impulse_response(hz0043)
hz02_ir = impulse_response(hz02)
hz06_ir = impulse_response(hz06)
q0_0043 = q0_from_filter_ir(P, hz0043_ir)
ntf0043 = ntf_fir_from_q0(q0_0043)
q0_02 = q0_from_filter_ir(P, hz02_ir)
ntf02 = ntf_fir_from_q0(q0_02)
q0_06 = q0_from_filter_ir(P, hz06_ir)
ntf06 = ntf_fir_from_q0(q0_06)
delsig_ntf = synthesizeNTF(DELSIG_P, OSR, 3, 1.5, 0)

# Plot the NTFs
nyz0043 = evalTF(ntf0043, np.exp(2j * np.pi * ff / fphi))
nyz02 = evalTF(ntf02, np.exp(2j * np.pi * ff / fphi))
nyz06 = evalTF(ntf06, np.exp(2j * np.pi * ff / fphi))
delsig_ny = evalTF(delsig_ntf, np.exp(2j * np.pi * ff / fphi))

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")
예제 #15
0
# Care: in butter the cut of frequency is specified as a number from 0 to 1
# where 1 is fphi/2, not fphi
hz = sp.signal.butter(1, 2*(2*B)/fphi, btype='low')

# Compute impulse response
print("...computing impulse response of filter")
hz_ir = impulse_response(hz, db=60)

# Compute the optimal NTF
print("... computing optimal NTF")
q0 = q0_from_filter_ir(order, hz_ir)
ntf_opti = ntf_fir_from_q0(q0, H_inf=H_inf)

# Compute an NTF with DELSIG, for comparison
print("... computing delsig NTF")
ntf_delsig = synthesizeNTF(4, OSR, 3, H_inf, 0)

# Determine freq values for which plots are created
fmin = 10**np.ceil(np.log10(2*B/OSR))
fmax = 10**np.floor(np.log10(fphi/2))
ff = np.logspace(np.log10(fmin), np.log10(fmax), 1000)

# Compute frequency response data
resp_filt = np.abs(evalTF(hz, np.exp(1j*2*np.pi*ff/fphi)))
resp_opti = np.abs(evalTF(ntf_opti, np.exp(1j*2*np.pi*ff/fphi)))
resp_delsig = np.abs(evalTF(ntf_delsig, np.exp(1j*2*np.pi*ff/fphi)))

# Plot frequency response
plt.figure()
plt.semilogx(ff, dbv(resp_filt), 'b', label="Output filter")
plt.semilogx(ff, dbv(resp_opti), 'r', label="Optimal NTF")
예제 #16
0
A2 = 0.44  # Amplitude of the second signal
f1 = 1003  # Frequency used to test the first test signal with a tone
f2 = 3193  # Frequency used to test the second test signal with a tone

Amax = 0.34  # Max amplitude used for testing

# Clock frequency of modulator
fphi = 2 * OSR * (B1 + B2)

# Cut off frequency of reconstruction filters
# ...set twice as wide as they should to better see artifacts
brk1 = B1 / fphi
brk2 = 0.5 - B2 / fphi

# Create NTF with DELSIG synthesizeNTF
ntf_a = synthesizeNTF(order=4, osr=2 * OSR, opt=3, H_inf=np.sqrt(1.5))
ntf_dual_a = mirroredNTF(ntf_a)

# Prepare frequency grid
ff_log = np.logspace(np.log10(0.5E-5), np.log10(0.5), 4096)
ff_lin = np.linspace(0, 0.5, 1024)

# Compute magnitude responses of NTF for plotting
ntf_a_mag = lambda f: np.abs(evalTF(ntf_a, np.exp(-2j * np.pi * f)))
vv_ntf_a_log = ntf_a_mag(ff_log)
vv_ntf_a_lin = ntf_a_mag(ff_lin)
ntf_dual_a_mag = lambda f: np.abs(evalTF(ntf_dual_a, np.exp(-2j * np.pi * f)))
vv_ntf_dual_a_log = ntf_dual_a_mag(ff_log)
vv_ntf_dual_a_lin = ntf_dual_a_mag(ff_lin)

# Design output filter
예제 #17
0
plt.legend()
plt.ion()
plt.show()
plt.ioff()

# Compute optimal and benchmark NTFs
hz0043_ir = impulse_response(hz0043)
hz02_ir = impulse_response(hz02)
hz06_ir = impulse_response(hz06)
q0_0043 = q0_from_filter_ir(P, hz0043_ir)
ntf0043 = ntf_fir_from_q0(q0_0043)
q0_02 = q0_from_filter_ir(P, hz02_ir)
ntf02 = ntf_fir_from_q0(q0_02)
q0_06 = q0_from_filter_ir(P, hz06_ir)
ntf06 = ntf_fir_from_q0(q0_06)
delsig_ntf = synthesizeNTF(DELSIG_P, OSR, 3, 1.5, 0)

# Plot the NTFs
nyz0043 = evalTF(ntf0043, np.exp(2j*np.pi*ff/fphi))
nyz02 = evalTF(ntf02, np.exp(2j*np.pi*ff/fphi))
nyz06 = evalTF(ntf06, np.exp(2j*np.pi*ff/fphi))
delsig_ny = evalTF(delsig_ntf, np.exp(2j*np.pi*ff/fphi))

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')