%pylab inline from __future__ import print_function from deltasigma import * from IPython.core.display import Image # skip this, this is just to display nice tables. from itertools import izip_longest class Table(list): def _repr_html_(self): html = [""] for row in self: html.append("") for col in row: try: float(col) html.append("" % col) except(ValueError): html.append("" % col) html.append("") html.append("
%.6f%s
") return ''.join(html) order = 5 R = 42 opt = 1 H = synthesizeNTF(order, R, opt) print(pretty_lti(H)) figure(figsize=(10, 5)) plotPZ(H, showlist=True) title('NTF'); Image(url='http://python-deltasigma.readthedocs.org/en/latest/_images/CRFB.png', retina=True) a, g, b, c = realizeNTF(H) b = np.concatenate((b[0].reshape((1, )), np.zeros((b.shape[0] - 1, ))), axis=0) t = Table() ilabels = ['#1', '#2', '#3', '#4', '#5', '#6'] t.append(['Coefficients', 'DAC feedback', 'Resonator feedback', 'Feed-in', 'Interstage']) t.append(['', 'a(n)', 'g(n)', ' b(n)', ' c(n)']) [t.append(x) for x in izip_longest(ilabels, a.tolist(), g.tolist(), b.tolist(), c.tolist(), fillvalue="")] t ABCD = stuffABCD(a, g, b, c); u = np.linspace(0, 0.6, 30); N = 1e4; T = np.ones((1, N)) maxima = np.zeros((order, len(u))) for i in range(len(u)): ui = u[i] v, xn, xmax, _ = simulateDSM(ui*T, ABCD); maxima[:, i] = np.squeeze(xmax) if any(xmax > 1e2): umax = ui; u = u[:i+1]; maxima = maxima[:, :i] break; # save the maxima prescale_maxima = np.copy(maxima) print('The state maxima have been evaluated through simulation.') for i in range(order): semilogy(u, maxima[i, :],'o-') if not i: hold(True) grid(True) xlabel('DC input') ylabel('Peak value') title('Simulated State Maxima') xlim([0, 0.6]) ylim([1e-4, 10]); ABCDs, umax, _ = scaleABCD(ABCD, N_sim=1e5) as_, gs, bs, cs = mapABCD(ABCDs) print('\nScaled modulator, umax = %.2f\n' % umax) t = Table() ilabels = ['#1', '#2', '#3', '#4', '#5', '#6'] t.append(['Coefficients', 'DAC feedback', 'Resonator feedback', 'Feed-in', 'Interstage']) t.append(['', 'a(n)', 'g(n)', ' b(n)', ' c(n)']) [t.append(x) for x in izip_longest(ilabels, as_.tolist(), gs.tolist(), bs.tolist(), cs.tolist(), fillvalue="")] t u = np.linspace(0, umax, 30) N = 1e4 T = np.ones((N,)) maxima = np.zeros((order, len(u))) for i in range(len(u)): ui = u[i] v, xn, xmax, _ = simulateDSM(ui*T, ABCDs) maxima[:, i] = xmax.squeeze() if any(xmax > 1e2): umax = ui; u = u[:i] maxima = maxima[:, :i] break print('The state maxima have been re-evaluated through simulation.') print("The maximum input was found to be %.6f" % umax) for i in range(order): semilogy(u, maxima[i, :], 'o-') if not i: hold(True) grid(True) ylabel('Peak value') xlabel('DC input') xlim([0, 0.6]) ylim([4e-2, 4]); #%install_ext http://raw.github.com/jrjohansson/version_information/master/version_information.py %load_ext version_information %reload_ext version_information %version_information numpy, scipy, matplotlib, deltasigma