def GenerateAM(fp, fm, t0, tf, vp): times = linspace(t0, tf, 100000) values = [vp*(cos(2*pi*fp*t) + cos(2*pi*(fp-fm)*t)/2 + cos(2*pi*(fp+fm)*t)/2) for t in times] SignalsReadWrite.writeSignal( Senial.Senial(times, values), "Signals/AM_" + str(fp / 1000) + "kHz.xml" )
def GenerateSine(freq, a, b, vp): #print(freq) times = linspace(a, b, 100000) values = [vp*sin(2*pi*freq*t) for t in times] SignalsReadWrite.writeSignal( Senial.Senial(times, values), "Signals/Seno_"+str(freq/1000)+"k.xml" )
def GenerateSquare(start, end, vp): times = linspace(0, 0.005, 100000) values = [vp*square(t, start, end) for t in times] SignalsReadWrite.writeSignal( Senial.Senial(times, values), "Signals/Sqaure_" + str(start / 1000) + "_" + str(end/1000) + "ms.xml" )
def Generate32Sine(freq, a, b, vp): times = linspace(a, b, 100000) T = 2/3/freq values = [vp*Sine32(t, T) for t in times] SignalsReadWrite.writeSignal( Senial.Senial(times, values), "Signals/Sine32_" + str(freq / 1000) + "k.xml" )
def subniquistTest(): #m = 3 s1 = SignalsReadWrite.readSignal("Signals/AM_2.4Khz.xml") s2 = SampleAndHold.SampleAndHold().processInput(s1, None, 1) #s3 = SignalsReadWrite.readSignal("Signals/AM_0.36Khz.xml") fs = 2040 lowcut = 2400 - 250 highcut = 2400 + 250 print(1 / s1.separation) #print(s1.xvar[1] - s1.xvar[0]) values = butter_bandpass_filter(s2.values, lowcut, highcut, 1 / s1.separation, order=2) values = [v for v in values] s3 = Senial.Senial(s2.xvar, values) #print(s3.values) CombinedPlot() \ .addSignalPlot(s1, "orange", "Señal AM 2.4Khz") \ .addSignalPlot(s2, "blue", "Salida LLave analogica") \ .addSignalPlot(s3, "green", "señal subniquist") \ .plotAndSave("IndividualTests/test_niquist.png") plt.show()
def GenerateExp(f, t0, tf, vp): times = linspace(t0, tf, 100000) values = [] for t in times: t = abs(t) T = 1/f if t > T/2: t -= (ceil(t/T)-1)*T if t > T/2: t -= T values.append(vp * exp(-abs(t * (10 * f)))) SignalsReadWrite.writeSignal( Senial.Senial(times, values), "Signals/Exp_" + str(f) + "Hz.xml" )
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 addXMLPlot(self, filename, name, color): signal = SignalsReadWrite.readSignal(inputDirectory + "/" + filename) signal.mode = "teorica" self.plotCount.append( { "signal": signal, "color": color, "name": name } ) return self
def processSignals(inputFile, modes, loadingModel): signal = SignalsReadWrite.readSignal(inputFile) PlotSignals.getSignalsData().setSignal("Entrada", signal) total = modes["FAA"].get() + \ modes["Sample and Hold"].get() + \ modes["Llave analógica"].get() + \ modes["FR"].get() if total != 0: fraction = 100 / total else: fraction = 1 print("processing") if modes["FAA"].get(): signal = FiltroLP.getFiltroLP().processInput(signal, loadingModel, fraction) PlotSignals.getSignalsData().setSignal("FAA", signal) #loadingModel.update(fraction) print("A") if modes["Sample and Hold"].get(): signal = SampleAndHold.getSampleAndHold().processInput( signal, loadingModel, fraction) PlotSignals.getSignalsData().setSignal("Sample and Hold", signal) #loadingModel.update(fraction) print("B") if modes["Llave analógica"].get(): signal = LlaveAnalogica.getLlaveAnalogica().processInput( signal, loadingModel, fraction) PlotSignals.getSignalsData().setSignal("Llave analógica", signal) #loadingModel.update(fraction) print("C") if modes["FR"].get(): signal = FiltroLP.getFiltroLP().processInput(signal, loadingModel, fraction) PlotSignals.getSignalsData().setSignal("FR", signal) #loadingModel.update(fraction) print("D") loadingModel.callOnFinished()
def spectra_plot(medcsv, simxml, out, fmax=None): fmed = [] pmed = [] with open(medcsv, 'rt') as csvfile: reader = list(csv.reader(csvfile)) # hola = csv.reader(csvfile) reader.pop(0) # saco el header, me quedo solo con las mediciones if fmax is None: fmax = float(reader[-1][0]) for row in reader: f = float(row[0]) if f > fmax: break fmed.append(f) pmed.append((10**(float(row[1]) / 20))**2) #plt.plot(fmed, pmed) #plt.show() s1 = Senial.Senial(fmed, pmed) s_xml = SignalsReadWrite.readSignal(simxml) s2 = FourierTransform.fourierTransform(s_xml) fsim = [] psim = [] for f in s2.xvar: if f < 0: continue if f > fmax: break fsim.append(f) psim.append(s2.values[s2.xvar.index(f)]) s2.xvar = fsim s2.values = psim psum = sum(s2.values) s2.values = [v / psum * 100 for v in s2.values] psum = sum(pmed) s1.values = [v / psum * 100 for v in s1.values] ExpressPlot.CombinedPlot()\ .setTitle(" ")\ .setXTitle("Frecuencia (Hz)")\ .setYTitle("Potencia (% de total)")\ .addSignalPlot( signal=s1, color="orange", name="Medido" )\ .addSignalPlot( signal=s2, color="blue", name="Simulado" )\ .plotAndSave( filename=out ) plt.show()
def saveFile(self): if self.currentSignal: filename = filedialog.asksaveasfile(mode='w', defaultextension=".xls") if filename: SignalsReadWrite.writeSignal(self.currentSignal, filename.name)