Inconsistency between the first data and the following data

Need help installing or figuring out something about your SDR? Ask here.
Post Reply
xbm
Posts: 1
Joined: Mon Nov 12, 2018 4:07 pm

Inconsistency between the first data and the following data

Post by xbm » Mon Nov 12, 2018 4:16 pm

Hi, I am a beginner about this RTLSDR. I am facing some problems, and hoping anybody can help or discuss.

The RTLSDR is connected to a signal generator and I am using pyrtlsdr to capture the data on a Raspberry PI. The problem is that the first capture is always larger than the following ones. The figure below contains four captures, the blue and green curves are the I/Q, and the red one is the magnitude. Every time I will set (1) gain = 1 (2) sample_rate = 2000000 (3) center_freq = 130e6 and (4) reset the buffer. What is wrong with it? THX in advance.

Code: Select all

from rtlsdr import RtlSdr
from contextlib import closing
import math
import time
import matplotlib.pyplot as plt
import numpy as np
from rtlsdr import librtlsdr



samples = 16*1024



def gain(sdr):
    print(sdr.get_gain())

def power(sdr):
    iq = sdr.read_samples(samples)
    #iq = iq[2001:-1]
    ivalue = np.real(iq)
    qvalue = np.imag(iq)
    plt.plot(ivalue)
    plt.plot(qvalue)
    plt.plot(np.abs(iq))
    plt.show()
    return iq, 10*math.log(pow(sum(abs(iq))/((samples)*pow(2,0.5)),2)/50,10)



with closing(RtlSdr()) as sdr:



    time.sleep(3)
    c_freq = 130e6
    gain = 0.9
    
    #sdr.center_freq = c_freq*4
#####################################
    sdr.gain = gain
    sdr.sample_rate = sample_rate = 2000000
    sdr.center_freq = c_freq
    librtlsdr.rtlsdr_reset_buffer(sdr.dev_p)
    iq1, p1 = power(sdr)
    print('p1 = ', p1)

######################################

    #sdr.close()
    #sdr.open()
    sdr.gain = gain
    sdr.sample_rate = sample_rate = 2000000
    sdr.center_freq = c_freq
    librtlsdr.rtlsdr_reset_buffer(sdr.dev_p);
    iq2, p2 = power(sdr)
    print('p2 = ', p2)

######################################

    sdr.gain = gain
    sdr.sample_rate = sample_rate = 2000000
    sdr.center_freq = c_freq
    librtlsdr.rtlsdr_reset_buffer(sdr.dev_p)
    iq3, p3 = power(sdr)
    print('p3 = ', p3)

######################################

    sdr.gain = gain
    sdr.sample_rate = sample_rate = 2000000
    sdr.center_freq = c_freq
    librtlsdr.rtlsdr_reset_buffer(sdr.dev_p)
    iq4, p4 = power(sdr)
    print('p4 = ', p4)


    iq = np.append(iq1,iq2)
    iq = np.append(iq,iq3)
    iq = np.append(iq,iq4)    
    ivalue = np.real(iq)
    qvalue = np.imag(iq)
    plt.plot(ivalue)
    plt.plot(qvalue)
    plt.plot(np.abs(iq))
    plt.show()

    #print(sdr.get_gains())
Attachments
orggsc.png
Four captures
orggsc.png (32.8 KiB) Viewed 1629 times

Post Reply