def receive_power0():
    rec=NN
    #start0 = time.time()

    while rec:
        rec=rec-1
        fre0 = 0
        raw_data0 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples0 = sdr0.read_samples(Nu * 1024)  # 256
            p_density0, fre0 = selfpsd(samples0, NFFT=1024, Fs=sdr0.sample_rate, Fc=sdr0.center_freq)  # get psd using own function
            raw_data0[ii, :] = p_density0


        re_pow0, new_psd0, f_new0 = received_power2(raw_data0, fre0, 1, M)
        myglobals.power_threads[0].append(re_pow0)
        myglobals.psd_threads[0].append(new_psd0)
        myglobals.fre_threads[0].append(f_new0)
        # myglobals.power_threads[0]=re_pow0
        # myglobals.psd_threads[0]=new_psd0
        # myglobals.fre_threads[0]=f_new0
        #print('nothing0')
    # sensingtime0 = (time.time() - start)
    # print('average time0', sensingtime0 / NN)
    return
def receive_power2():
    rec = NN
    #start2 = time.time()

    while rec:
        rec = rec - 1
        fre2 = 0
        raw_data2 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples2 = sdr2.read_samples(Nu * 1024)  # 256
            p_density2, fre2 = selfpsd(samples2, NFFT=1024, Fs=sdr2.sample_rate, Fc=sdr2.center_freq)  # get psd using own function
            raw_data2[ii, :] = p_density2


        re_pow2, new_psd2, f_new2 = received_power2(raw_data2, fre2, 1, M)
        myglobals.power_threads[2].append(re_pow2)
        myglobals.psd_threads[2].append(new_psd2)
        myglobals.fre_threads[2].append(f_new2)
        # myglobals.power_threads[2]=re_pow2
        # myglobals.psd_threads[2]=new_psd2
        # myglobals.fre_threads[2]=f_new2
        #print('nothing2')
    # sensingtime2 = (time.time() - start)
    # print('average time2', sensingtime2 / NN)
    return
def receive_power1():
    rec=NN
    #start1 = time.time()

    while rec:
        rec=rec-1
        fre1 = 0
        raw_data1 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples1 = sdr1.read_samples(Nu * 1024)  # 256
            p_density1, fre1 = selfpsd(samples1, NFFT=1024, Fs=sdr1.sample_rate, Fc=sdr1.center_freq)  # get psd using own function
            raw_data1[ii, :] = p_density1


        re_pow1, new_psd1, f_new1 = received_power2(raw_data1, fre1, 1, M)
        myglobals.power_threads[1].append(re_pow1)
        myglobals.psd_threads[1].append(new_psd1)
        myglobals.fre_threads[1].append(f_new1)
        # myglobals.power_threads[1]=re_pow1
        # myglobals.psd_threads[1]=new_psd1
        # myglobals.fre_threads[1]=f_new1
        #print('nothing1')
    # sensingtime1 = (time.time() - start)
    # print('average time1', sensingtime1 / NN)
    return
def receive_power4():
    rec = NN
    #start4 = time.time()

    while rec:
        rec = rec - 1
        fre4 = 0
        raw_data4 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples4 = sdr4.read_samples(Nu * 1024)  # 256
            p_density4, fre4 = selfpsd(samples4, NFFT=1024, Fs=sdr4.sample_rate, Fc=sdr4.center_freq)  # get psd using own function
            raw_data4[ii, :] = p_density4


        re_pow4, new_psd4, f_new4 = received_power2(raw_data4, fre4, 1, M)
        myglobals.power_threads[4].append(re_pow4)
        myglobals.psd_threads[4].append(new_psd4)
        myglobals.fre_threads[4].append(f_new4)
        # myglobals.power_threads[4]=re_pow4
        # myglobals.psd_threads[4]=new_psd4
        # myglobals.fre_threads[4]=f_new4
        #print('nothing4')
    # sensingtime4 = (time.time() - start)
    # print('average time4', sensingtime4 / NN)
    return
def receive_power3():
    rec = NN
    #start3 = time.time()

    while rec:
        rec = rec - 1
        fre3 = 0
        raw_data3 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples3 = sdr3.read_samples(Nu * 1024)  # 256
            p_density3, fre3 = selfpsd(samples3, NFFT=1024, Fs=sdr3.sample_rate, Fc=sdr3.center_freq)  # get psd using own function
            raw_data3[ii, :] = p_density3


        re_pow3, new_psd3, f_new3 = received_power2(raw_data3, fre3, 1, M)
        myglobals.power_threads[3].append(re_pow3)
        #print(myglobals.power_threads[3])
        myglobals.psd_threads[3].append(new_psd3)
        myglobals.fre_threads[3].append(f_new3)
        # myglobals.power_threads[3]=re_pow3
        # myglobals.psd_threads[3]=new_psd3
        # myglobals.fre_threads[3]=f_new3
        #print('nothing3')
    # sensingtime3 = (time.time() - start)
    # print('average time3', sensingtime3 / NN)
    return
Exemple #6
0
def receive_power2():
    rec = 100
    while rec:
        rec = rec - 1
        raw_data = np.zeros((N, 1024))
        for ii in range(0, N):
            samples = sdr1.read_samples(56 * 1024)  # 256
            # use matplotlib to estimate and plot the PSD
            p_density, fre = selfpsd(samples,
                                     NFFT=1024,
                                     Fs=sdr1.sample_rate,
                                     Fc=sdr1.center_freq,
                                     detrend=None,
                                     window=None,
                                     noverlap=None,
                                     pad_to=None,
                                     sides=None,
                                     scale_by_freq=None)
            #p_density, fre = plt.psd(samples, NFFT=1024, Fs=sdr1.sample_rate, Fc=sdr1.center_freq)

            raw_data[ii, :] = p_density

        figurhandler = 12
        re_pow, new_psd = received_power2(raw_data, fre, figurhandler, M)
        myglobals.power2.append(re_pow)
        #print('pow2',re_pow)
    return
Exemple #7
0
def receive_power6():

    fre6 = 0
    raw_data6 = np.zeros((N, 1024))
    for ii in range(0, N):
        samples6 = sdr6.read_samples(56 * 1024)  # 256
        p_density6, fre6 = selfpsd(samples6, NFFT=1024, Fs=sdr6.sample_rate, Fc=sdr6.center_freq)  # get psd using own function
        raw_data6[ii, :] = p_density6


    re_pow6, new_psd6, f_new6 = received_power2(raw_data6, fre6, 1, M)
    myglobals.power_threads[6].append(re_pow6)
    myglobals.psd_threads[6].append(new_psd6)
    myglobals.fre_threads[6].append(f_new6)
Exemple #8
0
def receive_power5():

    fre5 = 0
    raw_data5 = np.zeros((N, 1024))
    for ii in range(0, N):
        samples5 = sdr5.read_samples(56 * 1024)  # 256
        p_density5, fre5 = selfpsd(samples5, NFFT=1024, Fs=sdr5.sample_rate, Fc=sdr5.center_freq)  # get psd using own function
        raw_data5[ii, :] = p_density5


    re_pow5, new_psd5, f_new5 = received_power2(raw_data5, fre5, 1, M)
    myglobals.power_threads[5].append(re_pow5)
    myglobals.psd_threads[5].append(new_psd5)
    myglobals.fre_threads[5].append(f_new5)
Exemple #9
0
def receive_power0(sdr, id):
    sdr0 = sdr
    fre0 = 0
    raw_data0 = np.zeros((N, 1024))
    for ii in range(0, N):
        samples0 = sdr0.read_samples(56 * 1024)  # 256
        p_density0, fre0 = selfpsd(samples0, NFFT=1024, Fs=sdr0.sample_rate,
                                   Fc=sdr0.center_freq)  # get psd using own function
        raw_data0[ii, :] = p_density0

    re_pow0, new_psd0, f_new0 = received_power2(raw_data0, fre0, 1, M)
    myglobals.power_threads[id].append(re_pow0)
    myglobals.psd_threads[id].append(new_psd0)
    myglobals.fre_threads[id].append(f_new0)
Exemple #10
0
    def receive_power1():

        fre1 = 0
        raw_data1 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples1 = sdr1.read_samples(56 * 1024)  # 256
            p_density1, fre1 = selfpsd(
                samples1, NFFT=1024, Fs=sdr1.sample_rate,
                Fc=sdr1.center_freq)  # get psd using own function
            raw_data1[ii, :] = p_density1

        re_pow1, new_psd1, f_new1 = received_power2(raw_data1, fre1, 1, M)
        myglobals.power_threads[1].append(re_pow1)
        myglobals.psd_threads[1].append(new_psd1)
        myglobals.fre_threads[1].append(f_new1)
Exemple #11
0
    def receive_power3():

        fre3 = 0
        raw_data3 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples3 = sdr3.read_samples(56 * 1024)  # 256
            p_density3, fre3 = selfpsd(
                samples3, NFFT=1024, Fs=sdr3.sample_rate,
                Fc=sdr3.center_freq)  # get psd using own function
            raw_data3[ii, :] = p_density3

        re_pow3, new_psd3, f_new3 = received_power2(raw_data3, fre3, 1, M)
        myglobals.power_threads[3].append(re_pow3)
        myglobals.psd_threads[3].append(new_psd3)
        myglobals.fre_threads[3].append(f_new3)
Exemple #12
0
    def receive_power4():

        fre4 = 0
        raw_data4 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples4 = sdr4.read_samples(56 * 1024)  # 256
            p_density4, fre4 = selfpsd(
                samples4, NFFT=1024, Fs=sdr4.sample_rate,
                Fc=sdr4.center_freq)  # get psd using own function
            raw_data4[ii, :] = p_density4

        re_pow4, new_psd4, f_new4 = received_power2(raw_data4, fre4, 1, M)
        myglobals.power_threads[4].append(re_pow4)
        myglobals.psd_threads[4].append(new_psd4)
        myglobals.fre_threads[4].append(f_new4)
Exemple #13
0
    def receive_power2():

        fre2 = 0
        raw_data2 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples2 = sdr2.read_samples(56 * 1024)  # 256
            p_density2, fre2 = selfpsd(
                samples2, NFFT=1024, Fs=sdr2.sample_rate,
                Fc=sdr2.center_freq)  # get psd using own function
            raw_data2[ii, :] = p_density2

        re_pow2, new_psd2, f_new2 = received_power2(raw_data2, fre2, 1, M)
        myglobals.power_threads[2].append(re_pow2)
        myglobals.psd_threads[2].append(new_psd2)
        myglobals.fre_threads[2].append(f_new2)
def receive_power1():
    rec=NN # time of samples
    while rec:
        rec=rec-1
        raw_data = np.zeros((N, 1024))
        for ii in range(0, N):
            samples = sdr0.read_samples(56 * 1024)  # 256
            # use matplotlib to estimate and plot the PSD
            p_density, fre = selfpsd(samples, NFFT=1024, Fs=sdr0.sample_rate, Fc=sdr0.center_freq)
            #p_density, fre = plt.psd(samples, NFFT=1024, Fs=sdr0.sample_rate, Fc=sdr0.center_freq)

            raw_data[ii, :] = p_density

        figurhandler = 12
        re_pow, new_psd = received_power2(raw_data, fre, figurhandler,M)
        myglobals.power1.append(re_pow)
        #print('pow1', re_pow)
    return
def receive_power16():
    rec = NN
    # start4 = time.time()

    while rec:
        rec = rec - 1
        fre16 = 0
        raw_data16 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples16 = sdr16.read_samples(56 * 1024)  # 256
            p_density16, fre16 = selfpsd(samples16, NFFT=1024, Fs=sdr16.sample_rate, Fc=sdr16.center_freq)  # get psd using own function
            raw_data16[ii, :] = p_density16


        re_pow16, new_psd16, f_new16 = received_power2(raw_data16, fre16, 1, M)
        myglobals.power_threads[16].append(re_pow16)
        myglobals.psd_threads[16].append(new_psd16)
        myglobals.fre_threads[16].append(f_new16)
def receive_power9():
    rec = NN
    # start4 = time.time()

    while rec:
        rec = rec - 1
        fre9 = 0
        raw_data9 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples9 = sdr9.read_samples(Nu * 1024)  # 256
            p_density9, fre9 = selfpsd(samples9, NFFT=1024, Fs=sdr9.sample_rate, Fc=sdr9.center_freq)  # get psd using own function
            raw_data9[ii, :] = p_density9


        re_pow9, new_psd9, f_new9 = received_power2(raw_data9, fre9, 1, M)
        myglobals.power_threads[9].append(re_pow9)
        myglobals.psd_threads[9].append(new_psd9)
        myglobals.fre_threads[9].append(f_new9)
def receive_power12():
    rec = NN
    # start4 = time.time()

    while rec:
        rec = rec - 1
        fre12 = 0
        raw_data12 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples12 = sdr12.read_samples(Nu * 1024)  # 256
            p_density12, fre12 = selfpsd(samples12, NFFT=1024, Fs=sdr12.sample_rate, Fc=sdr12.center_freq)  # get psd using own function
            raw_data12[ii, :] = p_density12


        re_pow12, new_psd12, f_new12 = received_power2(raw_data12, fre12, 1, M)
        myglobals.power_threads[12].append(re_pow12)
        myglobals.psd_threads[12].append(new_psd12)
        myglobals.fre_threads[12].append(f_new12)
def receive_power7():
    rec = NN
    # start4 = time.time()

    while rec:
        rec = rec - 1
        fre7 = 0
        raw_data7 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples7 = sdr7.read_samples(Nu * 1024)  # 256
            p_density7, fre7 = selfpsd(samples7, NFFT=1024, Fs=sdr7.sample_rate, Fc=sdr7.center_freq)  # get psd using own function
            raw_data7[ii, :] = p_density7


        re_pow7, new_psd7, f_new7 = received_power2(raw_data7, fre7, 1, M)
        myglobals.power_threads[7].append(re_pow7)
        myglobals.psd_threads[7].append(new_psd7)
        myglobals.fre_threads[7].append(f_new7)
def receive_power8():
    rec = NN
    # start4 = time.time()

    while rec:
        rec = rec - 1
        fre8 = 0
        raw_data8 = np.zeros((N, 1024))
        for ii in range(0, N):
            samples8 = sdr8.read_samples(Nu * 1024)  # 256
            p_density8, fre8 = selfpsd(samples8, NFFT=1024, Fs=sdr8.sample_rate, Fc=sdr8.center_freq)  # get psd using own function
            raw_data8[ii, :] = p_density8


        re_pow8, new_psd8, f_new8 = received_power2(raw_data8, fre8, 1, M)
        myglobals.power_threads[8].append(re_pow8)
        myglobals.psd_threads[8].append(new_psd8)
        myglobals.fre_threads[8].append(f_new8)
def receive_power(sdr, id):
    rec = NN
    # start4 = time.time()

    while rec:
        rec = rec - 1
        fre = 0
        raw_data = np.zeros((N, 1024))
        for ii in range(0, N):
            samples = sdr.read_samples(56 * 1024)  # 256
            p_density, fre = selfpsd(
                samples, NFFT=1024, Fs=sdr.sample_rate,
                Fc=sdr.center_freq)  # get psd using own function
            raw_data[ii, :] = p_density

        re_pow, new_psd, f_new = received_power2(raw_data, fre, 1, M)
        myglobals.power_threads[id].append(re_pow)
        myglobals.psd_threads[id].append(new_psd)
        myglobals.fre_threads[id].append(f_new)
    def receive_power10():

        while 1:
            fre10 = 0
            raw_data10 = np.zeros((N, 1024))
            for ii in range(0, N):
                samples10 = sdr10.read_samples(Nu * 1024)  # 256
                p_density10, fre10 = selfpsd(
                    samples10,
                    NFFT=1024,
                    Fs=sdr10.sample_rate,
                    Fc=sdr10.center_freq)  # get psd using own function
                raw_data10[ii, :] = p_density10

            re_pow10, new_psd10, f_new10 = received_power2(
                raw_data10, fre10, 1, M)
            myglobals.power_threads[10].append(re_pow10)
            myglobals.psd_threads[10].append(new_psd10)
            myglobals.fre_threads[10].append(f_new10)
    def receive_power13():

        while 1:
            fre13 = 0
            raw_data13 = np.zeros((N, 1024))
            for ii in range(0, N):
                samples13 = sdr13.read_samples(56 * 1024)  # 256
                p_density13, fre13 = selfpsd(
                    samples13,
                    NFFT=1024,
                    Fs=sdr13.sample_rate,
                    Fc=sdr13.center_freq)  # get psd using own function
                raw_data13[ii, :] = p_density13

            re_pow13, new_psd13, f_new13 = received_power2(
                raw_data13, fre13, 1, M)
            myglobals.power_threads[13].append(re_pow13)
            myglobals.psd_threads[13].append(new_psd13)
            myglobals.fre_threads[13].append(f_new13)
    def receive_power14():

        while 1:
            fre14 = 0
            raw_data14 = np.zeros((N, 1024))
            for ii in range(0, N):
                samples14 = sdr14.read_samples(56 * 1024)  # 256
                p_density14, fre14 = selfpsd(
                    samples14,
                    NFFT=1024,
                    Fs=sdr14.sample_rate,
                    Fc=sdr14.center_freq)  # get psd using own function
                raw_data14[ii, :] = p_density14

            re_pow14, new_psd14, f_new14 = received_power2(
                raw_data14, fre14, 1, M)
            myglobals.power_threads[14].append(re_pow14)
            myglobals.psd_threads[14].append(new_psd14)
            myglobals.fre_threads[14].append(f_new14)
    def receive_power15():

        while 1:
            fre15 = 0
            raw_data15 = np.zeros((N, 1024))
            for ii in range(0, N):
                samples15 = sdr15.read_samples(56 * 1024)  # 256
                p_density15, fre15 = selfpsd(
                    samples15,
                    NFFT=1024,
                    Fs=sdr15.sample_rate,
                    Fc=sdr15.center_freq)  # get psd using own function
                raw_data15[ii, :] = p_density15

            re_pow15, new_psd15, f_new15 = received_power2(
                raw_data15, fre15, 1, M)
            myglobals.power_threads[15].append(re_pow15)
            myglobals.psd_threads[15].append(new_psd15)
            myglobals.fre_threads[15].append(f_new15)
        #start = time.time()
        samples1 = sdr1.read_samples(56 * 1024)  #256
        #sensingtime1 = (time.time() - start)
        #print('time for read_sample:',sensingtime1)

        # use matplotlib to estimate and plot the PSD
        plt.figure(1)
        #start = time.time()
        plt.cla()
        #p_density, fre = plt.psd(samples1, NFFT=1024, Fs=sdr1.sample_rate, Fc=sdr1.center_freq) # get psd using github package

        #print(np.max(20*np.log(p_density)))

        p_density, fre = selfpsd(
            samples1, NFFT=1024, Fs=sdr1.sample_rate,
            Fc=sdr1.center_freq)  # get psd using own function
        re_pow1, new_psd1, f_new1 = received_power2(p_density, fre, 1, 128)
        # # sensingtime2 = (time.time() - start)
        # # print('time for get psd:',sensingtime2)
        # p_density=10 * np.log10(p_density)
        # plt.plot(fre,p_density)
        # plt.xlabel('Frequency (MHz)')
        # plt.ylabel('Relative power (dB)')
        # plt.title('using own psd_code')
        #plt.pause(0.001)

        #raw_data[ii,:]=p_density
        samples2 = sdr2.read_samples(56 * 1024)
        plt.figure(2)
        plt.cla()
Exemple #26
0
def psdfigure(*args):

    while 1:
        fig1.clf()
        axis1 = fig1.add_subplot(131)
        #axis1.set_title('power spectral density')
        axis1.set_xlabel('frequency[MHz]')
        axis1.set_ylabel('Relative power (dB)')
        # axis1.set_xlim(0, 10)
        axis1.set_ylim(-120, -50)
        axis2 = fig1.add_subplot(133)
        #axis1.set_title('power spectral density')
        axis2.set_xlabel('frequency[MHz]')
        axis2.set_ylabel('Relative power (dB)')
        axis2.set_ylim(-120, -50)

        if senID.get() != '0' and senID1.get() == '0':
            if senID.get() == '1':
                # -------------------------------------------------
                samples1 = sdr1.read_samples(56 * 1024)  # 256

                p_density1, fre1 = selfpsd(samples1,
                                           NFFT=1024,
                                           Fs=sdr1.sample_rate,
                                           Fc=sdr1.center_freq)
                p_density1 = 10 * np.log10(p_density1)
                axis1.plot(fre1, p_density1)

                print('sensor 1')
            elif senID.get() == '2':
                samples2 = sdr2.read_samples(56 * 1024)  # 256
                axis1 = fig1.add_subplot(131)
                p_density2, fre2 = selfpsd(samples2,
                                           NFFT=1024,
                                           Fs=sdr2.sample_rate,
                                           Fc=sdr2.center_freq)
                p_density2 = 10 * np.log10(p_density2)
                axis1.plot(fre2, p_density2)

                print('sensor 2')

        elif senID.get() == '0' and senID1.get() != '0':
            if senID1.get() == '1':
                # -------------------------------------------------
                samples1 = sdr1.read_samples(56 * 1024)  # 256

                p_density1, fre1 = selfpsd(samples1,
                                           NFFT=1024,
                                           Fs=sdr1.sample_rate,
                                           Fc=sdr1.center_freq)
                p_density1 = 10 * np.log10(p_density1)
                axis2.plot(fre1, p_density1)
                axis2.set_title('power spectral density')
                axis2.set_xlabel('frequency[MHz]')
                axis2.set_ylabel('Relative power (dB)')
                # axis1.set_xlim(0, 10)
                axis2.set_ylim(-120, -50)
                print('sensor 1')
            elif senID1.get() == '2':
                samples2 = sdr2.read_samples(56 * 1024)  # 256

                p_density2, fre2 = selfpsd(samples2,
                                           NFFT=1024,
                                           Fs=sdr2.sample_rate,
                                           Fc=sdr2.center_freq)
                p_density2 = 10 * np.log10(p_density2)
                axis2.plot(fre2, p_density2)
                axis2.set_title('power spectral density')
                axis2.set_xlabel('frequency[MHz]')
                axis2.set_ylabel('Relative power (dB)')
                axis2.set_ylim(-120, -50)
                print('sensor 2')

        elif senID.get() != '0' and senID1.get() != '0':
            if senID.get() == '1' and senID1.get() == '2':
                samples1 = sdr1.read_samples(56 * 1024)  # 256

                p_density1, fre1 = selfpsd(samples1,
                                           NFFT=1024,
                                           Fs=sdr1.sample_rate,
                                           Fc=sdr1.center_freq)
                p_density1 = 10 * np.log10(p_density1)
                axis1.plot(fre1, p_density1)
                axis1.set_title('power spectral density')
                axis1.set_xlabel('frequency[MHz]')
                axis1.set_ylabel('Relative power (dB)')
                # axis1.set_xlim(0, 10)
                axis1.set_ylim(-120, -50)
                print('sensor 1')
                samples2 = sdr2.read_samples(56 * 1024)  # 256

                p_density2, fre2 = selfpsd(samples2,
                                           NFFT=1024,
                                           Fs=sdr2.sample_rate,
                                           Fc=sdr2.center_freq)
                p_density2 = 10 * np.log10(p_density2)
                axis2.plot(fre2, p_density2)
                axis2.set_title('power spectral density')
                axis2.set_xlabel('frequency[MHz]')
                axis2.set_ylabel('Relative power (dB)')
                axis2.set_ylim(-120, -50)
                print('sensor 2')
            elif senID.get() == '2' and senID1.get() == '1':
                samples2 = sdr2.read_samples(56 * 1024)  # 256
                axis1 = fig1.add_subplot(131)
                p_density2, fre2 = selfpsd(samples2,
                                           NFFT=1024,
                                           Fs=sdr2.sample_rate,
                                           Fc=sdr2.center_freq)
                p_density2 = 10 * np.log10(p_density2)
                axis1.plot(fre2, p_density2)
                axis1.set_title('power spectral density')
                axis1.set_xlabel('frequency[MHz]')
                axis1.set_ylabel('Relative power (dB)')
                axis1.set_ylim(-120, -50)
                print('sensor 2')
                samples1 = sdr1.read_samples(56 * 1024)  # 256

                p_density1, fre1 = selfpsd(samples1,
                                           NFFT=1024,
                                           Fs=sdr1.sample_rate,
                                           Fc=sdr1.center_freq)
                p_density1 = 10 * np.log10(p_density1)
                axis2.plot(fre1, p_density1)
                axis2.set_title('power spectral density')
                axis2.set_xlabel('frequency[MHz]')
                axis2.set_ylabel('Relative power (dB)')
                # axis1.set_xlim(0, 10)
                axis2.set_ylim(-120, -50)
                print('sensor 1')

        psdFig.draw()
        plt.pause(0.2)
Exemple #27
0
#
#--------------------------- use github
sensingtime = 0
for gg in range(0, NN):
    start = time.time()
    N = 1
    raw_data = np.zeros((N, 1024))

    for ii in range(0, N):

        samples = sdr.read_samples(56 * 1024)  # 256

        # use matplotlib to estimate and plot the PSD
        #plt.figure(1)
        p_density, fre = selfpsd(samples,
                                 NFFT=1024,
                                 Fs=sdr.sample_rate,
                                 Fc=sdr.center_freq)

        raw_data[ii, :] = p_density
    #plt.close(1)
    figurhandler = 12
    M = 128
    re_pow, new_psd = received_power2(raw_data, fre, figurhandler, M)
    sensingtime = (time.time() - start)
    Tim = Tim + sensingtime

Tim = Tim / NN
print(Tim)

# NN=100 # locations of source
# Nmx=np.array([3,4,5,6])