Esempio n. 1
0

def play(u1, u2):
    reference = u1[0]
    measured = u2[0]
    power = 10.0 * np.log10(measured / reference)
    amplitude = 20.0 * np.log10(measured / reference)
    return power, amplitude


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.description = """
Calculate ratio in decibels
    """
    parser.add_argument("arg1",
                        help='Reference numeric value (No units are expected)')
    parser.add_argument("arg2",
                        help='Measured numeric value (No units are expected)')
    args = parser.parse_args()

    arg1 = units.parse(args.arg1)
    arg2 = units.parse(args.arg2)

    res = play(arg1, arg2)
    msg1 = units.format_verbose(res[0], 'dB')
    msg2 = units.format_verbose(res[1], 'dB')

    print('Power ratio    : {0}'.format(msg1))
    print('Amplitude ratio: {0}'.format(msg2))
Esempio n. 2
0
        print('R1 is expected to be [{0}]'.format(U.R))
        os.exit(-1)

    if r2[1] != U.R:
        print('R2 is expected to be [{0}]'.format(U.R))
        os.exit(-1)

    return v_in[0] * r2[0] / (r1[0] + r2[0]), U.V


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.description = """
Voltage divider. Provide input voltage [V], first resistance [Ω] and second resistance [Ω].
The resulting voltage will be calculated according to the formula:
V_out = V_in * R2 / (R1 + R2)
For example: volt_divider.py 10V 4k7 1k2
    """
    parser.add_argument("arg1", help='Input voltage V_in [V]')
    parser.add_argument("arg2", help='First resistor of the divider R1 [Ω]')
    parser.add_argument("arg3", help='Second resistor of the divider R2 [Ω]')
    args = parser.parse_args()

    arg1 = units.parse(args.arg1)
    arg2 = units.parse(args.arg2)
    arg3 = units.parse(args.arg3)

    res = play(arg1, arg2, arg3)
    msg = units.format_verbose(res[0], res[1])
    print(msg)