def calcBackground(self):
        N = 10
        bg, bg2, bg3, bg_final, bg_final2, bg_final3 = ([] for i in range(6))
        # Warm up
        for w_up in range(0, 2 * N):
            vnakit.Record()
            junk = vnakit.GetRecordingResult()
        # Avg background noise
        for bgIndex in range(0, N):
            vnakit.Record()
            results = vnakit.GetRecordingResult()
            oneTrial, oneTrial2, oneTrial3 = ([] for i in range(3))
            for sample_p4, sample_p2, sample_p5, sample_p6 in zip(
                    results[4], results[2], results[5], results[6]):
                oneTrial2.append(sample_p5 / sample_p2)
                oneTrial.append(sample_p4 / sample_p2)
                oneTrial3.append(sample_p6 / sample_p2)
            bg.insert(bgIndex, oneTrial)
            bg2.insert(bgIndex, oneTrial2)
            bg3.insert(bgIndex, oneTrial3)
        for i in range(0, len(bg[0])):
            freq_sum = freq_sum2 = freq_sum3 = 0
            for j in range(0, N):
                freq_sum2 += bg2[j][i]
                freq_sum += bg[j][i]
                freq_sum3 += bg3[j][i]
            bg_final2.append(freq_sum2 / N)
            bg_final.append(freq_sum / N)
            bg_final3.append(freq_sum3 / N)

        return bg_final, bg_final2, bg_final3
    def animateTime(i, bg1, bg2, bg3):
        raw1,raw2,raw3 = []
        # Conducts test
        vnakit.Record()
        results = vnakit.GetRecordingResult()

        # Calc S21
        for sample_p4, sample_p2, sample_p5, sample_p6, bg_sample1, bg_sample2, bg_sample3\
                in zip(results[4], results[2], results[5], results[6], bg1, bg2, bg3):
            sample = sample_p4 / sample_p2
            sample2 = sample_p5 / sample_p2
            sample3 = sample_p6 / sample_p2
            raw2.append(sample2)# - bg_sample2)
            raw1.append(sample)# - bg_sample1)
            raw3.append(sample3)# - bg_sample3)

        # Retrieve time domain stuff
        freqs = freqs2 = freqs3 = vnakit.GetFreqVector_MHz() 
        #does this syntax work? What do these do?
        times2, waveform2 = calcTimeDomainModel(freqs2, raw2)
        times, waveform1 = calcTimeDomainModel(freqs, raw1)
        times3, waveform3 = calcTimeDomainModel(freqs3, raw3)

        # Calculate range and angle measurement based on returns for both horns.
        #Get return time for each horn
        range_time1 = times[numpy.argmax(waveform1)]
        range_time2 = times2[numpy.argmax(waveform2)]
        range_time3 = times3[numpy.argmax(waveform3)]
        print('======================================================')
        print(getPosition(waveform1, waveform2, waveform3, range_time1, range_time2, range_time3))
        print('======================================================')
def animateTime(i, bg1, bg2, bg3):
    raw1 = []
    raw2 = []
    raw3 = []
    # Conducts test
    vnakit.Record()
    results = vnakit.GetRecordingResult()

    # Calc S21
    for sample_p4, sample_p2, sample_p5, sample_p6, bg_sample1, bg_sample2, bg_sample3\
            in zip(results[4], results[2], results[5], results[6], bg1, bg2, bg3):
        sample = sample_p4 / sample_p2
        sample2 = sample_p5 / sample_p2
        sample3 = sample_p6 / sample_p2
        raw2.append(sample2)  # - bg_sample2)
        raw1.append(sample)  # - bg_sample1)
        raw3.append(sample3)  # - bg_sample3)

    # Retrieve time domain stuff
    freqs = vnakit.GetFreqVector_MHz()
    freqs2 = vnakit.GetFreqVector_MHz()
    freqs3 = vnakit.GetFreqVector_MHz()
    times2, waveform2 = calcTimeDomainModel(freqs2, raw2)
    times, waveform1 = calcTimeDomainModel(freqs, raw1)
    times3, waveform3 = calcTimeDomainModel(freqs3, raw3)

    # Calculate range and angle measurement based on returns for both horns.
    #Get return time for each horn
    range_time1 = times[numpy.argmax(waveform1)]
    range_time2 = times2[numpy.argmax(waveform2)]
    range_time3 = times3[numpy.argmax(waveform3)]
    range_adjust = 0
    # for circulator and black cable
    range_est = (3 * math.pow(10, 8) * range_time1) / 2 * 3.281
    range_est_adj = range_est / 2 - 14
    # TODO: need adj for current cables
    # Print results
    print('======================================================')
    print(
        getPosition(waveform1, waveform2, waveform3, range_time1, range_time2,
                    range_time3))
    print('======================================================')
    def animateTime(self, bg1, bg2, bg3):
        raw1, raw2, raw3 = ([] for i in range(3))
        # Conducts test
        vnakit.Record()
        results = vnakit.GetRecordingResult()
        #print('location3')
        # Calc S21
        for sample_p4, sample_p2, sample_p5, sample_p6, bg_sample1, bg_sample2, bg_sample3 \
                in zip(results[4], results[2], results[5], results[6], bg1, bg2, bg3):
            sample = sample_p4 / sample_p2
            sample2 = sample_p5 / sample_p2
            sample3 = sample_p6 / sample_p2
            raw2.append(sample2 - bg_sample2)
            raw1.append(sample - bg_sample1)
            raw3.append(sample3 - bg_sample3)

        # Retrieve time domain stuff
        freqs = vnakit.GetFreqVector_MHz()
        freqs3 = vnakit.GetFreqVector_MHz()
        freqs2 = vnakit.GetFreqVector_MHz()
        # does this syntax work? What do these do? Yes
        # left horn
        times, waveform1 = vnaStuff.calcTimeDomainModel(freqs, raw1)
        # right horn
        times2, waveform2 = vnaStuff.calcTimeDomainModel(freqs2, raw2)
        # Ice cream cone
        times3, waveform3 = vnaStuff.calcTimeDomainModel(freqs3, raw3)

        # Calculate range and angle measurement based on returns for both horns.
        # Get return time for each horn
        range_time1 = times[numpy.argmax(waveform1)]
        range_time2 = times2[numpy.argmax(waveform2)]
        range_time3 = times3[numpy.argmax(waveform3)]
        print('======================================================')
        print(
            self.getPosition(waveform1, waveform2, waveform3, range_time1,
                             range_time2, range_time3))
        print('======================================================')
        self.plotTimeDomain(times, waveform1, waveform2, waveform3)