Ejemplo n.º 1
0
def generator(Fs, i):
    print("Signal iteration", i)

    T = np.float(6e-3)  # Pulse duration
    # Time domain window for NLFM generation
    NLFM = radar.chirp(Fs)
    NLFM.fftLen = 2048

    sigObj = waveform()
    sigObj.Fs = Fs
    sigObj.T = T
    sigObj.symbolRate = 1 / T

    # Synthesize the target autocorrelation function
    #window_t = signal.chebwin(np.intc(2048), 60)
    window_t = signal.hamming(np.intc(2048))
    #window_t = signal.gaussian(np.intc(2048), 360)
    #window_t = signal.gaussian(np.intc(2048), 400)
    """
    # Random BW
    fStart = random.uniform(10e3,100e3)
    fStop = fStart+random.uniform(10e3,100e3)
    fCenter = fStop-(fStop-fStart)/2

    path = '../../waveforms/'
    """

    # Fixed BW
    fStart = random.uniform(10e3, 100e3)
    fStop = fStart + 50e3
    fCenter = fStop - (fStop - fStart) / 2

    sigObj.fCenter = fCenter
    sigObj.fStart = fStart
    sigObj.fStop = fStop

    path = '../waveforms/'

    sigObj.polynomial = NLFM.getCoefficients(window_t,
                                             targetBw=fStop - fStart,
                                             centerFreq=fCenter,
                                             T=T)
    sigObj.omega_t = NLFM.targetOmega_t

    # Center frequency is defined as the estimated center frequency in infinite SNR
    sig_t = NLFM.genNumerical()
    #sigObj.fCenter = estimate.carierFrequencyEstimator(sig_t, Fs, method='mle', nfft=len(sig_t))

    # Write to binary file
    filename = str(i)
    destination = path + filename + '.pkl'

    # Save sigObj to binary file
    with open(destination, 'wb') as f:
        pickle.dump(sigObj, f)
Ejemplo n.º 2
0
imagePath = '../figures/ModChirpPsd/'

import numpy as np
import rftool.radar as radar
import rftool.utility as util

Fs = np.intc(802e3)  # receiver sample rate
T = np.float(6e-3)  # Pulse duration
points = np.intc(Fs * T)
t = np.linspace(0, T, points)

targetBw = 50e3  # Pulse BW
centerFreq = 75e3  # Pulse center frequency

# Generate chirp
NLFM = radar.chirp(Fs)
window_t = signal.hamming(np.intc(2048))
NLFM.getCoefficients(window_t, targetBw=targetBw, centerFreq=centerFreq, T=T)
NLFMsig = NLFM.genNumerical()

#! Study a single symbol
"""sig_t = NLFM.modulate( np.array([1]) )
util.periodogram(sig_t, Fs)"""

# Periodogram of packet
bitstream = np.random.randint(0, 2, 32)
sig_t = NLFM.modulate(bitstream)

#util.periodogram(sig_t, Fs)
# Calculates Power Spectral Density in dBW/Hz.
fftLen = np.intc(2**15)
Ejemplo n.º 3
0
fCenterEstimate = np.zeros((nIterations, len(snrVector)), dtype=np.float64)
fCenterEstimate2 = np.zeros((nIterations, len(snrVector)), dtype=np.float64)
R_symbEstimate = np.zeros((nIterations, len(snrVector)), dtype=np.float64)
R_symbEstimate2 = np.zeros((nIterations, len(snrVector)), dtype=np.float64)

for i in range(0, nIterations):
    print("Iteration", i+1, "of", nIterations)
    
    # Load from binary file
    filename = str(i)
    fileString = path + filename + ".pkl"

    with open(fileString,'rb') as f:
        sigObj = pickle.load(f)

    NLFM = radar.chirp(sigObj.Fs)
    NLFM.targetOmega_t = sigObj.omega_t
    NLFM.points = len(sigObj.omega_t)
    NLFM.c = sigObj.polynomial

    packetSize=32
    package = np.random.randint(0, 2, packetSize)
    modSig = NLFM.modulate( package )
    targetR_symb = 1/NLFM.T

    # Calculate CRLB for the chirp in the SNR range
    if(i == 0):
        # Generate pulse
        #p_n = NLFM.genFromPoly()
        p_n = NLFM.genNumerical()
        # Number of pulses
Ejemplo n.º 4
0
        def estimate(i, SNRVector, estimator, packetSize=1, **kwargs):
            print(estimator.name, 'iteration', i)

            time = np.empty_like(SNRVector)
            AE = np.empty_like(SNRVector)

            if signalType == 'NLFM':
                # Load from binary file
                filename = str(i)
                fileString = self.path + filename + ".pkl"

                with open(fileString, 'rb') as f:
                    m_waveform = pickle.load(f)

                FM = radar.chirp(m_waveform.Fs)
                FM.targetOmega_t = m_waveform.omega_t
                FM.points = len(m_waveform.omega_t)

                if 1 < packetSize:
                    bitstream = np.random.randint(0, 2, packetSize)
                    m_waveform.packet = bitstream
                    sig_t = FM.modulate(bitstream)
                else:
                    sig_t = FM.genNumerical()
                    m_waveform.packet = 1

            elif signalType == 'LFM':
                m_waveform = kwargs.get('m_waveform')
                # Fixed BW, Random Center Frequency
                fStart = random.uniform(10e3, 100e3)
                fStop = fStart + 50e3
                fCenter = fStop - (fStop - fStart) / 2

                m_waveform.fCenter = fCenter
                m_waveform.fStart = fStart
                m_waveform.fStop = fStop

                FM = LFM.chirp(
                    Fs=m_waveform.Fs,
                    T=m_waveform.T,
                    fStart=fStart,
                    fStop=fStop,
                    nChirps=8,
                    direction='both'
                )  # Both directions and 8 symbols are configured in order to generate the sync sequence.

                if 1 < packetSize:
                    addSyncSeq = kwargs.get('syncSeq', False)
                    if addSyncSeq == True:
                        synqSeqSymbols = np.array(
                            [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 4, 4, 4])
                        symbolStream = np.random.randint(
                            0, 4, packetSize - len(synqSeqSymbols))
                        synqSeq = FM.modulate(synqSeqSymbols)
                        # Remove the last three quartes of a symbol
                        clipLen = np.intc(FM.Fs * FM.T * 0.75)
                        synqSeq = synqSeq[:-clipLen]
                        # Add a random packet to the sync sequence
                        sig_t = FM.modulate(symbolStream)
                        sig_t = np.append(synqSeq, sig_t)
                    else:
                        symbolStream = np.random.randint(0, 4, packetSize)
                        m_waveform.packet = symbolStream
                        sig_t = FM.modulate(symbolStream)
                else:
                    sig_t = FM.getSymbolSig(1)
                    m_waveform.packet = 1

            for m, SNR in enumerate(SNRVector):
                sig_noisy_t = util.wgnSnr(sig_t, SNR)
                tic = timeit.default_timer()
                # cleanSig and SNR is passed to enable CRLB calculation, fCenter for a-priori freq info for some estimators
                estimate = estimator.function(sig_noisy_t,
                                              **estimator.kwargs,
                                              SNR=SNR,
                                              cleanSig=sig_t,
                                              fCenterPriori=m_waveform.fCenter)
                toc = timeit.default_timer()

                # Calculate Accumulated Absolute Error
                # For packets, the inverse of the bitstream is accepted.
                if parameter == 'packet':
                    AE_temp = []
                    AE_temp.append(
                        np.sum(
                            np.abs(
                                np.subtract(m_waveform.returnValue(parameter),
                                            estimate))))
                    AE_temp.append(
                        np.sum(
                            np.abs(
                                np.subtract(m_waveform.returnValue(parameter),
                                            abs(1 - estimate)))))
                    AE[m] = np.min(AE_temp)
                    # If the error is greater than 50% then (for binary symbols) the packet is broken.
                    if len(estimate) / 2 < AE[m]:
                        AE[m] = len(estimate) / 2
                elif 'CRLB' in estimator.name:
                    AE[m] = estimate
                else:
                    AE[m] = np.sum(
                        np.abs(
                            np.subtract(m_waveform.returnValue(parameter),
                                        estimate)))
                # calculate execution time
                time[m] = toc - tic
            return AE, time