Exemplo n.º 1
0
def onComputeErrorParameters(window, values, storedSignals):
    selectedGraphs = values['selectedGraphs']
    if len(selectedGraphs) != 1:
        sg.Popup('Error!', 'Select 1 graph for error parameters computation!')
        return None

    selectedSignal = storedSignals[getSelectedGraphIndex(selectedGraphs[0])]
    name, x, y, params = pluck(selectedSignal, 'name', 'x', 'y', 'params')

    actualValuesForSignal = computeSignal(selectedSignal, x)

    #test
    newSignal = {
        **selectedSignal, 'displayName':
        f"computed: {selectedSignal['displayName']}",
        'y': actualValuesForSignal
    }
    addToSelectionList(window, newSignal, storedSignals)
    #test

    errors = calculateErrorStatistics(selectedSignal['y'],
                                      actualValuesForSignal)
    MSE, SNR, PSNR, MD, ENOB = pluck(errors, 'MSE', 'SNR', 'PSNR', 'MD',
                                     'ENOB')

    sg.Popup(
        'Signal properties', f"""
        MSE: {MSE}
        SNR: {SNR}
        PSNR: {PSNR}
        MD: {MD}
        ENOB: {ENOB}
        """)
def onGenerateSpectrum(window, selectedSignals, storedSignals):
    if (len(selectedSignals) != 1):
        sg.Popup('Error!', "Select single signal")
    else:
        selectedSignal = storedSignals[getSelectedGraphIndex(
            selectedSignals[0])]
        spectrum = ops.calculateSpectrum(selectedSignal)
        addToSelectionList(window, spectrum, storedSignals)
Exemplo n.º 3
0
def onReconstructSignal(window, values, storedSignals):
    selectedGraphs = values['selectedGraphs']
    if len(selectedGraphs) != 1:
        sg.Popup('Error!', 'Select 1 graph to reconstruct!')
        return None

    reconstructed = reconstruct(storedSignals[getSelectedGraphIndex(
        selectedGraphs[0])],
                                params=values)
    addToSelectionList(window, reconstructed, storedSignals)
Exemplo n.º 4
0
def onQuantizeSignal(window, values, storedSignals):
    selectedGraphs = values['selectedGraphs']
    if len(selectedGraphs) != 1:
        sg.Popup('Error!', 'Select 1 graph to quantize!')
        return None

    steps = try_int(values['quantizationSteps'])
    if steps == None:
        sg.Popup('Error!', 'Specify amount of quantization levels!')
        return None

    selectedGraph = storedSignals[getSelectedGraphIndex(selectedGraphs[0])]
    quantized = quantize(selectedGraph, steps)

    addToSelectionList(window, quantized, storedSignals)
Exemplo n.º 5
0
def onSampleSignal(window, values, storedSignals):
    selectedGraphs = values['selectedGraphs']
    if len(selectedGraphs) != 1:
        sg.Popup('Error!', 'Select 1 graph to sample!')
        return None

    fp = try_float(values['samplingFrequency'])
    if fp == None or fp == 0:
        sg.Popup('Error!', 'Specify correct sampling frequency!')
        return None

    selectedGraph = storedSignals[getSelectedGraphIndex(selectedGraphs[0])]
    sampled = sample(selectedGraph, fp)

    addToSelectionList(window, sampled, storedSignals)
def onGenerateSignal(window, values, storedSignals):
    signalType = values["signalType"]
    inputFields = signals[signalType]["fields"]
    inputValues = {k: v for k, v in values.items() if k in inputFields}
    err_msg, param_values = validate_input(inputValues)
    if err_msg != "":
        sg.Popup('Error!', err_msg)
        return

    xSet, ySet = generate_signal(signalType, param_values)

    newSignal = {
        'name': signalType,
        'displayName': signalType,
        'isDiscrete': signals[signalType]['isDiscrete'],
        'isPeriodic': signals[signalType]['isPeriodic'],
        'isComplex': False,
        'x': xSet,
        'y': ySet,
        'params': param_values
    }
    addToSelectionList(window, newSignal, storedSignals)
Exemplo n.º 7
0
def onFilter(window, values, storedSignals):
    errors, params = assembleFilterParams(values)
    if errors != "":
        sg.Popup('Invalid parameters', errors)
        return None

    selectedSignal = values['selectedGraphs']
    if len(selectedSignal) != 1:
        sg.Popup('Error!', 'Select 1 graph to filter!')
        return None
    selectedSignal = storedSignals[getSelectedGraphIndex(selectedSignal[0])]

    if not values["useK?"]:
        params["K"] = selectedSignal["params"]["fp"] / params["K"]

    filter, filteredSignal = filterSignal(selectedSignal, **params)

    filteredSignal = {
        'name': selectedSignal["name"],
        'displayName': f"filtered {selectedSignal['displayName']}",
        'isDiscrete': False,
        'isComplex': False,
        'isPeriodic': False,
        'x': selectedSignal["x"],
        'y': filteredSignal,
        "params": selectedSignal['params']
    }

    filterTransmittance = operations.calculateFilterTransmittance(
        selectedSignal, filteredSignal)

    impulseResponse = {
        'name': selectedSignal["name"],
        'displayName': f"filter",
        'isDiscrete': False,
        'isComplex': False,
        'isPeriodic': False,
        'x': np.linspace(0,
                         len(filter) - 1, len(filter)),
        'y': filter,
        "params": selectedSignal['params']
    }

    addToSelectionList(window, filteredSignal, storedSignals)
    addToSelectionList(window, impulseResponse, storedSignals)
    addToSelectionList(window, filterTransmittance, storedSignals)
def onDivideSignals(window, values, storedSignals):
    first, second = ops.extractSignalsForOperation(values, storedSignals)
    if first == None: return
    newSignal = ops.applyOperation("/", first, second)
    if (newSignal != None):
        addToSelectionList(window, newSignal, storedSignals)
Exemplo n.º 9
0
def readFile(window, values, storedSignals):
    fileName = values['readFile']
    signal = fileOps.readFile(fileName)
    if (signal == None):
        return
    addToSelectionList(window, signal, storedSignals)