Ejemplo n.º 1
0
def main():
    # Setting up the coder's initialization and feedback vector
    init = np.array([1, 1, 1, 1])
    fb = np.array([0, 1, 0, 1])
    n_of_bits = 40
    # Running the coder
    out_seq = prn.ssrg(init, fb, n_bits=n_of_bits, verbosity=True)
    code = [int(elem) for elem in out_seq]
    # Mapping the code into symbols of two bits
    sym = map_4ary_symbols(code)
    bb = 2 * sym[:, 0] - 1 + (2 * sym[:, 1] - 1) * 1j
    # Prepare a csv file to test GNU Radio module
    write_csv(bb, 40, "test_data_ssrg01.csv")
Ejemplo n.º 2
0
from siggens import PRN_bitstreams as prn
from utils import freqaxis_shape as ut

from correlators import corrCUDA as corcud
from correlators import corrMKL as cormkl
from correlators import corrNumpy as cornp

##################### Parameters ######################
f_sampl = 50e3  # sampling frequency in kHz
T_int = 0.5  # entire signal length in ms

##################### Simulation ######################
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 = prn.gold_seq(3, 5, no_bits=500)  # code
Ts = 10e-3  # Nyquist's symbol interval
tau = 0.3  # time acceleration factor
Tstr = Ts * tau  # transmitted symbol interval
td = 0.05  # initial delay of the sequence (time offset)

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

print("Length of the signal", np.size(a1))

print(60 * '-')
print('CUDA correlator')
print(60 * '-')
p = profiler.Profile(signatures=False)
Ejemplo n.º 3
0
#!/usr/bin/env python

"""
This is a test bed script to plot a bitsteam with its
symbols shaped. 
"""
import sys
sys.path.append("../../sim")

import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt
from siggens import train_pulse as gen
from siggens import PRN_bitstreams as prn
from utils import freqaxis_shape as ut
from modulators import constallation_mappers as mod
from modulators import up_convertors as upcon


cd = prn.gold_seq(3,7,1,test=1,test_rep=50)
cd.tofile("code_PRN1.txt",format='%d',sep=',')
Ejemplo n.º 4
0
from siggens import PRN_bitstreams as prn
from utils import freqaxis_shape as ut
from modulators import constallation_mappers as mod
from modulators import up_convertors as upcon

##################### Parameters ######################
f_sampl = 900e6  # sampling frequency in Hz
T_int = 0.005115  # entire signal length in s

##################### Simulation BASEBAND ######################
t = np.arange(0, T_int, 1 / f_sampl)  # time axis
#f = ut.freq_fr_time (t)				# frequency axis
#cd = np.array([1,1,1,0,1,1,1,1,0,1,0,0,1,0,1]) # code
x1 = 2  # tap 1 to generate G2 in goldcode generator
x2 = 6  # tap 2 to generate G2 in goldcode generator
cd = prn.gold_seq(x1, x2, 1)
Tstr = 5e-6  # Nyquist's symbol interval
tau = 0.35  # time acceleration factor
Ts = Tstr / tau  # transmitted symbol interval
bitrate = 1 / Tstr
td = 0.0  # initial delay of the sequence (time offset)

# baseband signals
a1 = mod.rcos_bpsk_map(t, cd, bitrate, pw=Ts, alpha=1.0, td=Tstr / 2)
a2 = mod.rcos_bpsk_map(t, cd, bitrate, pw=Ts, alpha=0.5, td=Tstr / 2)
a3 = mod.rcos_bpsk_map(t, cd, bitrate, pw=Ts, alpha=0.0, td=Tstr / 2)
c = gen.rect_tr(t, Tstr, 0, td, cd)

##################### Simulation PASSBAND ######################

fc = 60e6  # carrier frequency in Hz
Ejemplo n.º 5
0
import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt
from siggens import train_pulse as gen
from siggens import PRN_bitstreams as prn
from utils import freqaxis_shape as ut

##################### Parameters ######################
f_sampl = 50e3 		# sampling frequency in kHz
T_int = 30 			# entire signal length in ms

##################### Simulation ######################
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 = prn.gold_seq(3,5,no_periods = 3)	# code
Ts = 10e-3							# Nyquist's symbol interval
tau = 0.3							# time acceleration factor
Tstr = Ts * tau						# transmitted symbol interval
td = 0.05							# initial delay of the sequence (time offset)

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

print ("Length of the signal", np.size(a1))

# Correlate processor
#ts = timer()
#A1_c = signal.correlate(a1,a1,'full')
#C1_c = signal.correlate( c,a1,'full')
import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt
from siggens import train_pulse as gen
from siggens import PRN_bitstreams as prn
from utils import freqaxis_shape as ut

##################### Parameters ######################
f_sampl = 50e3  # sampling frequency in kHz
T_int = 10.23  # entire signal length in ms

##################### 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 = prn.gold_seq(2, 6, 1)  # code

tau = 1  # time acceleration factor
Ts = 10e-3  # transmitted symbol interval
Tstr = Ts * tau  # Nyquist's symbol interval
td = 0  # 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')
Ejemplo n.º 7
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"])