Exemplo n.º 1
0
def rect_qpsk_map(t, data, s_rate, **args):
    """
    Generates a baseband signal to modulate with QPSK and rectangular pulses

    :param t: time axis
    :param data: binary sequence which is going to be mapped
    :param s_rate: symbol rate of the transmitted baseband signal
    :param args: optional arguments, see the table.

    +----------+-------------+-----------+---------------------------------------------------+
    | Key word | Possible    | Default   | Description                                       |
    |          | values      |           |                                                   |
    +==========+=============+===========+===================================================+
    | tp       | positive    |           |  pulse width of a single symbol                   |
    |          | float       | 1/b_rate  |                                                   |
    +----------+-------------+-----------+---------------------------------------------------+
    | td       | positive    |           |  delay of the signal with reference to the origin |
    |          | float       |   0       |  of the time axis                                 |
    +----------+-------------+-----------+---------------------------------------------------+
    | ts       | positive    |   0       |  the space between pulses in a stream             |
    |          | float       |           |                                                   |
    +----------+-------------+-----------+---------------------------------------------------+

    :return: Baseband signal
    """
    tup = 2  # number of bits in one tuple
    n_d = tup - (np.size(data) % tup)
    data = np.append(data,
                     np.zeros(n_d))  # appends zero to get odd number of bits
    data_2s = data.reshape(-1, tup)  # reshaping the data vector into matrix
    data_2s = data_2s > 0

    ## Baseband signal parameters
    if 'tp' in args:
        tp = args['tp']
    else:
        tp = 1 / s_rate  # pulse width of a single symbol

    if 'td' in args:
        td = args['td']
    else:
        td = 0  # signal starts at time td = 0s

    if 'ts' in args:
        ts = args['ts']
    else:
        ts = 0  # the space between pulses in a stream is ts = 0s

    # Baseband signal generator
    i_bb = 2 * gen.rect_tr(t, tp, ts, td, data_2s[:, 0]) - 1
    q_bb = 2 * gen.rect_tr(t, tp, ts, td, data_2s[:, 1]) - 1
    bb = i_bb + q_bb * 1j

    return (bb)
Exemplo n.º 2
0
def rect_bpsk_map(t, data, b_rate, **args):
    """
    Generates a baseband signal for a BPSK modulation with rectangular pulses

    :param t: time axis
    :param data: binary sequence which is going to be mapped
    :param b_rate: bit rate of the transmitted bit-stream
    :param args: optional arguments, see the table.

    +----------+-------------+-----------+---------------------------------------------------+
    | Key word | Possible    | Default   | Description                                       |
    |          | values      |           |                                                   |
    +==========+=============+===========+===================================================+
    | tp       | positive    |           |  pulse width of a single symbol                   |
    |          | float       | 1/b_rate  |                                                   |
    +----------+-------------+-----------+---------------------------------------------------+
    | td       | positive    |           |  delay of the signal with reference to the origin |
    |          | float       |   0       |  of the time axis                                 |
    +----------+-------------+-----------+---------------------------------------------------+
    | ts       | positive    |   0       |  the space between pulses in a stream             |
    |          | float       |           |                                                   |
    +----------+-------------+-----------+---------------------------------------------------+

    :return: Baseband signal
    """
    if 'tp' in args:
        tp = args['tp']
    else:
        tp = 1 / b_rate  # pulse width of a single symbol

    if 'td' in args:
        td = args['td']
    else:
        td = 0  # signal starts at time td = 0s

    if 'ts' in args:
        ts = args['ts']
    else:
        ts = 0  # the space between pulses in a stream is ts = 0s

    # Baseband signal generator
    i_bb = 2 * gen.rect_tr(t, tp, ts, td, data) - 1
    q_bb = np.zeros(np.size(t))
    bb = i_bb + q_bb * 1j

    return (bb)
Exemplo n.º 3
0
##################### Simulation TAU = 1 ######################
t = np.arange(0,T_int,1/f_sampl)	# time axis
f = ut.freq_fr_time (t)				# frequency axis
tc = ut.corr_fr_time (t)			# correlation time axis
cd = np.array([1,1,1,0,1,1,1,1,0,1,0,0,1,0,1])	# code

tau = 1								# time acceleration factor
Tstr = 10e-3						# transmitted symbol interval
Ts = Tstr/tau						# Nyquist's symbol interval
td = 0.01							# initial delay of the sequence (time offset)

# Time Domain
a1 = gen.rcos_tr(t,Tstr,td + Tstr/2,cd,Ts,1.0)
a2 = gen.rcos_tr(t,Tstr,td + Tstr/2,cd,Ts,0.5)
a3 = gen.rcos_tr(t,Tstr,td + Tstr/2,cd,Ts,0.0)
c  = gen.rect_tr(t,Tstr,0,td,cd)


# Correlate processor
A1_c = signal.correlate(a1,a1,'full')
A2_c = signal.correlate(a2,a2,'full')
A3_c = signal.correlate(a3,a3,'full')
C1_c = signal.correlate( c,a1,'full')
C2_c = signal.correlate( c,a2,'full')
C3_c = signal.correlate( c,a3,'full')

CC_c = signal.correlate( c, c,'full')

# Frequency Spectrum 
A1_fft = np.fft.fft(np.real(a1))
A2_fft = np.fft.fft(np.real(a2))
Exemplo n.º 4
0
def main(setup_data):

    stp.logger_setup(setup_data["setup"])
    logger = logging.getLogger(__name__)
    logger.info("Main function started.")

    logger.debug("Coder analysis configuration file %s", setup_data["cnf"])
    logger.debug("Setup configuration file %s", setup_data["setup"])
    logger.debug("Plotting configuration file %s", setup_data["plt"])
    logger.debug("Logger output file %s", setup_data["log"])
    logger.debug("Python files %s", setup_data["srcpy"])
    logger.debug("SSRG state output file %s", setup_data["data_state"])
    logger.debug("Coder PRN output file %s", setup_data["data_code"])

    ##################### code generator ###############################
    analysis_setup = stp.analysis_cnf_file_parser(setup_data["cnf"])
    logger.debug("%s file read to setup analysis", setup_data["cnf"])
    ssrg_init = analysis_setup["ssrg_init"]
    logger.debug("initial state of the ssrg, ssrg_init =  %s ", ssrg_init)
    ssrg_fb = analysis_setup["ssrg_fb"]
    logger.debug("feedback vector of the ssrg, ssrg_fb =  %s ", ssrg_fb)
    srm = prn.build_srm(ssrg_fb)
    logger.debug("srm matrix created, srm =  %s ", srm)
    logger.debug("Number of bits in one period of the code N = %s bits ",
                 analysis_setup["code_period"])
    logger.debug("Number of periods being generated %s ",
                 analysis_setup["n_o_periods"])
    n_of_bits = analysis_setup["code_period"] * analysis_setup["n_o_periods"]
    logger.debug("code generator setup - number of generated bits %s ",
                 n_of_bits)

    x = ssrg_init.T
    code = np.zeros(1)
    for i1 in range(1, n_of_bits):
        x = prn.proceed_ssrg_onestep(x, srm)
        csvi.write_csv(x, setup_data["data_state"], i1)
        csvi.write_csv(x[-1], setup_data["data_code"], i1)
        code = np.append(code, x[-1])
    logger.debug("coder run - binary sequence generated, number of bits %s ",
                 code.size)

    #################### time related simulation ######################
    f_sampl = analysis_setup["chip_rate"] * analysis_setup[
        "oversampling_factor"]
    logger.debug("sampling rate is %s kHz", f_sampl)
    logger.debug("sampling period is %s ms", 1 / f_sampl)
    logger.debug("chiprate is %s kHz", analysis_setup["chip_rate"])
    Ts = 1 / analysis_setup[
        "chip_rate"]  # transmitted symbol interval or a chip length
    logger.debug("chip length is %s ms", Ts)
    logger.debug("code period is %s ms",
                 analysis_setup["code_period"] / analysis_setup["chip_rate"])
    T_int = analysis_setup["n_o_samples"] / f_sampl
    logger.debug("time axis  length  is %s ms", T_int)
    t = np.arange(0, T_int, 1 / f_sampl)  # time axis
    logger.debug("time axis created, length  %s samples", t.size)

    f = ut.freq_fr_time(t)  # frequency axis
    logger.debug("frequency axis for spectral analysis, length  %s", f.size)
    tc = ut.corr_fr_time(t)  # correlation time axis
    logger.debug("time axis correlation created, length  %s samples", tc.size)
    tc_h = ut.corr_fr_halftime(t)  # correlation time axis
    logger.debug("half time axis correlation created, length  %s samples",
                 tc_h.size)

    tau = analysis_setup[
        "time_accelerating_factor"]  # time acceleration factor
    logger.debug("time acceleration factor is %s", tau)
    Tstr = Ts * tau  # Nyquist's symbol interval
    logger.debug("Transmitted (accelerated) chip length is %s ms", Tstr)
    td = analysis_setup[
        "time_offset"]  # initial delay of the sequence (time offset)
    logger.debug("Time offset (delay) of transmitted baseband signal is %s ms",
                 td)

    # Time Domain Signals
    # a1 = gen.rcos_tr(t, Tstr, td + Tstr / 2, x, Ts, 1.0)
    # a2 = gen.rcos_tr(t, Tstr, td + Tstr / 2, x, Ts, 0.5)
    # a3 = gen.rcos_tr(t, Tstr, td + Tstr / 2, x, Ts, 0.0)
    c = gen.rect_tr(t, Tstr, 0, td, code)
    logger.debug(
        "Oversampled signal with rectangular pulse shape created, number of samples %s",
        c.size)

    # Correlate processor
    c_con = np.concatenate((c, c))
    A1_c = ncorr.corr_fd(
        c,
        c,
    )
    # A1_c = signal.correlate(c, c_con, 'full', 'fft')
    # A1_c = signal.convolve(c, c, 'full')
    # A1_c = signal.fftconvolve(c, c, 'full')
    # A1_c = np.real(np.fft.ifft( np.fft.fft(c)*np.fft.fft(c) ))
    logger.debug("Autocorrelation function calculated, number of samples %s",
                 A1_c.size)

    ##################### Plots ###########################
    plotting_setup = stp.plotting_cnf_file_parser(setup_data["plt"])
    logger.debug("%s file read to setup plotting results", setup_data["plt"])

    if plotting_setup["plotting"]:
        #  Time domain
        f1 = plt.figure(1, figsize=(10, 7), dpi=300)
        f1ax1 = f1.add_subplot(211)
        texts = {
            "y_legend": "$h_{rect}(t), \\beta = 1.0$",
            "title": "Pulse-shaped time-domain baseband signal",
            "y_label": "$prn(t)$",
            "x_label": "time [ms]"
        }
        # figure_axes = [-0.25, 0.25, -100, 253000]
        aplt.timedomain_plot(f1ax1, t, c, texts=texts)

        #  Autocorrelated
        # f2 = plt.figure(2, figsize=(10, 7), dpi=300)
        # f2ax1 = f2.add_subplot(212)
        f1ax2 = f1.add_subplot(212)
        texts = {
            # "y_legend": "$h_{rect}(t), \\beta = 1.0$",
            # "title":"Pulse-shaped Autocorrelated",
            "y_label": "$C_{xx}(\\tau)$",
            "x_label": "time [ms]"
        }
        # figure_axes = [-0.25, 0.25, -100, 253000]
        tc_con = np.concatenate((tc, t))
        aplt.timedomain_plot(f1ax2, f, A1_c, texts=texts)

        if plotting_setup["show_plots"]:
            # f1.show()
            # f2.show()
            plt.show()

        if plotting_setup["save_plots"]:
            ssrg_time = setup_data[
                "data_path"] + 'ssrgout_timedomain.' + plotting_setup[
                    "plot_saving_format"]
            ssrg_corr = setup_data[
                "data_path"] + 'ssrgout_autocorr.' + plotting_setup[
                    "plot_saving_format"]
            f1.savefig(ssrg_time, format=plotting_setup["plot_saving_format"])