%% MATLAB SCRIPT TO READ, ORGANIZE AND PLOT .TXT FILES ACCORDING TO THE RADAR CONFIGURATION % 1) This script reads .txt files for the COSMOS defined use-cases. % Complex radar data is stored in seperate text files for real and imaginary parts. % 2) The data is then reshaped according to the 4D radar data format described in the attached document in the UBIRA repository % Anum Ahmed Pirkani % Microwave Integrated Systems Laboratory (MISL), University of Birmingham % Copyright 2022 University of Birmingham % Confidential - Authorised redistribution only % Note: %Change the Matlab directory to the folder with Text files of the use-case that needs to be processed. %Loading each .txt files will take processing time. %% Adding Relevant Paths % Change this path to the location of the extracted folder 'VariablesToPlot' addpath('D:\COSMOS_MIRA_SECOND_TRIALS\MatlabDataFiles\MATLAB_MAT_Files\VariablesToPlot') % Change this path to the location of the extracted folder with the use-case: Example here is: Case2d_Reference. % addpath('D:\COSMOS_MIRA_SECOND_TRIALS\MatlabDataFiles\MATLAB_MAT_Files\Case2d_Reference') %% Loading .TXT Files % Variables to Plot Data fid = fopen('Variable_CrossRange.txt', 'r'); CrossRange = fscanf(fid, '%g', inf); CrossRange = reshape(CrossRange,[1025 512]); fclose(fid); fid = fopen('Variable_Range.txt', 'r'); Range = fscanf(fid, '%g', inf); fclose(fid); fid = fopen('Variable_SlantRange.txt', 'r'); SlantRange = fscanf(fid, '%g', inf); SlantRange = reshape(SlantRange,[1025 512]); fclose(fid); fid = fopen('Variable_Velocity.txt', 'r'); Velocity = fscanf(fid, '%g', inf); Velocity = Velocity.'; fclose(fid); % Variable according to a specific Use-Case fid = fopen('Variable_Beamform.txt', 'r'); Beamform = fscanf(fid, '%g', inf); Beamform = reshape(Beamform,[1025 512 156]); fclose(fid); fid = fopen('Variable_RangeData_Real.txt', 'r'); RangeData_Real = fscanf(fid, '%g', inf); fclose(fid); fid = fopen('Variable_RangeData_Imag.txt', 'r'); RangeData_Imag = fscanf(fid, '%g', inf); fclose(fid); RangeData = RangeData_Real+1i*RangeData_Imag; RangeData = reshape(RangeData,[1025 4 128 156]); clearvars RangeData_Imag RangeDataReal fid = fopen('Variable_RangeDoppler_Real.txt', 'r'); RangeDoppler_Real = fscanf(fid, '%g', inf); fclose(fid); fid = fopen('Variable_RangeDoppler_Imag.txt', 'r'); RangeDoppler_Imag = fscanf(fid, '%g', inf); fclose(fid); RangeDoppler = RangeDoppler_Real+1i*RangeDoppler_Imag; RangeDoppler = reshape(RangeDoppler,[1025 4 128 156]); clearvars RangeDoppler_Imag RangeDoppler_Real fid = fopen('Variable_ZED_Image.txt', 'r'); ZED_Image = fscanf(fid, '%g', inf); ZED_Image = reshape(ZED_Image,[720 1280 3 156]); fclose(fid); %% Plotting Results MIMOFrame = 70; % Sample MIMO frame to plot: Change this from 1 to 156 figure; % Camera subplot(221) image(uint8(ZED_Image(:,:,:,MIMOFrame))); axis off;axis tight;title('Camera');set(gca,'fontsize',14) % Range subplot(222) ChirpToPlot = 20; % Sample chirp to plot: total 128 chirps available plot(Range,squeeze(20.*log10(abs(RangeData(:,:,ChirpToPlot,MIMOFrame))))+30); % result in dBm xlabel('Range (m)');ylabel('Power (dBm)');xlim([2 100]);grid minor;ylim([-100 -40]); legend({'Tx 1','Tx 2','Tx 3','Tx 4'},'NumColumns',2);title('Range FFT');set(gca,'fontsize',14); % Range Doppler subplot(223) TxChannel = 2; imagesc(Velocity,Range,20.*log10(abs(squeeze(RangeDoppler(:,TxChannel,:,MIMOFrame))))+30); xlabel('Speed (m/s)'); ylabel('Range (m)');set(gca,'YDir','normal');caxis([-80 -10]) xlim([min(Velocity) max(Velocity)]);ylim([0,100]);cc = colorbar; cc.Label.String = 'Power (dBm)'; colormap('jet');title('Range Doppler');set(gca,'fontsize',14); % Range Cross Range subplot(224) surf(CrossRange, SlantRange, 20*log10(Beamform(:,:,MIMOFrame))+30, 'edgecolor', 'none'); caxis([-50 20]);set(gca, 'YDir', 'reverse');axis tight;ax = axis;ax(1:4) = [0, 100, -30, 30]; axis(ax);grid minor;cc = colorbar;cc.Label.String = 'Power (dBm)';box on;zlim([-100 50]); view([-90 90]);xlabel('Range (m)');ylabel('Cross Range (m)');colormap('jet'); title('Range - Cross Range (MIMO)');set(gca,'fontsize',14)