예제 #1
0
def inductive_reactance(l, f=1000.0) -> Quantity("Ω"):
    """
    Compute the inductive reactance for a given inductance and frequency.
    """
    l, _ = autoNormalizeEngineerInput(l)
    f, _ = autoNormalizeEngineerInput(f)
    return 2 * np.pi * f * l
예제 #2
0
def capacitive_reactance(c, f=1000.0) -> Quantity("Ω"):
    """
    Compute the capacitive reactance for a given capacitance and frequency.
    """
    c, _ = autoNormalizeEngineerInput(c)
    f, _ = autoNormalizeEngineerInput(f)
    return 1.0 / (2 * np.pi * f * c)
예제 #3
0
def capacitor_energy(capacitance, voltage) -> Quantity("J"):
    """
    Compute the total energy stored in a capacitor given:
    - The capacitance in farads
    - The voltage the capacitor is charged to
    The energy is returned as joules.
    """
    capacitance, _ = autoNormalizeEngineerInput(capacitance)
    voltage, _ = autoNormalizeEngineerInput(voltage)
    return 0.5 * capacitance * np.square(voltage)
예제 #4
0
def capacitor_charge(capacitance, voltage) -> Quantity("C"):
    """
    Compute the total charge stored in a capacitor given:
    - The capacitance in farads
    - The voltage the capacitor is charged to
    The charge is returned in coulombs.
    """
    capacitance, _ = autoNormalizeEngineerInput(capacitance)
    voltage, _ = autoNormalizeEngineerInput(voltage)
    return capacitance * voltage
예제 #5
0
def johnson_nyquist_noise_voltage(r, delta_f, T) -> Quantity("V"):
    """
    Compute the Johnson Nyquist noise current in amperes
    T must be given in °C whereas r must be given in Ohms.
    The result is given in volts
    """
    r, _ = autoNormalizeEngineerInput(r)
    delta_f, _ = autoNormalizeEngineerInput(delta_f)
    t_kelvin = normalize_temperature(T)
    return math.sqrt(4 * scipy.constants.k * t_kelvin * delta_f * r)
예제 #6
0
def actualNoise(density, bandwith) -> Quantity("V"):
    """
    Compute the actual noise given:
     - A noise density in x/√Hz where x is any unit
     - A bandwith in ΔHz

    >>> autoFormat(actualNoise, "100 µV", "100 Hz")
    '1.00 mV'
    """
    density, _ = autoNormalizeEngineerInput(density)
    bandwith, _ = autoNormalizeEngineerInput(bandwith)
    return np.sqrt(bandwith) * density
예제 #7
0
def noiseDensity(actual_noise, bandwith) -> Quantity("V/√Hz"):
    """
    Compute the noise density given:
     - A noise density in x/√Hz where x is any unit
     - A bandwith in ΔHz

    >>> formatValue(noiseDensity("1.0 mV", "100 Hz"), "V/√Hz")
    '100 μV/√Hz'
    """
    actual_noise, _ = autoNormalizeEngineerInput(actual_noise)
    bandwith, _ = autoNormalizeEngineerInput(bandwith)
    return actual_noise / np.sqrt(bandwith)
예제 #8
0
def ptx_temperature(r0, r, standard=ptxITS90, poly=None) -> Quantity("°C"):
    """
    Compute the PTx temperature at a given temperature.

    Accepts an additive correction polynomial that is applied to the resistance.
    If the poly kwarg is None, the polynom is automatically selected.
    noCorrection is used for other r0 values. In this case, use a
    custom polynomial (numpy poly1d object) as the poly kwarg.

    See http://www.thermometricscorp.com/pt1000 for reference
    """
    r, _ = autoNormalizeEngineerInput(r)
    A, B = standard.a, standard.b
    # Select
    if poly is None:
        if abs(r0 - 1000.0) < 1e-3: poly = pt1000Correction
        elif abs(r0 - 100.0) < 1e-3: poly = pt100Correction
        else: poly = noCorrection

    t = ((-r0 * A + np.sqrt(r0 * r0 * A * A - 4 * r0 * B * (r0 - r))) /
         (2.0 * r0 * B))
    # For subzero-temperature refine the computation by the correction polynomial
    if isinstance(r, numbers.Number):
        if r < r0:
            t += poly(r)
    else:  # Treated like a numpy array
        t += poly(r) * np.piecewise(r, [r < r0, r >= r0], [1.0, 0.0])
    return t
예제 #9
0
def summing_amplifier_noninv(v1, v2, r1, r2, rfb1, rfb2) -> Quantity("V"):
    """
    Computes the output voltage of a non-inverting summing amplifier:
    V1 connected via R1 to IN+
    V2 connected via R2 to IN+
    IN- connected via RFB1 to GND
    IN- connected via RFB2 to VOut
    """
    v1, _ = autoNormalizeEngineerInput(v1)
    v2, _ = autoNormalizeEngineerInput(v2)
    r1, _ = autoNormalizeEngineerInput(r1)
    r2, _ = autoNormalizeEngineerInput(r2)
    rfb1, _ = autoNormalizeEngineerInput(rfb1)
    rfb2, _ = autoNormalizeEngineerInput(rfb2)
    return (1.0 + rfb2 / rfb1) * (v1 * (r2 / (r1 + r2)) + v2 * (r1 / (r1 + r2)))