示例#1
0
def sineBridgeResponse(vmax=3.0, freq=100.0):
    base = 3.1 - vmax
    slab.waveSine(base, base + vmax, 100)
    slab.setWaveFrequency(freq)
    slab.waveSine(base + vmax, base, 100, second=True)
    slab.tranStore(500, 4)
    t, a1, a2, a3, a4 = slab.waveResponse(dual=True)
    vi = a1 - a2
    vo = a3 - a4
    slab.plot1n(t, [vi, vo], "Sine Bridge Response", "time (s)", "Vi,Vo (V)",
                ["Vi", "Vo"])
示例#2
0
def distortion(v1, v2, freq, show=True):
    points = int(slab.maxSFfresponse / freq)
    if points > 100:
        points = 100
    if points < 50:
        raise slab.SlabEx("Frequency too high")

    cycles = 10
    slab.waveCosine(v1, v2, points)
    slab.setWaveFrequency(freq)
    slab.tranStore(cycles * points)
    t, s = slab.singleWaveResponse()
    if show:
        slab.plot11(t, s, "Time plot", "time(s)", "ADC1(V)")
    c, f = ftransform(s, t)
    if show:
        ac.plotFreq(f, c)

    # THD
    base = np.abs(c[cycles])
    tot = 0
    for i in range(2, 7):
        tot = tot + np.abs(c[i * cycles]) * np.abs(c[i * cycles])
    tot = np.sqrt(tot)
    print("tot: " + str(tot))
    thd = 100.0 * tot / base

    # THD+N
    rms_total = std(s)
    rms_signal = base / np.sqrt(2.0)
    rms_no_signal = np.sqrt(rms_total * rms_total - rms_signal * rms_signal)
    thdn = 100.0 * rms_no_signal / rms_signal

    # Harmonic Distortion 2nd
    h2 = dB(np.abs(c[2 * cycles]) / base)

    # Harmonic Distortion 3rd
    h3 = dB(np.abs(c[3 * cycles]) / base)

    if show:
        print()
        print("THD   : " + str(thd) + " %")
        print("THD+N : " + str(thdn) + " %")
        print("Harmonic distortion 2nd : " + str(h2) + " dBc")
        print("Harmonic distortion 3rd : " + str(h3) + " dBc")
        print()

    return thd, thdn, h2, h3
示例#3
0
文件: slabTest.py 项目: R6500/SLab
if not isVectorConstant(w,1.0):
    raise slab.SlabEx("dcSweep fails at DAC1 or ADC3")
w=v[4]/v[0]
if not isVectorConstant(w,1.0):
    raise slab.SlabEx("dcSweep fails at DAC1 or ADC4")
if not isVectorConstant(v[2],1.0):
    raise slab.SlabEx("dcSweep fails at DAC2 or ADC2")
print('pass')    
print()

#Transient async test
print('Transient async check')
slab.setVoltage(1,1.0)
slab.setVoltage(2,2.0)
slab.setSampleTime(0.001)
slab.tranStore(100,4)
v=slab.transientAsync()
if not isVectorConstant(v[1],1.0):
    raise slab.SlabEx("transientAsync fails at ADC1")
if not isVectorConstant(v[2],2.0):
    raise slab.SlabEx("transientAsync fails at ADC2")
if not isVectorConstant(v[3],1.0):
    raise slab.SlabEx("transientAsync fails at ADC3")   
if not isVectorConstant(v[4],1.0):
    raise slab.SlabEx("transientAsync fails at ADC4")
print('  transientAsync pass')
print()

#Step response test
print('Step response check')
v=slab.stepResponse(1.0,2.0)
示例#4
0
def squareResponse(v1=1, v2=2, freq=100):
    slab.waveSquare(v1, v2, 100)
    slab.setWaveFrequency(freq)
    slab.tranStore(500, 4)
    slab.wavePlot()
示例#5
0
def triangleResponse(vmin=1, vmax=2, freq=100):
    slab.waveTriangle(vmin, vmax, 100)
    slab.setWaveFrequency(freq)
    slab.tranStore(500, 4)
    slab.wavePlot()