def continuar(self): if userInput['order'] == 1: self.label.pack_forget() self.zero1.pack_forget() self.label2.pack_forget() self.pole1.pack_forget() if userInput['z1'] == None: self.pasabajosTitle.pack_forget() if userInput['z1'] == 0: self.pasaaltosTitle.pack_forget() else: self.pasatodoTitle.pack_forget() self.enterButton1.pack_forget() if userInput['order'] == 2: self.label3.pack_forget() self.zero2.pack_forget() self.label4.pack_forget() self.pole2.pack_forget() self.label5.pack_forget() self.zero3.pack_forget() self.label6.pack_forget() self.pole3.pack_forget() p1 = userInput.get('p1') p2 = userInput.get('p2') z1 = userInput.get('z1') z2 = userInput.get('z2') if (p1 != complex(0, 0)) and (p2 != complex(0, 0)): if (z1 or z2) is None: if (z1 and z2) is None: if (p1 == None) or (p2 == None): self.pasabajos1Title.pack_forget() if (p1 != None) and (p2 != None): self.pasabajos2Title.pack_forget() if (z1 is None and z2 != None) or (z2 is None and z1 != None): if (p1 == None) or (p2 == None): self.pasatodo1Title.pack_forget() if (z1 == complex(0, 0)) and (z2 == complex(0, 0)): self.pasaaltos2Title.pack_forget() if (z1 == complex(0, 0) and z2 == None) or (z2 == complex(0, 0) and z1 == None): if (p1 == None) or (p2 == None): self.pasaaltos1Title.pack_forget() if (p1 != None) and (p2 != None): self.pasabandaTitle.pack_forget() if (z1 != None) and (z2 != None): self.pasatodo2Title.pack_forget() self.enterButton2.pack_forget() self.controller.showFrame(MenuMode)
def focus(self): self.title.pack(side=tk.TOP, fill=tk.BOTH) self.titleG.pack_forget() self.gain.pack_forget() self.buttonSimulate.pack_forget() self.buttonBackFromFirst.pack_forget() self.w2.pack_forget() self.scale.pack_forget() print(userInput.get("order")) if userInput.get("order") == 1: self.titleF1.pack_forget() self.titleEpsilon.pack_forget() self.epsilon.pack_forget() self.titleFo.pack(side=tk.TOP, fill=tk.BOTH, pady=30) self.w2.pack(side=tk.TOP) self.scale.pack() elif userInput.get('order') == 2: self.titleFo.pack_forget() self.titleF1.pack(side=tk.TOP, fill=tk.BOTH, pady=30) self.w2.pack(side=tk.TOP) self.scale.pack() self.titleEpsilon.pack() self.epsilon.pack() self.titleG.pack(side=tk.TOP, fill=tk.BOTH, pady=30) self.gain.pack(side=tk.TOP) self.buttonSimulate.pack(side=tk.TOP, fill=tk.BOTH, pady=20) self.buttonBackFromFirst.pack(expand=0, fill=tk.NONE, pady=separation + 30) pass
def simulate(self): # configuramos modos multiplier = 1 if self.var.get() == "Hz": multiplier = 1 elif self.var.get() == "KHz": multiplier = 1000 elif self.var.get() == "MHz": multiplier = 1000000 elif self.var.get() == "GHz": multiplier = 1000000 else: multiplier = 1 userInput["frequency"] = self.w2.get() * multiplier if userInput.get("order") == 2: userInput["epsilon"] = self.epsilon.get() userInput["gain"] = self.gain.get() self.controller.showFrame(MenuMode)
def focus(self): Vin = [1] Vout = [1] order = userInput.get("order") filterType = userInput.get("type") f0 = userInput.get("frequency") f1 = userInput.get("frequency2") k = userInput.get("gain") epsilon = userInput.get("epsilon") p1 = userInput.get("p1") z1 = userInput.get("z1") p2 = userInput.get("p2") z2 = userInput.get("z2") print("Order ", order, "Type ", filterType, "Freq ", f0, "Gain", k, "Eps ", epsilon) if order == 1: if filterType == "low": Vout = [k] Vin = [1 / f0, 1] elif filterType == "high": Vout = [k, 0] Vin = [1 / f0, 1] elif filterType == "all": Vout = [k / f0, -k] Vin = [1 / f0, +1] elif filterType == "guess": if z1 is None: Vout = [1] else: Vout = [1, -z1] Vin = [1, -p1] elif order == 2: if filterType == "low": Vout = [k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "high": Vout = [k, 0, 0] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "all": Vout = [k * pow(1 / f0, 2), -2 * k * epsilon / f0, k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "band": Vout = [k, 0] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "notch": Vout = [k * pow(1 / f0, 2), 0, k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "guess": if (z1 or z2) is None: if (z1 and z2) is None: Vout = [1] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] elif z1 == None: Vout = [1, -z2] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] elif z2 == None: Vout = [1, -z1] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] else: Vout = [ pow(1 / sqrt(z1 * z2), 2), (-z1 - z2) / (z1 * z2), 1 ] Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] self.H = ss.TransferFunction(Vout, Vin) x2 = logspace(-1, 5, num=1000) Bode = ss.bode(self.H, x2) # Bode diagram. ######### ##ACA HACER COSAS CON GRAFICOS EN BASE A H ######### self.ax1.clear() z = roots(Vout) p = roots(Vin) r = 1.5 * amax(concatenate((abs(z), abs(p), [1]))) self.ax1.axis('scaled') self.ax1.axis([-r, r, -r, r]) # Plot the poles and set marker properties self.ax1.plot(p.real, p.imag, 'x', markersize=9, alpha=0.5, label='Poles', color='b') # Plot the zeros and set marker properties self.ax1.plot(z.real, z.imag, 'o', markersize=9, alpha=0.5, label='Zeros', color='g') #self.ax1.add_patch(unit_circle) self.ax1.axvline(0, color='0.4') self.ax1.axhline(0, color='0.4') self.ax1.minorticks_on() self.ax1.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax1.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax1.set_title('S-plane') self.ax1.set_xlabel('\u03C3') self.ax1.set_ylabel('j2πf') self.ax1.legend() #self.ax1.xaxis.set_label_coords(1.05, -0.025) """ If there are multiple poles or zeros at the same point, put a superscript next to them. TODO: can this be made to self-update when zoomed? # Finding duplicates by same pixel coordinates (hacky for now): poles_xy = self.ax1.transData.transform(vstack(p[0].get_data()).T) zeros_xy = self.ax1.transData.transform(vstack(z[0].get_data()).T) # dict keys should be ints for matching, but coords should be floats for # keeping location of text accurate while zooming # TODO make less hacky, reduce duplication of code d = defaultdict(int) coords = defaultdict(tuple) for xy in poles_xy: key = tuple(np.rint(xy).astype('int')) d[key] += 1 coords[key] = xy for key, value in d.iteritems(): if value > 1: x, y = self.ax1.transData.inverted().transform(coords[key]) plt.text(x, y, r' ${}^{' + str(value) + '}$',fontsize=13) d = defaultdict(int) coords = defaultdict(tuple) for xy in zeros_xy: key = tuple(np.rint(xy).astype('int')) d[key] += 1 coords[key] = xy for key, value in d.iteritems(): if value > 1: x,y = self.ax1.transData.inverted().transform(coords[key]) plt.text(x, y, r' ${}^{' + str(value) + '}$', fontsize=13) """ self.canvas.draw() pass
def focus(self): Vin = [1] Vout = [1] order = userInput.get("order") filterType = userInput.get("type") f0 = userInput.get("frequency") f1 = userInput.get("frequency2") k = userInput.get("gain") epsilon = userInput.get("epsilon") p1 = userInput.get("p1") z1 = userInput.get("z1") p2 = userInput.get("p2") z2 = userInput.get("z2") print("Order ", order, "Type ", filterType, "Freq ", f0, "Gain", k, "Eps ", epsilon) if order == 1: if filterType == "low": Vout = [k] Vin = [1 / f0, 1] elif filterType == "high": Vout = [k, 0] Vin = [1 / f0, 1] elif filterType == "all": print("selected all") Vout = [k / f0, -k] Vin = [1 / f0, +1] print("Vout ", Vout, "Vin", Vin, "Gain", k) elif filterType == "guess": if z1 is None: Vout = [1] else: Vout = [1, -z1] Vin = [1, -p1] elif order == 2: if filterType == "low": Vout = [k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "high": Vout = [k, 0, 0] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "all": Vout = [k * pow(1 / f0, 2), -2 * k * epsilon / f0, k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "band": Vout = [k, 0] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "notch": Vout = [k * pow(1 / f0, 2), 0, k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "guess": if (z1 or z2) is None: if (z1 and z2) is None: Vout = [1] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] elif z1 == None: Vout = [1, -z2] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] elif z2 == None: Vout = [1, -z1] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] else: Vout = [ pow(1 / sqrt(z1 * z2), 2), (-z1 - z2) / (z1 * z2), 1 ] Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] print("Vout ", Vout, "Vin", Vin) self.H = ss.TransferFunction(Vout, Vin) x2 = logspace(-1, 5, num=1000) Bode = ss.bode(self.H, x2) # Bode diagram. self.ax1.clear() self.ax1.set_xscale('log') self.ax1.plot(Bode[0], Bode[1]) self.ax1.minorticks_on() self.ax1.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax1.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax1.set_title('Bode Diagram') self.ax1.set_ylabel('log(|H(j2πft)|)') self.ax2.clear() self.ax2.set_xscale('log') self.ax2.plot(Bode[0], Bode[2]) self.ax2.minorticks_on() self.ax2.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax2.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax2.set_title('Bode Phase Diagram') self.ax2.set_xlabel('f (log) [Hz]') self.ax2.set_ylabel('Phase [degrees]') self.canvas.draw() pass
def boton2OrdenPresionado(self): self.controller.showFrame(MenuSecondOrder) userInput['order'] = 2 print(userInput.get("order"))
def boton1OrdenPresionado(self): self.controller.showFrame(MenuFirstOrder) userInput['order'] = 1 print(userInput.get("order"))
def enter2(self): txt = self.pole2.get() if txt == ";": userInput['p1'] = None else: a = txt.split(";") userInput['p1'] = complex(float(a[0]), float(a[1])) txt = self.zero2.get() if txt == ";": userInput['z1'] = None else: b = txt.split(";") userInput['z1'] = complex(float(b[0]), float(b[1])) txt = self.pole3.get() if txt == ";": userInput['p2'] = None else: c = txt.split(";") userInput['p2'] = complex(float(c[0]), float(c[1])) txt = self.zero3.get() if txt == ";": userInput['z2'] = None else: d = txt.split(";") userInput['z2'] = complex(float(d[0]), float(d[1])) p1 = userInput.get('p1') p2 = userInput.get('p2') z1 = userInput.get('z1') z2 = userInput.get('z2') if (p1 != complex(0, 0)) and (p2 != complex(0, 0)): if (z1 or z2) is None: if (z1 and z2) is None: if (p1 == None) or (p2 == None): self.pasabajos1Title.pack() if (p1 != None) and (p2 != None): self.pasabajos2Title.pack() if (z1 is None and z2 != None) or (z2 is None and z1 != None): if (p1 == None) or (p2 == None): self.pasatodo1Title.pack() if (z1 == complex(0, 0)) and (z2 == complex(0, 0)): self.pasaaltos2Title.pack() if (z1 == complex(0, 0) and z2 == None) or (z2 == complex(0, 0) and z1 == None): if (p1 == None) or (p2 == None): self.pasaaltos1Title.pack() if (p1 != None) and (p2 != None): self.pasabandaTitle.pack() if (z1 != None) and (z2 != None): self.pasatodo2Title.pack() print(userInput['p1']) print(userInput['z1']) print(userInput['p2']) print(userInput['z2']) self.zero2.delete(0, 'end') self.pole2.delete(0, 'end') self.zero3.delete(0, 'end') self.pole3.delete(0, 'end')
def focus(self): Vin = [1] Vout = [1] xinput = userInput.get("inputFunction") amp = userInput.get("inputAmplitude") finput = userInput.get("inputFreq") order = userInput.get("order") filterType = userInput.get("type") f0 = userInput.get("frequency") f1 = userInput.get("frequency2") k = userInput.get("gain") epsilon = userInput.get("epsilon") p1 = userInput.get("p1") z1 = userInput.get("z1") p2 = userInput.get("p2") z2 = userInput.get("z2") print("Order ", order, "Type ", filterType, "Freq ", f0, "Gain", k, "Eps ", epsilon) if order == 1: if filterType == "low": Vout = [k] Vin = [1 / f0, 1] elif filterType == "high": Vout = [k, 0] Vin = [1 / f0, 1] elif filterType == "all": Vout = [k / f0, -k] Vin = [1 / f0, +1] elif filterType == "guess": if z1 is None: Vout = [1] else: Vout = [1, -z1] Vin = [1, -p1] elif order == 2: if filterType == "low": Vout = [k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "high": Vout = [k, 0, 0] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "all": Vout = [k * pow(1 / f0, 2), -2 * k * epsilon / f0, k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "band": Vout = [k, 0] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "notch": Vout = [k * pow(1 / f0, 2), 0, k] Vin = [pow(1 / f0, 2), 2 * epsilon / f0, 1] elif filterType == "guess": if (z1 or z2) is None: if (z1 and z2) is None: Vout = [1] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] elif z1 == None: Vout = [1, -z2] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] elif z2 == None: Vout = [1, -z1] if p1 == None: Vin = [1, -p2] if p2 == None: Vin = [1, -p1] else: Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] else: Vout = [ pow(1 / sqrt(z1 * z2), 2), (-z1 - z2) / (z1 * z2), 1 ] Vin = [ pow(1 / sqrt(p1 * p2), 2), (-p1 - p2) / (p1 * p2), 1 ] self.H = ss.TransferFunction(Vout, Vin) self.ax1.clear() self.ax2.clear() if xinput == "Sine": t = linspace(0, 1, num=1000) u = amp * sin(2 * pi * finput * t) tout, yout, xout = ss.lsim(self.H, U=u, T=t) self.ax1.plot(t, u, color='r', linewidth=0.5) self.ax1.minorticks_on() self.ax1.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax1.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax1.set_title('Sinusoidal input signal') self.ax1.set_ylabel('Amplitude [V]') self.ax2.plot(tout, yout, color='b', linewidth=0.5) self.ax2.minorticks_on() self.ax2.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax2.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax2.set_title('Output signal') self.ax2.set_xlabel('Time [s]') self.ax2.set_ylabel('Amplitude [V]') elif xinput == "Step": t, Step = ss.step(self.H) self.ax1.plot(t, amp * heaviside(t, 0.5), color='b') self.ax1.minorticks_on() self.ax1.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax1.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax1.set_title('A*u(t) input signal') self.ax1.set_ylabel('Amplitude [V]') self.ax2.plot(t, amp * Step, color='r') self.ax2.minorticks_on() self.ax2.grid(which='major', color='black', linewidth=0.8, linestyle='--') self.ax2.grid(which='minor', color='black', linewidth=0.4, linestyle=':') # Sets figure data. self.ax2.set_title('Output signal') self.ax2.set_xlabel('Time [s]') self.ax2.set_ylabel('Amplitude [V]') self.canvas.draw() pass