Exemplo n.º 1
0
 def doppler_resolution(self):
     _, bw = dsp.range_resolution(
         self.cfg['profiles'][0]['adcSamples'],
         self.cfg['profiles'][0]['adcSampleRate'] / 1000,
         self.cfg['profiles'][0]['freqSlopeConst'] / 1e12)
     return dsp.doppler_resolution(
         bw,
         start_freq_const=self.cfg['profiles'][0]['start_frequency'] / 1e9,
         ramp_end_time=self.cfg['profiles'][0]['rampEndTime'] * 1e6,
         idle_time_const=self.cfg['profiles'][0]['idle'] * 1e6,
         num_loops_per_frame=self.cfg['numChirps'] /
         len(self.cfg['chirps']),
         num_tx_antennas=self.cfg['numTx'])
Exemplo n.º 2
0
    numLoopsPerFrame = configParameters['numLoops']
    numChirpsPerFrame = numTxAntennas * numLoopsPerFrame

    numRangeBins = numADCSamples

    # numDopplerBins = numLoopsPerFrame
    numDopplerBins = numLoopsPerFrame

    numAngleBins = 64

    # data processing parameter
    numDisplaySamples = 20

    range_resolution, bandwidth = dsp.range_resolution(
        numADCSamples,
        dig_out_sample_rate=configParameters['digOutSampleRate'],
        freq_slope_const=configParameters['freqSlopeConst'])
    doppler_resolution = dsp.doppler_resolution(
        bandwidth,
        start_freq_const=configParameters['startFreq'],
        ramp_end_time=configParameters['rampEndTime'],
        idle_time_const=configParameters['idleTime'],
        num_loops_per_frame=configParameters['numLoops'],
        num_tx_antennas=numTxAntennas)
    print(
        f'Range Resolution: {range_resolution}, Bandwidth: {bandwidth}, Doppler Resolution: {doppler_resolution}'
    )

    ims = []
    max_size = 0
Exemplo n.º 3
0
# QOL settings
loadData = True

numFrames = 300
numADCSamples = 128
numTxAntennas = 3
numRxAntennas = 4
numLoopsPerFrame = 128
numChirpsPerFrame = numTxAntennas * numLoopsPerFrame

numRangeBins = numADCSamples
numDopplerBins = numLoopsPerFrame
numAngleBins = 64

range_resolution, bandwidth = dsp.range_resolution(numADCSamples)
doppler_resolution = dsp.doppler_resolution(bandwidth)

plotRangeDopp = False
plot2DscatterXY = False
plot2DscatterXZ = False
plot3Dscatter = True
plotCustomPlt = False

plotMakeMovie = False
makeMovieTitle = "3dscatter"
makeMovieDirectory = r"c://Users//Zber//Desktop//mymovie.mp4"

visTrigger = plot2DscatterXY + plot2DscatterXZ + plot3Dscatter + plotRangeDopp + plotCustomPlt
assert visTrigger < 2, "Can only choose to plot one type of plot at once"
Exemplo n.º 4
0
def featureExtraction(folder, optPath):
    """
    Return opt: numFrame, 3 (heatmaps), 46*46(angle bin), nLoopsPerFrame 
    
    """
    
    startTime = ''
    with open(folder+'adc_data_Raw_LogFile.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        for row in csv_reader:
            if 'Capture start time' in str(row):
                startTimeRow = row
                break
    startTimeStr = startTimeRow[0].split(' - ')[1]
    timestamp = datetime.datetime.timestamp(parser.parse(startTimeStr))
    timestampList = []

    filename = folder + 'adc_data.bin'
    
    numFrames = 640
    numADCSamples = 512
    numTxAntennas = 2
    numRxAntennas = 4
    numLoopsPerFrame = 76
    numChirpsPerFrame = numTxAntennas * numLoopsPerFrame
    
    BINS_PROCESSED = 55
    ANGLE_RES = 1
    ANGLE_RANGE = 70
    ANGLE_BINS = (ANGLE_RANGE * 2) // ANGLE_RES + 1
    
    reso = dsp.range_resolution(numADCSamples, dig_out_sample_rate=6000, freq_slope_const=39.010)
    reso = round(reso[0], 4)
    
    adc_data = np.fromfile(filename, dtype=np.uint16)

    # (1) Load Data
    if adc_data.shape[0]<398458880:
        padSize = 398458880 - adc_data.shape[0]
        print("padded size: ", padSize)
        adc_data = np.pad(adc_data, padSize)[padSize:]
        
    adc_data = adc_data.reshape(numFrames, -1)
    adc_data = np.apply_along_axis(DCA1000.organize, 1, adc_data, num_chirps=numChirpsPerFrame,
                       num_rx=numRxAntennas, num_samples=numADCSamples)
    
    heatmaps = np.zeros((adc_data.shape[0], ANGLE_BINS, ANGLE_BINS), dtype = 'float32')
    
    numVirAntHori = 3
    numVirAntVer = 4
    
    # (2) Start DSP processing
    num_vec_4va, steering_vec_4va = dsp.gen_steering_vec(ANGLE_RANGE, ANGLE_RES, numVirAntVer)
    num_vec_3va, steering_vec_3va = dsp.gen_steering_vec(ANGLE_RANGE, ANGLE_RES, numVirAntHori)
    
    # (3) Process each frame
    for i, frame in enumerate(adc_data):
        timestamp+=0.033
        timestampList.append(timestamp)
        range_azimuth = np.zeros((ANGLE_BINS, BINS_PROCESSED-10))
        range_azimuth2 = np.zeros((ANGLE_BINS, BINS_PROCESSED-10))
        range_elevation = np.zeros((ANGLE_BINS, BINS_PROCESSED-10))
    
        # Range Processing
        radar_cube = dsp.range_processing(frame, window_type_1d=Window.BLACKMAN)
    
        """ (Capon Beamformer) """
        # --- static clutter removal / normalize
        mean = radar_cube.mean(0)
        radar_cube = radar_cube - mean
        

        # --- capon beamforming  
        beamWeights_azimuth = np.zeros((numVirAntHori, BINS_PROCESSED), dtype=np.complex_)
        beamWeights_azimuth2 = np.zeros((numVirAntHori, BINS_PROCESSED), dtype=np.complex_)
        beamWeights_elevation = np.zeros((numVirAntVer, BINS_PROCESSED), dtype=np.complex_)
        
        # Separate TX, rx 1234, vrx1234
        radar_cube = np.concatenate((radar_cube[0::2, ...], radar_cube[1::2, ...]), axis=1)
        
                
        # Note that when replacing with generic doppler estimation functions, radarCube is interleaved and
        # has doppler at the last dimension.
        # Range bin processed
        for j in range(10,BINS_PROCESSED):
            
            range_azimuth[:, j-10], beamWeights_azimuth[:, j-10] = dsp.aoa_capon( radar_cube[:, 1:4 , j-10].T, steering_vec_3va, magnitude=True)
            range_azimuth2[:, j-10], beamWeights_azimuth2[:, j-10] = dsp.aoa_capon( radar_cube[:, 5:8 , j-10].T, steering_vec_3va, magnitude=True)
            range_elevation[:, j-10], beamWeights_elevation[:, j-10] = dsp.aoa_capon( radar_cube[:, [0,4,1,5] , j-10].T,  steering_vec_4va, magnitude=True)
        
        # normalize
        prescale_factor = 10000000
        range_azimuth = scale(range_azimuth/prescale_factor, axis = 1)
        range_azimuth2 = scale(range_azimuth2/prescale_factor, axis = 1) 
        range_elevation = scale(range_elevation/prescale_factor, axis = 1) 
        
        range_azimuth = resize(range_azimuth, (ANGLE_BINS, ANGLE_BINS/3))
        range_azimuth2 = resize(range_azimuth2, (ANGLE_BINS, ANGLE_BINS/3))
        range_elevation = resize(range_elevation, (ANGLE_BINS, ANGLE_BINS/3))
        
        heatmaps[i,:,:] = np.concatenate((range_azimuth, range_azimuth2, range_elevation), axis = 1)
        
                
    # opt
    heatmaps=heatmaps.astype('float32')
    
    if np.isnan(heatmaps).sum() + np.isinf(heatmaps).sum() > 0:
        print('dtype: ', heatmaps.dtype, ', has NAN or INF error')
    else:
        print('dtype: ', heatmaps.dtype)


    if optPath != '':
        # if not os.path.isdir(optPath + '//'):
        #     os.mkdir(optPath + '//')
        np.savez(optPath+'.npz', heatmaps=heatmaps, timestampList=timestampList)
        
    return heatmaps, np.array(timestampList), reso
# Important Radar Scan Constants
# Using Radar: Texas Instruments 1843
num_frames = 500
num_adc_samples = 128
num_tx_antennas = 3
num_rx_antennas = 4
num_loops_per_frame = 128
num_chirps_per_frame = num_tx_antennas * num_loops_per_frame

num_range_bins = num_adc_samples
num_doppler_bins = num_loops_per_frame
num_angle_bins = 64
chirp_period = 0.06

range_resolution, bandwidth = dsp.range_resolution(num_adc_samples)
doppler_resolution = dsp.doppler_resolution(bandwidth)

load_data_flag = True

accumulate_flag = True
logGabor_flag = False
plot_range_doppler_flag = False

if __name__ == '__main__':

    if load_data_flag:
        # (1) Reading in adc data
        adc_data = np.fromfile('./data/processed/uDoppler1.bin',
                               dtype=np.int16)
        # adc_data = np.fromfile('./scripts/data/adc_data.bin', dtype=np.int16)
Exemplo n.º 6
0
def generate_spectrum_from_RDC(filename,
                               numFrames=500,
                               numADCSamples=128,
                               numTxAntennas=3,
                               numRxAntennas=4,
                               numLoopsPerFrame=128,
                               numAngleBins=64,
                               chirpPeriod=0.06,
                               logGabor=False,
                               accumulate=True,
                               save_full=False):
    numChirpsPerFrame = numTxAntennas * numLoopsPerFrame

    # =============================================================================
    #     numADCSamples = number of range bins
    #     numLoopsPerFrame = number of doppler bins
    # =============================================================================

    range_resolution, bandwidth = dsp.range_resolution(numADCSamples)
    doppler_resolution = dsp.doppler_resolution(bandwidth)

    if filename[-4:] != '.bin':
        filename += '.bin'

    adc_data = np.fromfile(filename, dtype=np.int16)
    adc_data = adc_data.reshape(numFrames, -1)
    adc_data = np.apply_along_axis(DCA1000.organize,
                                   1,
                                   adc_data,
                                   num_chirps=numChirpsPerFrame,
                                   num_rx=numRxAntennas,
                                   num_samples=numADCSamples)
    print("Data Loaded!")

    dataCube = adc_data
    micro_doppler_data = np.zeros((numFrames, numLoopsPerFrame, numADCSamples),
                                  dtype=np.float64)
    theta_data = np.zeros((numFrames, numLoopsPerFrame,
                           numTxAntennas * numRxAntennas, numADCSamples),
                          dtype=np.complex)

    for i, frame in enumerate(dataCube):
        # (2) Range Processing
        from mmwave.dsp.utils import Window

        radar_cube = dsp.range_processing(frame,
                                          window_type_1d=Window.BLACKMAN)
        assert radar_cube.shape == (
            numChirpsPerFrame, numRxAntennas,
            numADCSamples), "[ERROR] Radar cube is not the correct shape!"

        # (3) Doppler Processing
        det_matrix, theta_data[i] = dsp.doppler_processing(
            radar_cube,
            num_tx_antennas=3,
            clutter_removal_enabled=True,
            window_type_2d=Window.HAMMING)

        # --- Shifts & Store
        det_matrix_vis = np.fft.fftshift(det_matrix, axes=1)
        micro_doppler_data[i, :, :] = det_matrix_vis
        # Data should now be ready. Needs to be in micro_doppler_data, a 3D-numpy array with shape [numDoppler, numRanges, numFrames]

        # LOG GABOR
        if logGabor:
            if accumulate:
                image = micro_doppler_data.sum(axis=1).T
            else:
                image = micro_doppler_data.T

            from LogGabor import LogGabor
            import holoviews as hv

            lg = LogGabor("default_param.py")
            lg.set_size(image)
            lg.pe.datapath = 'database/'

            image = lg.normalize(image, center=True)

            # display input image
            # hv.Image(image)

            # display log gabor'd image
            image = lg.whitening(image) * lg.mask
            hv.Image(image)

            uDoppler = image
        elif accumulate:
            uDoppler = micro_doppler_data.sum(axis=1).T
        else:
            uDoppler = micro_doppler_data.T

    if save_full:
        return range_resolution, doppler_resolution, uDoppler, theta_data
    else:
        return range_resolution, doppler_resolution, uDoppler
Exemplo n.º 7
0
import matplotlib.pyplot as plt
import numpy as np
from mmwave import dsp
# Radar specific parameters
from mmwave.dsp import Window

from radar_utils.data_loader import load_file
from dsp_utils import extract_phases
from etc.config_1 import adc_samples, NUM_FRAMES
from filter_params import dist_range_bottom, dist_range_top, all_data, freq_range_top, freq_range_bottom, \
    slow_sample_rate, time_filter_bottom, time_filter_top
from plot_utils import plot_named_list, plot_range_maps
from signal_generation import table

fig = plt.figure()
range_res, _ = dsp.range_resolution(200, 4000, 70)
freq_res = 20 / 1000  # 20 Hz / 1000 samples
ranges = np.arange(adc_samples) * range_res
range_mask = (dist_range_bottom < ranges) & (ranges < dist_range_top)
ranges_filtered = ranges[range_mask]
frequencies = np.arange(0, NUM_FRAMES / 2) * freq_res
frequency_mask = (frequencies > freq_range_bottom) & (frequencies <
                                                      freq_range_top)
frequencies_filtered = frequencies[frequency_mask]
times = np.arange(0, NUM_FRAMES) * slow_sample_rate
time_mask = (time_filter_bottom < times) & (times < time_filter_top)
times_filtered = times[time_mask]

keyword = "s"

data_set = [
Exemplo n.º 8
0
 def range_resolution(self):
     range_res, bw = dsp.range_resolution(
         self.cfg['profiles'][0]['adcSamples'],
         self.cfg['profiles'][0]['adcSampleRate'] / 1000,
         self.cfg['profiles'][0]['freqSlopeConst'] / 1e12)
     return range_res
Exemplo n.º 9
0
import numpy as np
# Radar specific parameters
from mmwave.dsp import range_resolution, doppler_resolution

from etc.config_1 import NUM_CHIRPS, NUM_ADC_SAMPLES, sample_rate, freq_slope, adc_samples, \
    start_freq, idle_time, ramp_end_time

# Data specific parameters

# DSP processing parameters

# Data sampling configuration

# Range and Velocity resolution
range_res, band_width = range_resolution(NUM_ADC_SAMPLES, sample_rate,
                                         freq_slope)
# range_res = RANGE_RESOLUTION
print(f'Range Resolution: {range_res} [meters]')
velocity_res = doppler_resolution(band_width, start_freq, ramp_end_time,
                                  idle_time, NUM_CHIRPS, 1)
print(f'Velocity Resolution: {velocity_res} [meters/second]')

# Apply the range resolution factor to the range indices
ranges = np.arange(adc_samples) * range_res


def load_file(file_path, radar_config=None, discard_rx=True):
    adc_data = np.fromfile(file_path, dtype=np.uint16)
    adc_data = adc_data.reshape(NUM_FRAMES, -1)
    all_data = np.apply_along_axis(DCA1000.organize,
                                   1,