class SampleAndHold(Filter):
    def __init__(self):
        self.blockActivated = True
        self.samplingSignal = None

    def control_by_sampling_signal(self, sampling_signal):
        self.samplingSignal = None
        self.samplingSignal = Signal(sampling_signal.timeArray)
        self.samplingSignal.copy_signal(sampling_signal)

    def deactivate_block(self, deactivate):
        self.blockActivated = not deactivate

    def apply_to_signal(self, signal_in):
        returning_signal = Signal(None)
        returning_signal.copy_signal(signal_in)

        if self.blockActivated:

            out_x_array = signal_in.timeArray.copy()
            out_y_array = signal_in.yValues.copy()

            for it in range(0, len(signal_in.timeArray)):
                if self.samplingSignal.yValues[it] > 0.4:  # Chequea si la senal de sampleo esta activa
                    out_y_array[it] = signal_in.yValues[it]
                else:
                    if it > 0 and out_y_array[it - 1] is not None:
                        out_y_array[it] = out_y_array[it - 1]
                    else:
                        out_y_array[it] = 0

            returning_signal.set_x_y_values(out_x_array, out_y_array)
            returning_signal.set_step_plot(True)
        return returning_signal
Beispiel #2
0
class AnalogSwitch(Filter):
    def __init__(self):
        self.blockActivated = True
        self.samplingSignal = None

    def control_by_sampling_signal(self, sampling_signal):
        self.samplingSignal = Signal(sampling_signal.timeArray)
        self.samplingSignal.copy_signal(sampling_signal)

    def deactivate_block(self, deactivate):
        self.blockActivated = not deactivate

    def apply_to_signal(self, signal_in):
        returning_signal = Signal(None)
        returning_signal.copy_signal(signal_in)
        if self.blockActivated:

            out_x_array = signal_in.timeArray.copy()
            out_y_array = signal_in.yValues.copy()

            for it in range(0, len(signal_in.timeArray)):
                if self.samplingSignal.yValues[it] > 0.5:  # Chequea si la senal de sampleo esta activa
                    out_y_array[it] = signal_in.yValues[it]
                else:
                    out_y_array[it] = 0

            returning_signal.set_x_y_values(out_x_array, out_y_array)
            returning_signal.set_step_plot(True)
        return returning_signal

    def get_filter_freq_response(self):
        return self.angularFreq, self.freqResponse
 def add_signal_to_oscilloscope(self, signal):
     if self.hidden:
         self.hidden = False
         self.__show_oscilloscope__()
     new_signal = Signal(signal.timeArray)
     new_signal.copy_signal(signal)
     self.plot_signals.append(new_signal)
     list_widget_item = QListWidgetItem(new_signal.description)
     self.signalList.addItem(list_widget_item)
     self.plot_current_signals()
Beispiel #4
0
    def sampling_signal_changed(self, duty_cycle, period):
        if (self.blocks[BlockOrder.SampleAndHold.value].blockActivated
                and self.blocks[BlockOrder.AnalogSwitch.value].blockActivated):
            for i in range(SignalOrder.SampleAndHoldOut.value,
                           len(self.signals)):
                self.signals[i] = None

        self.samplingSignal = Signal(self.signals[0].timeArray)
        self.samplingSignal.create_square_signal(duty_cycle, period)
        self.blocks[BlockOrder.SampleAndHold.value].control_by_sampling_signal(
            self.samplingSignal)
        self.blocks[BlockOrder.AnalogSwitch.value].control_by_sampling_signal(
            self.samplingSignal)
Beispiel #5
0
 def xin_changed(self, xin):
     self.signals = [None, None, None, None, None, None]
     self.signals[0] = Signal(xin.timeArray)
     self.signals[0].copy_signal(xin)
     if self.samplingSignal is not None:
         self.samplingSignal.change_time_array(self.signals[0].timeArray)
         self.blocks[
             BlockOrder.SampleAndHold.value].control_by_sampling_signal(
                 self.samplingSignal)
         self.blocks[
             BlockOrder.AnalogSwitch.value].control_by_sampling_signal(
                 self.samplingSignal)
Beispiel #6
0
    def apply_to_signal(self, signal_in):
        returning_signal = Signal(None)
        returning_signal.copy_signal(signal_in)
        if self.blockActivated:

            out_x_array = signal_in.timeArray.copy()
            out_y_array = signal_in.yValues.copy()

            for it in range(0, len(signal_in.timeArray)):
                if self.samplingSignal.yValues[it] > 0.5:  # Chequea si la senal de sampleo esta activa
                    out_y_array[it] = signal_in.yValues[it]
                else:
                    out_y_array[it] = 0

            returning_signal.set_x_y_values(out_x_array, out_y_array)
            returning_signal.set_step_plot(True)
        return returning_signal
    def __show_oscilloscope__(self):
        try:
            loadUi('../GUI/FrontEnd/oscilloscope.ui', self)
        except:
            loadUi('GUI/FrontEnd/oscilloscope.ui', self)
        self.setWindowTitle("Osciloscopio")

        self.spectrumWindowCombo.addItem("Automática")
        self.spectrumWindowCombo.addItems(Signal.get_window_types())



        self.removeSignal.clicked.connect(self.remove_signal_from_oscilloscope)
        self.removeAllSignals.clicked.connect(self.remove_all_signals_from_oscilloscope)
        self.toggleSignal.clicked.connect(self.toggle_signal)

        self.graphSpectrum.clicked.connect(self.graph_spectrum)
        self.plot_current_signals()

        self.show()
Beispiel #8
0
    def get_signal(self, signal_order):
        returning_signal = Signal(None)
        if self.signals[signal_order] is not None:

            returning_signal.copy_signal(self.signals[signal_order])
            return returning_signal
        else:
            found = False
            i = signal_order - 1
            while not found and i >= 0:
                if self.signals[i] is not None:
                    found = True
                else:
                    i -= 1
            if not found:
                return None
            else:
                for it in range(i, signal_order):
                    self.signals[it + 1] = self.blocks[it].apply_to_signal(
                        self.signals[it])

                returning_signal.copy_signal(self.signals[signal_order])

                return returning_signal
 def control_by_sampling_signal(self, sampling_signal):
     self.samplingSignal = None
     self.samplingSignal = Signal(sampling_signal.timeArray)
     self.samplingSignal.copy_signal(sampling_signal)
 def apply_to_signal(self, signal_in):
     returning_signal = Signal(None)
     returning_signal.copy_signal(signal_in)
     if self.blockActivated:
         if 1 / signal_in.period <= 3.9:
             tout, y, ni = signal.lsim(
                 (self.b1, self.a1), signal_in.yValues, signal_in.timeArray)
             returning_signal.set_x_y_values(tout, y)
             returning_signal.cut_first_period()
         elif 3510 >= 1 / signal_in.period > 3.9:
             tout, y, ni = signal.lsim(
                 (self.b2, self.a2), signal_in.yValues, signal_in.timeArray)
             returning_signal.set_x_y_values(tout, y)
             returning_signal.cut_first_period()
         else:
             tout, y, ni = signal.lsim(
                 (self.b3, self.a3), signal_in.yValues, signal_in.timeArray)
             returning_signal.set_x_y_values(tout, y)
             returning_signal.cut_first_period()
     return returning_signal
Beispiel #11
0
 def add_signal(self, signal, signal_order):
     new_aux = Signal(signal.timeArray)
     new_aux.copy_signal(signal)
     self.signals[signal_order] = new_aux
Beispiel #12
0
class Data:
    def __init__(self):
        self.signals = [None, None, None, None, None]
        self.blocks = [None, None, None, None]
        self.samplingSignal = None

    def block_property_changed(self, block_num):
        for i in range(
                block_num, len(self.blocks)
        ):  # reconstruyo desde el bloque que cambio hasta el final
            self.signals[i + 1] = None

    def xin_changed(self, xin):
        self.signals = [None, None, None, None, None, None]
        self.signals[0] = Signal(xin.timeArray)
        self.signals[0].copy_signal(xin)
        if self.samplingSignal is not None:
            self.samplingSignal.change_time_array(self.signals[0].timeArray)
            self.blocks[
                BlockOrder.SampleAndHold.value].control_by_sampling_signal(
                    self.samplingSignal)
            self.blocks[
                BlockOrder.AnalogSwitch.value].control_by_sampling_signal(
                    self.samplingSignal)

    def sampling_signal_changed(self, duty_cycle, period):
        if (self.blocks[BlockOrder.SampleAndHold.value].blockActivated
                and self.blocks[BlockOrder.AnalogSwitch.value].blockActivated):
            for i in range(SignalOrder.SampleAndHoldOut.value,
                           len(self.signals)):
                self.signals[i] = None

        self.samplingSignal = Signal(self.signals[0].timeArray)
        self.samplingSignal.create_square_signal(duty_cycle, period)
        self.blocks[BlockOrder.SampleAndHold.value].control_by_sampling_signal(
            self.samplingSignal)
        self.blocks[BlockOrder.AnalogSwitch.value].control_by_sampling_signal(
            self.samplingSignal)

    def valid_sampling_period(self, period):
        signal_period = self.signals[0].period
        if signal_period / 1000 <= period <= signal_period * 2:
            return True
        return False

    def add_signal(self, signal, signal_order):
        new_aux = Signal(signal.timeArray)
        new_aux.copy_signal(signal)
        self.signals[signal_order] = new_aux

    def add_block(self, block, block_order):
        self.blocks[block_order] = block

    def get_signal(self, signal_order):
        returning_signal = Signal(None)
        if self.signals[signal_order] is not None:

            returning_signal.copy_signal(self.signals[signal_order])
            return returning_signal
        else:
            found = False
            i = signal_order - 1
            while not found and i >= 0:
                if self.signals[i] is not None:
                    found = True
                else:
                    i -= 1
            if not found:
                return None
            else:
                for it in range(i, signal_order):
                    self.signals[it + 1] = self.blocks[it].apply_to_signal(
                        self.signals[it])

                returning_signal.copy_signal(self.signals[signal_order])

                return returning_signal

    def xin_exists(self):
        if self.signals[0] is not None:
            return True
        else:
            return False

    def sampling_exists(self):
        if self.samplingSignal is not None:
            return True
        elif not self.blocks[BlockOrder.SampleAndHold.
                             value].blockActivated and not self.blocks[
                                 BlockOrder.AnalogSwitch.
                                 value].blockActivated:  # no necesito sampleo
            return True
        else:
            return False
Beispiel #13
0
    def refresh_xin_clicked(self):
        self.errorLabel.setText('')
        if self.pulseRadio.isChecked():
            time_array = np.linspace(0, 1, Signal.timeTick)
            xin_signal = Signal(time_array)
            xin_signal.create_dirac_signal()
            xin_signal.add_description("Input: Impulso.")

            self.data.xin_changed(xin_signal)

        elif self.sineRadio.isChecked():
            freq = self.param2Value.value()
            freq_mult_text = self.param2Unit.currentText()
            freq_mult_value = self.frequencyMultipliers[freq_mult_text]
            total_freq = freq * freq_mult_value

            amplitude = self.param1Value.value()
            amplitude_mult_text = self.param1Unit.currentText()
            amplitude_mult_value = self.tensionMultipliers[amplitude_mult_text]

            phase = self.param3Value.value()
            phase_mult_text = self.param3Unit.currentText()
            phase_mult_value = self.phaseMultipliers[phase_mult_text]

            time_array = np.linspace(0, Signal.showingPeriods / total_freq,
                                     Signal.showingPeriods * Signal.timeTick)
            xin_signal = Signal(time_array)

            xin_signal.create_cos_signal(total_freq,
                                         amplitude * amplitude_mult_value,
                                         phase=phase * phase_mult_value)
            xin_signal.add_description("Input: " + str(amplitude) +
                                       amplitude_mult_text + "*cos(2π*" +
                                       str(freq) + freq_mult_text + " + " +
                                       str(phase) + phase_mult_text + ")")

            self.data.xin_changed(xin_signal)

        elif self.halfSineRadio.isChecked():
            freq = self.param2Value.value()
            freq_mult_text = self.param2Unit.currentText()
            freq_mult_value = self.frequencyMultipliers[freq_mult_text]
            total_freq = freq * freq_mult_value

            amplitude = self.param1Value.value()
            amplitude_mult_text = self.param1Unit.currentText()
            amplitude_mult_value = self.tensionMultipliers[amplitude_mult_text]

            phase = self.param3Value.value()
            phase_mult_text = self.param3Unit.currentText()
            phase_mult_value = self.phaseMultipliers[phase_mult_text]

            time_array = np.linspace(0, (Signal.showingPeriods * 3 / 2) /
                                     total_freq,
                                     Signal.showingPeriods * Signal.timeTick)
            xin_signal = Signal(time_array)

            xin_signal.create_half_sine_signal(total_freq,
                                               amplitude *
                                               amplitude_mult_value,
                                               phase=phase * phase_mult_value)
            xin_signal.add_description("Input: " + str(amplitude) +
                                       amplitude_mult_text + "*sin(2π*" +
                                       str(freq) + freq_mult_text + " + " +
                                       str(phase) + phase_mult_text +
                                       " ), período: " +
                                       str((3 / 2) * (1 / total_freq)) + "s")

            self.data.xin_changed(xin_signal)

        elif self.amRadio.isChecked():
            freq = self.param2Value.value()
            freq_mult_text = self.param2Unit.currentText()
            freq_mult_value = self.frequencyMultipliers[freq_mult_text]
            total_freq = freq * freq_mult_value

            amplitude = self.param1Value.value()
            amplitude_mult_text = self.param1Unit.currentText()
            amplitude_mult_value = self.tensionMultipliers[amplitude_mult_text]

            phase = self.param3Value.value()
            phase_mult_text = self.param3Unit.currentText()
            phase_mult_value = self.phaseMultipliers[phase_mult_text]

            time_array = np.linspace(0, Signal.showingPeriods * 5 / total_freq,
                                     Signal.showingPeriods * Signal.timeTick)
            xin_signal = Signal(time_array)

            xin_signal.create_am_signal(total_freq,
                                        amplitude * amplitude_mult_value,
                                        phase=phase * phase_mult_value)
            xin_signal.add_description("Input: Señal AM")
            '''xin_signal.add_description("Input: " + str(amplitude) + amplitude_mult_text + "*(1/2*cos(2π*1,8*" + str(freq) + freq_mult_text + "*t + " + str(
                                       phase) + phase_mult_text + ") + cos(2π*2*" + str(freq) + freq_mult_text + "*t + " + str(
                                       phase) + phase_mult_text + ") + 1/2*cos(2π*2,2*" + str(freq) + freq_mult_text + "*t + " + str(
                                       phase) + phase_mult_text + ")), período: " + str((5 / total_freq)) + "s")'''

            self.data.xin_changed(xin_signal)

        elif self.expRadio.isChecked():
            vmax_v = self.param1Value.value()
            vmax_unit_text = self.param1Unit.currentText()
            vmax_unit_value = self.tensionMultipliers[vmax_unit_text]

            period_value = self.param2Value.value()
            period_mult_text = self.param2Unit.currentText()
            period_mult_value = self.periodMultipliers[period_mult_text]
            total_period = period_value * period_mult_value

            time_array = np.linspace(0, Signal.showingPeriods * total_period,
                                     Signal.showingPeriods * Signal.timeTick)
            xin_signal = Signal(time_array)

            xin_signal.create_exp_signal(vmax_v * vmax_unit_value,
                                         total_period)

            xin_signal.add_description("Input: " + str(vmax_v) +
                                       vmax_unit_text +
                                       "*e^(-|t|), período: " +
                                       str(period_value) + period_mult_text)

            self.data.xin_changed(xin_signal)