├── README.md ├── Radar_Target_Generation_and_Detection.m └── pics ├── 1Drange.jpg ├── 2dCFAR.png ├── 2dCFAR1.jpg ├── 2dCFAR2.jpg ├── 2dCFAR3.jpg ├── CFAR.png └── range_velocity.jpg /README.md: -------------------------------------------------------------------------------- 1 | # Radar Target Generation and Detection in MATLAB 2 | 3 | ## Radar Setup : 4 | 5 | ``` 6 | %% Radar Specifications 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | % Frequency of operation = 77GHz 9 | 10 | % Range Resolution = 1 m 11 | 12 | % Max Velocity = 100 m/s 13 | 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | Range_res = 1; 17 | Light_speed = 3e8; 18 | Max_range = 200; 19 | Max_velocity = 100; 20 | 21 | ``` 22 | 23 | ## Taget Info: 24 | ``` 25 | %max range of target is 200m 26 | % min/max velocity is -70 to 70 m/s 27 | 28 | Range_target = 120; 29 | Velocity_target = 40; 30 | 31 | ``` 32 | 33 | 34 | ## Frequency Modulated Continous Wave (FMCW) 35 | ``` 36 | %Operating carrier frequency of Radar 37 | fc= 77e9; 38 | 39 | % Bandwith of the chirp signal 40 | 41 | B_sweep = Light_speed/(2*Range_res); 42 | 43 | % Chirp signal sweep time 44 | 45 | T_c = 5.5*2*Max_range/Light_speed; 46 | 47 | % The slope of the upramp chirp 48 | slope = B_sweep/T_c; 49 | 50 | %The number of chirps in one sequence. Its ideal to have 2^ value for the ease of running the FFT 51 | %for Doppler Estimation. 52 | 53 | Nd=128; % #of doppler cells OR #of sent periods 54 | 55 | % number of chirps 56 | 57 | %The number of samples on each chirp. 58 | 59 | Nr=1024; %for length of time OR # of range cells 60 | 61 | ``` 62 | 63 | ## FFT (1D for the range detection): 64 | * Implement the 1D FFT on the Mixed Signal (Computed from the transimit signal and received signal, from code #line 73 ~ 92) 65 | * Reshape the vector into Nr*Nd array. 66 | * Run the FFT on the beat signal along the range bins dimension (Nr) 67 | * Normalize the FFT output. 68 | * Take the absolute value of that output. 69 | * Keep one half of the signal 70 | * Plot the output 71 | * There should be a peak at the initial position of the target 72 | 73 | ![range](./pics/1Drange.jpg) 74 | 75 | From the plot, the target is 120 meter away from the radar, it is exactly the same to target range in the setup 76 | 77 | ## FFT(2D for the range and velocity detection): 78 | ``` 79 | sig_fft2 = fft2(Mix,Nr,Nd); 80 | sig_fft2 = sig_fft2(1:Nr/2,1:Nd); 81 | sig_fft2 = fftshift (sig_fft2); 82 | ``` 83 | ![range_velocity](./pics/range_velocity.jpg) 84 | 85 | * x represents the speed (~39m/s) is close to the target speed (40 m/s) 86 | * y represents the range (~120 m) is close to the target range (120 m) 87 | 88 | ## 2d Constant Flase Alarm Rate(2D-CFAR) 89 | 90 | ![CFAR](./pics/CFAR.png) 91 | 92 | The false alarm issue can be resolved by implementing the constant false alarm rate. CFAR varies the detection threshold based on the vehicle surroundings. The CFAR technique estimates the level of interference in radar range and doppler cells “Training Cells” on either or both the side of the “Cell Under Test”. The estimate is then used to decide if the target is in the Cell Under Test (CUT). 93 | 94 | The process loops across all the range cells and decides the presence of target based on the noise estimate.The basis of the process is that when noise is present, the cells around the cell of interest will contain a good estimate of the noise, i.e. it assumes that the noise or interference is spatially or temporarily homogeneous. Theoretically it will produce a constant false alarm rate, which is independent of the noise or clutter level 95 | 96 | ![2dCFAR](./pics/2dCFAR.png) 97 | 98 | * Determine the number of Training cells for each dimension Tr and Td. Similarly, pick the number of guard cells Gr and Gd. 99 | * Slide the Cell Under Test (CUT) across the complete cell matrix 100 | * Select the grid that includes the training, guard and test cells. Grid Size = (2Tr+2Gr+1)(2Td+2Gd+1). 101 | * The total number of cells in the guard region and cell under test. (2Gr+1)(2Gd+1). 102 | * This gives the Training Cells : (2Tr+2Gr+1)(2Td+2Gd+1) - (2Gr+1)(2Gd+1) 103 | * Measure and average the noise across all the training cells. This gives the threshold 104 | * Add the offset (if in signal strength in dB) to the threshold to keep the false alarm to the minimum. 105 | * Determine the signal level at the Cell Under Test. 106 | * if the CUT signal level is greater than the Threshold, assign a value of 1, else equate it to zero. 107 | * Since the cell under test are not located at the edges, due to the training cells occupying the edges, we suppress the edges to zero. Any cell value that is neither 1 nor a 0, assign it a zero. 108 | 109 | ``` 110 | 111 | for i = Tr+Gr+1:(Nr/2-Tr-Gr) 112 | for j = Tc+Gc+1:(Nd-Tc-Gc) 113 | noise_level = zeros(1,1); 114 | for k = (i-Tr-Gr) : (i+Tr+Gr) 115 | for h = (j-Tc-Gc) : (j+Gc+Tc) 116 | if(abs(k-i)>Gr||abs(h-j)>Gc) 117 | noise_level = noise_level + db2pow(RDM(k,h)); 118 | end 119 | end 120 | end 121 | length = 2*(Tr+Gr)+1; 122 | width = 2*(Tc+Gc)+1; 123 | threshold = pow2db(noise_level/(length*width-(2*Gr+1)*(2*Gc+1)))*1.4; 124 | if(RDM(i,j)>threshold) 125 | CUT(i,j) = 1; 126 | else 127 | CUT(i,j) = 0; 128 | end 129 | end 130 | end 131 | 132 | ``` 133 | 134 | ### output 135 | ![CFAR1](./pics/2dCFAR1.jpg) 136 | 137 | ![CFAR1](./pics/2dCFAR2.jpg) 138 | 139 | ![CFAR1](./pics/2dCFAR3.jpg) -------------------------------------------------------------------------------- /Radar_Target_Generation_and_Detection.m: -------------------------------------------------------------------------------- 1 | clear all 2 | clc; 3 | close all; 4 | 5 | %% Radar Specifications 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | % Frequency of operation = 77GHz 8 | 9 | % Max Range = 200m 10 | % Range Resolution = 1 m 11 | 12 | % Max Velocity = 100 m/s 13 | 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | Range_res = 1; 17 | Light_speed = 3e8; 18 | Max_range = 200; 19 | Max_velocity = 100; 20 | 21 | 22 | %speed of light = 3e8 23 | %% User Defined Range and Velocity of target 24 | % *%TODO* : 25 | % define the target's initial position and velocity. Note : Velocity 26 | % remains contant 27 | Range_target = 120; 28 | Velocity_target = 40; 29 | 30 | 31 | %% FMCW Waveform Generation 32 | 33 | % *%TODO* : 34 | %Design the FMCW waveform by giving the specs of each of its parameters. 35 | % Calculate the Bandwidth (B), Chirp Time (Tchirp) and Slope (slope) of the FMCW 36 | % chirp using the requirements above. 37 | 38 | 39 | %Operating carrier frequency of Radar 40 | fc= 77e9; %carrier freq 41 | 42 | B_sweep = Light_speed/(2*Range_res); 43 | 44 | T_c = 5.5*2*Max_range/Light_speed; 45 | 46 | slope = B_sweep/T_c; 47 | 48 | %The number of chirps in one sequence. Its ideal to have 2^ value for the ease of running the FFT 49 | %for Doppler Estimation. 50 | Nd=128; % #of doppler cells OR #of sent periods % number of chirps 51 | 52 | %The number of samples on each chirp. 53 | Nr=1024; %for length of time OR # of range cells 54 | 55 | % Timestamp for running the displacement scenario for every sample on each 56 | % chirp 57 | t=linspace(0,Nd*T_c,Nr*Nd); %total time for samples 58 | 59 | %Creating the vectors for Tx, Rx and Mix based on the total samples input. 60 | Tx=zeros(1,length(t)); %transmitted signal 61 | Rx=zeros(1,length(t)); %received signal 62 | Mix = zeros(1,length(t)); %beat signal 63 | 64 | 65 | %Similar vectors for range_covered and time delay. 66 | r_t=zeros(1,length(t)); 67 | td=zeros(1,length(t)); 68 | 69 | 70 | %% Signal generation and Moving Target simulation 71 | % Running the radar scenario over the time. 72 | 73 | for i=1:length(t) 74 | 75 | 76 | % *%TODO* : 77 | %For each time stamp update the Range of the Target for constant velocity. 78 | 79 | r_t(i) = Range_target + t(i)*Velocity_target; 80 | td(i) = r_t(i)*2/Light_speed; 81 | 82 | % *%TODO* : 83 | %For each time sample we need update the transmitted and 84 | %received signal. 85 | Tx(i) = cos(2*pi*(fc*t(i)+0.5*slope*t(i)^2)); 86 | Rx(i) = cos(2*pi*(fc*(t(i)-td(i))+0.5*(t(i)-td(i))^2*slope)); 87 | 88 | % *%TODO* : 89 | %Now by mixing the Transmit and Receive generate the beat signal 90 | %This is done by element wise matrix multiplication of Transmit and 91 | %Receiver Signal 92 | Mix(i) = Tx(i).*Rx(i); 93 | 94 | end 95 | 96 | %% RANGE MEASUREMENT 97 | 98 | 99 | % *%TODO* : 100 | %reshape the vector into Nr*Nd array. Nr and Nd here would also define the size of 101 | %Range and Doppler FFT respectively. 102 | 103 | Mix = reshape(Mix,[Nr, Nd]); 104 | 105 | % *%TODO* : 106 | %run the FFT on the beat signal along the range bins dimension (Nr) and 107 | %normalize. 108 | fft1D = fft(Mix,Nr); 109 | 110 | % *%TODO* : 111 | % Take the absolute value of FFT output 112 | 113 | fft1D = abs(fft1D); 114 | fft1D = fft1D/max(fft1D); 115 | 116 | % *%TODO* : 117 | % Output of FFT is double sided signal, but we are interested in only one side of the spectrum. 118 | % Hence we throw out half of the samples. 119 | 120 | final_fft1D = fft1D(1:Nr/2+1); 121 | 122 | %plotting the range 123 | figure ('Name','Range from First FFT') 124 | plot(fft1D) 125 | axis ([0 200 0 1]); 126 | ylabel('Normalized Amplitude') 127 | xlabel('Range'); 128 | % *%TODO* : 129 | % plot FFT output 130 | 131 | 132 | 133 | 134 | 135 | 136 | % RANGE DOPPLER RESPONSE 137 | % The 2D FFT implementation is already provided here. This will run a 2DFFT 138 | % on the mixed signal (beat signal) output and generate a range doppler 139 | % map.You will implement CFAR on the generated RDM 140 | % 141 | % 142 | % Range Doppler Map Generation. 143 | % 144 | % The output of the 2D FFT is an image that has reponse in the range and 145 | % doppler FFT bins. So, it is important to convert the axis from bin sizes 146 | % to range and doppler based on their Max values. 147 | 148 | Mix=reshape(Mix,[Nr,Nd]); 149 | 150 | % 2D FFT using the FFT size for both dimensions. 151 | sig_fft2 = fft2(Mix,Nr,Nd); 152 | 153 | % Taking just one side of signal from Range dimension. 154 | sig_fft2 = sig_fft2(1:Nr/2,1:Nd); 155 | sig_fft2 = fftshift (sig_fft2); 156 | RDM = abs(sig_fft2); 157 | RDM = 10*log10(RDM) ; 158 | 159 | %use the surf function to plot the output of 2DFFT and to show axis in both 160 | %dimensions 161 | doppler_axis = linspace(-100,100,Nd); 162 | range_axis = linspace(-200,200,Nr/2)*((Nr/2)/400); 163 | 164 | figure ('Name','surface plot of FFT2') 165 | surf(doppler_axis,range_axis,RDM); 166 | title('FFT2 surface plot') 167 | xlabel('speed') 168 | ylabel('Range') 169 | zlabel('Amplitude') 170 | 171 | %% CFAR implementation 172 | 173 | %Slide Window through the complete Range Doppler Map 174 | 175 | % *%TODO* : 176 | %Select the number of Training Cells in both the dimensions. 177 | Tr = 10; 178 | Tc = 7; 179 | 180 | % *%TODO* : 181 | %Select the number of Guard Cells in both dimensions around the Cell under 182 | %test (CUT) for accurate estimation 183 | Gc = 4; 184 | Gr = 4; 185 | % *%TODO* : 186 | % offset the threshold by SNR value in dB 187 | offset = 1.6; 188 | % *%TODO* : 189 | %Create a vector to store noise_level for each iteration on training cells 190 | 191 | 192 | 193 | % *%TODO* : 194 | %design a loop such that it slides the CUT across range doppler map by 195 | %giving margins at the edges for Training and Guard Cells. 196 | %For every iteration sum the signal level within all the training 197 | %cells. To sum convert the value from logarithmic to linear using db2pow 198 | %function. Average the summed values for all of the training 199 | %cells used. After averaging convert it back to logarithimic using pow2db. 200 | %Further add the offset to it to determine the threshold. Next, compare the 201 | %signal under CUT with this threshold. If the CUT level > threshold assign 202 | %it a value of 1, else equate it to 0. 203 | 204 | 205 | % Use RDM[x,y] as the matrix from the output of 2D FFT for implementing 206 | % CFAR 207 | % normalized the RDM 208 | 209 | RDM = RDM/max(max(RDM)); 210 | [row,col] = size(RDM); 211 | CUT = zeros(row,col); 212 | 213 | for i = Tr+Gr+1:(Nr/2-Tr-Gr) 214 | for j = Tc+Gc+1:(Nd-Tc-Gc) 215 | noise_level = zeros(1,1); 216 | for k = (i-Tr-Gr) : (i+Tr+Gr) 217 | for h = (j-Tc-Gc) : (j+Gc+Tc) 218 | if(abs(k-i)>Gr||abs(h-j)>Gc) 219 | noise_level = noise_level + db2pow(RDM(k,h)); 220 | end 221 | end 222 | end 223 | length = 2*(Tr+Gr)+1; 224 | width = 2*(Tc+Gc)+1; 225 | threshold = pow2db(noise_level/(length*width-(2*Gr+1)*(2*Gc+1)))*1.4; 226 | if(RDM(i,j)>threshold) 227 | CUT(i,j) = 1; 228 | else 229 | CUT(i,j) = 0; 230 | end 231 | end 232 | end 233 | 234 | 235 | % *%TODO* : 236 | % The process above will generate a thresholded block, which is smaller 237 | %than the Range Doppler Map as the CUT cannot be located at the edges of 238 | %matrix. Hence,few cells will not be thresholded. To keep the map size same 239 | % set those values to 0. 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | % *%TODO* : 250 | %display the CFAR output using the Surf function like we did for Range 251 | %Doppler Response output. 252 | figure('Name', 'CA-CFAR Filtered RDM') 253 | surf(doppler_axis,range_axis,CUT); 254 | colorbar; 255 | title( 'CA-CFAR Filtered RDM surface plot'); 256 | xlabel('Speed'); 257 | ylabel('Range'); 258 | zlabel('Normalized Amplitude'); 259 | 260 | figure('Name', 'CA-CFAR Filtered Range') 261 | surf(doppler_axis,range_axis,CUT); 262 | colorbar; 263 | title( 'CA-CFAR Filtered RDM surface plot'); 264 | xlabel('Speed'); 265 | ylabel('Range'); 266 | zlabel('Normalized Amplitude'); 267 | view(90,0); 268 | 269 | figure('Name', 'CA-CFAR Filtered Speed') 270 | surf(doppler_axis,range_axis,CUT); 271 | colorbar; 272 | title( 'CA-CFAR Filtered RDM surface plot'); 273 | xlabel('Speed'); 274 | ylabel('Range'); 275 | zlabel('Normalized Amplitude'); 276 | view(0,0); 277 | 278 | -------------------------------------------------------------------------------- /pics/1Drange.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/1Drange.jpg -------------------------------------------------------------------------------- /pics/2dCFAR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/2dCFAR.png -------------------------------------------------------------------------------- /pics/2dCFAR1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/2dCFAR1.jpg -------------------------------------------------------------------------------- /pics/2dCFAR2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/2dCFAR2.jpg -------------------------------------------------------------------------------- /pics/2dCFAR3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/2dCFAR3.jpg -------------------------------------------------------------------------------- /pics/CFAR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/CFAR.png -------------------------------------------------------------------------------- /pics/range_velocity.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoJi07/Radar-target-generation-and-detection/4a2c9235b8faec70602c7ab0d23cfd191c8279dd/pics/range_velocity.jpg --------------------------------------------------------------------------------