def SubniquistSpectrum(input, fs, filename): config.GetConfigData().setFs(fs) config.GetConfigData().setSampleCycle(5) inputSpectrum = FourierTransform.fourierTransform(input) output = SampleAndHold.getSampleAndHold().processInput(input, None, 1) outputSpectrum = FourierTransform.fourierTransform(output) ExpressPlot.CombinedPlot()\ .setTitle("Simulación espectro $f_s="+str(fs/1000)+"k$")\ .setXTitle("Frecuencia (hz)")\ .setYTitle("Potencia (% del total)") \ .extraPlot( plotFunction, {"fs": fs}) \ .addSignalPlot( signal=inputSpectrum, color="green", name="Entrada" )\ .addSignalPlot( signal=outputSpectrum, color="orange", name="Salida sample and hold" ).plotAndSave( filename="ExpressOutput/"+filename )
def processInput(self, inputSignal, loadingModel, fraction): output = [0] * len(inputSignal.xvar) timePeriod = 1 / config.GetConfigData().fs cyclesPeriod = int(timePeriod / inputSignal.separation) toffCycles = int(config.GetConfigData().LLoff * cyclesPeriod) paso = fraction / len(inputSignal.xvar) aux = 0 for ti in range(len(inputSignal.xvar)): if ti % cyclesPeriod >= toffCycles: output[ti] = inputSignal.values[ti] else: output[ti] = 0 aux += paso if ti % 1000 == 0: if loadingModel: loadingModel.update(aux) aux = 0 if loadingModel: loadingModel.update(aux) return Senial.Senial(inputSignal.xvar, output)
def processInput(self, inputSignal, loadingModel, fraction): timePeriod = 1 / config.GetConfigData().fs cyclesPeriod = int(timePeriod / inputSignal.separation) output = [0] * len(inputSignal.xvar) paso = fraction / len(inputSignal.xvar) aux = 0 for i in range(len(inputSignal.xvar)): # tres casos fractionTime = i % cyclesPeriod if fractionTime < config.GetConfigData().SHsample * cyclesPeriod: output[i] = inputSignal.values[i] elif fractionTime < (config.GetConfigData().SHsample + config.GetConfigData().SHhold) * cyclesPeriod: if i != 0: output[i] = output[i - 1] else: output[i] = 0 aux += paso if i % 1000 == 0: if loadingModel: loadingModel.update(aux) aux = 0 if loadingModel: loadingModel.update(aux) return Senial.Senial(inputSignal.xvar, output)
def testsubplot(): s_in = SignalsReadWrite.readSignal("Signals/Coseno_0.5k_2Vp.xml") config.GetConfigData().setFs(4000) config.GetConfigData().setSampleCycle(50) s_sh = SampleAndHold.getSampleAndHold().processInput(s_in, None, 1) s_out = LlaveAnalogica.getLlaveAnalogica().processInput(s_sh, None, 1) f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True) ax1.plot(s_in.xvar, s_in.values) # ax1.set_title('Sharing both axes') ax2.plot(s_sh.xvar, s_sh.values) ax3.plot(s_out.xvar, s_out.values) # Fine-tune figure; make subplots close to each other and hide x ticks for # all but bottom plot. f.subplots_adjust(hspace=0) plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False) ticks = np.arange(0, 0.00401, 0.0005 / 4) #ticks = ticks + [ticks[1]+ticks[-1]] ax1.xaxis.set_ticks(ticks, minor=True) ax2.xaxis.set_ticks(ticks, minor=True) ax3.xaxis.set_ticks(ticks, minor=True) ax1.grid(axis='x', which='major', linestyle='-', linewidth=0.3, color='black') ax1.grid(axis='x', which='minor', linestyle=':', linewidth=0.1, color='black') ax2.grid(axis='x', which='major', linestyle='-', linewidth=0.3, color='black') ax2.grid(axis='x', which='minor', linestyle=':', linewidth=0.1, color='black') ax3.grid(axis='x', which='major', linestyle='-', linewidth=0.3, color='black') ax3.grid(axis='x', which='minor', linestyle=':', linewidth=0.1, color='black') plt.show()
def goToPlotMenu(self): if Modes.getModes().getFilename() and not self.isLoading: config.GetConfigData().setFs(self.slider1.getValue()) config.GetConfigData().setSampleCycle(self.slider2.getValue()) config.GetConfigData().save() config.GetConfigData().load() self.button.configure(state=tk.DISABLED) self.isLoading = True thread = Thread(target=ProcessSignals.processSignals, args=(Modes.getModes().getFilename(), Modes.getModes().modesEnabled, self.loadingModel)) thread.start()
def loadTf(self): s = sp.symbols("s") wp = 2 * pi * config.GetConfigData().FAAfreq self.addTf(1 / ((s / wp)**2 + 0.5548 * (s / wp) + 0.2702), s) self.addTf(1 / ((s / wp)**2 + 0.0918 * (s / wp) + 0.9870), s) self.addTf(1 / ((s / wp)**2 + 0.4284 * (s / wp) + 0.5282), s) self.addTf(1 / ((s / wp)**2 + 0.2650 * (s / wp) + 0.8013), s) self.addTf(1 / (72 * ((s / wp)**2 + 0.6344 * (s / wp) + 0.1218)), s) return self.tf
def makeBodes(): config.GetConfigData().FAAfreq = 1600 f = logspace(2.3, 3.5, 200000) wrange = [fi * 2 * pi for fi in f] w, mag, pha = FiltroLP.getFiltroLP().getBode(wrange) frange = [wi / 2 / pi for wi in w] senialTeorica = Senial.Senial(frange, mag) ExpressPlot.CombinedPlot()\ .setTitle("Respuesta en frecuencia")\ .setXTitle("Frecuencia (Hz)")\ .setYTitle("Amplitud (dB)")\ .setLogarithmic()\ .addSignalPlot( signal=senialTeorica, color="blue", name="Teórica" )\ .addSpiceBodePlot( filename="ExpressInput/SimulacionV2/bode_Modulo_Sim.txt", color="red", name="Simulación", mode=ExpressPlot.MAG )\ .addCSVQuotient( filename="ExpressInput/Mediciones/Filtro FAA/bode_moduloFAA.csv", fieldX="Frequency (Hz)", fieldA="Channel 1 Magnitude (dB)", fieldB="Channel 2 Magnitude (dB)", color="green", name="Medición FR", )\ .plotAndSave(filename="ExpressOutput/bodeFiltrosCaso3.png") plt.show()
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller label = tk.Label(self, height=2, text="Configuración", font=config.LARGE_FONT) label.pack(side=tk.TOP, fill=tk.BOTH) self.filename = "" self.btnText = tk.StringVar() self.buttonSelectFile = tk.Button(self, height=2, width=44, textvariable=self.btnText, background="dodger blue", font=config.SMALL_FONT, command=self.searchFile) self.btnText.set("Seleccionar entrada") self.slider1 = SliderModel(1, 5000, 5, config.GetConfigData().FAAfreq, "Sample rate (hz)") self.slider1cont = SliderContainer(self, self.slider1) self.slider1cont.pack(side=tk.TOP, fill=tk.BOTH) self.slider1.setContainer(self.slider1cont) self.slider1.setValue(config.GetConfigData().fs) self.slider2 = SliderModel(2, 98, 1, config.GetConfigData().FAAfreq, "Sample cycle (%)") self.slider2cont = SliderContainer(self, self.slider2) #print(config.GetConfigData().SHhold) self.slider2.setContainer(self.slider2cont) self.slider2.setValue(config.GetConfigData().SHhold * 100) self.slider2cont.pack(side=tk.TOP, fill=tk.BOTH) self.buttonSelectFile.pack(side=tk.TOP, fill=tk.BOTH) for mode in Modes.getModes().modesEnabled.keys(): checkButton = tk.Checkbutton( self, text=mode, variable=Modes.getModes().modesEnabled[mode], height=3, width=44, font=config.SMALL_FONT, background="light yellow") checkButton.pack(side=tk.TOP, fill=tk.BOTH) self.loadingModel = None self.isLoading = False self.loadingModel = LoadingModel(0, 100) self.loading = LoadingContainer(self, self.loadingModel) self.loadingModel.setContainer(self.loading) self.loading.pack(side=tk.BOTTOM, fill=tk.BOTH) self.loadingModel.setOnLoadedListener(self.onDataCalc) self.button = tk.Button(self, height=1, width=44, background="pale green", text="ACEPTAR", font=config.LARGE_FONT, command=lambda: self.goToPlotMenu()) self.button.pack(side=tk.BOTTOM, fill=tk.BOTH)