Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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()