├── README.md ├── graphs ├── CA-CFAR.png ├── range_1st_FFT.png ├── range_doppler_map_1.png └── range_doppler_map_2.png └── main.m /README.md: -------------------------------------------------------------------------------- 1 | # Detecting targets using simulated radar measurements 2 | 3 | ## Steps 4 | 5 | Designing wave 6 | 7 | d_res = 1; 8 | speed_of_light = 3*10^8; % 3e8 9 | RMax = 200; 10 | 11 | Bsweep = speed_of_light / (2 * d_res); % bandwidth 12 | Tchirp = 5.5 * 2 * RMax / speed_of_light; % chirp time 13 | alpha = Bsweep / Tchirp; % slope of FMCW chirps 14 | fc = 77e9; % carrier frequency of radar 15 | 16 | Nd = 128; % number of chirps in one sequence 17 | Nr = 1024; % number of samples on each chirp 18 | 19 | t = linspace(0, Nd * Tchirp, Nr * Nd); % total time for samples 20 | 21 | % vectors for Tx, Rx and Mix based on the total samples input 22 | Tx = zeros(1, length(t)); % transmitted signal 23 | Rx = zeros(1, length(t)); % received signal 24 | Mix = zeros(1, length(t)); % beat signal 25 | 26 | % vectors for range covered and time delay 27 | r_t = zeros(1, length(t)); 28 | td = zeros(1, length(t)); 29 | 30 | %% Signal generation and Moving Target simulation 31 | % Running the radar scenario over the time. 32 | 33 | for i = 1:length(t) 34 | % for each timestamp update the range of the target for constant velocity 35 | r_t(i) = d0 + v0 * t(i); 36 | td(i) = 2 * r_t(i) / speed_of_light; 37 | 38 | % for each time sample update the transmitted and received signal 39 | Tx(i) = cos(2 * pi * (fc * t(i) + alpha * t(i)^2 / 2)); 40 | Rx(i) = cos(2 * pi * (fc * (t(i) - td(i)) + (alpha * (t(i) - td(i))^2) / 2)); 41 | 42 | % now by mixing the transmit and receive generate the beat signal by performing 43 | % element-wise matrix multiplication of transmit and receiver signal 44 | Mix(i) = Tx(i) .* Rx(i); % beat signal 45 | end 46 | 47 | 48 | FFT 49 | 50 | %% RANGE (1st FFT) 51 | 52 | % running the Fast Fourier Transform (FFT) on the beat signal along the range bins dimension (Nr) and normalise 53 | sig_fft = fft(Mix, Nr) ./ Nr; 54 | 55 | % taking absolute value of FFT output 56 | sig_fft = abs(sig_fft); 57 | 58 | % output of FFT is double-sided signal, but since we are interested in one side of the spectrum only, we throw out half of the samples 59 | sig_fft = sig_fft(1 : (Nr / 2)); 60 | 61 | %% VELOCITY (2nd FFT) 62 | 63 | Mix = reshape(Mix, [Nr, Nd]); 64 | 65 | % 2D FFT using the FFT size for both dimensions 66 | sig_fft2 = fft2(Mix, Nr, Nd); 67 | 68 | % taking just one side of signal from range dimension 69 | sig_fft2 = sig_fft2(1 : Nr / 2, 1 : Nd); 70 | sig_fft2 = fftshift(sig_fft2); 71 | RDM = abs(sig_fft2); 72 | RDM = 10*log10(RDM); 73 | 74 | 75 | Selecting training, guard cells and offset 76 | 77 | % selecting number of training cells in both the dimensions by trial and error trying to match objective 78 | Tcr = 10; 79 | Tcd = 4; 80 | 81 | % selecting number of guard cells in both dimensions around the Cell Under Test (CUT) for accurate estimation 82 | Gcr = 5; 83 | Gcd = 2; 84 | 85 | % offsetting the threshold by signal-to-noise-ratio (SNR) value in dB 86 | offset = 1.4; 87 | 88 | % creating vector to store noise level for each iteration on training cells 89 | noise_level = zeros(Nr / 2 - 2 * (Tcd + Gcd), Nd - 2 * (Tcr + Gcr)); 90 | gridSize = (2 * Tcr + 2 * Gcr + 1) * (2 * Tcd + 2 * Gcd + 1); 91 | trainingCellsNum = gridSize - (2 * Gcr + 1) * (2 * Gcd + 1); 92 | 93 | 94 | Suppressing the non-thresholded cells at the edges 95 | 96 | Generating a thresholded block, which is smaller than the Range Doppler Map as the CUT cannot be located at the edges of matrix. Hence, few cells will not be thresholded. To keep the map size same set those values to 0 97 | 98 | CFAR_sig = zeros(size(RDM)); 99 | 100 | % Using RDM[x,y] as the matrix from the output of 2D FFT for implementing CFAR 101 | for j = 1 : Nd - 2 * (Tcr + Gcr) 102 | for i = 1 : Nr / 2 - 2 * (Tcd + Gcd) 103 | 104 | 105 | ![1D-FFT](graphs/range_1st_FFT.png) 106 | 107 | ![Range Doppler Map](graphs/range_doppler_map_1.png) 108 | 109 | ![Same Range Doppler Map](graphs/range_doppler_map_2.png) 110 | 111 | ![CA-CFAR](graphs/CA-CFAR.png) 112 | -------------------------------------------------------------------------------- /graphs/CA-CFAR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maggieliuzzi/radar_target_simulation_and_detection/a6c82462670ef19ae14a2b972c441eeb76b6835f/graphs/CA-CFAR.png -------------------------------------------------------------------------------- /graphs/range_1st_FFT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maggieliuzzi/radar_target_simulation_and_detection/a6c82462670ef19ae14a2b972c441eeb76b6835f/graphs/range_1st_FFT.png -------------------------------------------------------------------------------- /graphs/range_doppler_map_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maggieliuzzi/radar_target_simulation_and_detection/a6c82462670ef19ae14a2b972c441eeb76b6835f/graphs/range_doppler_map_1.png -------------------------------------------------------------------------------- /graphs/range_doppler_map_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maggieliuzzi/radar_target_simulation_and_detection/a6c82462670ef19ae14a2b972c441eeb76b6835f/graphs/range_doppler_map_2.png -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | clear 2 | clc 3 | close all 4 | 5 | 6 | %% DEFINITIONS AND FUNCTIONS 7 | 8 | % wavelength = speed of light / frequency 9 | % Frequency of a wave: the number of waves that pass by each second, and is measured in Hertz (Hz). 10 | % The automotive radar generally operates at W band (76GHz - 81GHz). 11 | % The signal at this frequency is referred to as millimeterWave since the wavelength is in mm. 12 | % The frequency can also be defined as the first derivative of the phase with respect to the time. 13 | % Bandwidth of a signal: the difference between the highest and the lowest frequency components in a continous band of frequencies. 14 | % Amplitude: the strength of the signal. Often it corresponds to the power of the RF signal/electromagnetic field defined in dB/dBm. 15 | % It is relevant while configuring the output power of the radar and sensing the received signal. 16 | % Higher the amplitude of the Radar signal, more is the visibility of radar. 17 | % Automotive Radar can operate at max of 55 dBm output power (316 W) 18 | % Phase: a particular point in time on the cycle of a waveform, measured as an angle in degrees. 19 | 20 | %% FMCW Hardware: 21 | % Frequency Synthesizer: The frequency synthesizer is the component that generates the frequency to bring the chirp frequency all the way to 77GHz in case of automotive radar. 22 | % Power Amp: The power amp amplifies the signal so the signal can reach long distance. Since the signal attenuates as it radiates, it needs higher power (amplitude) to reach targets at greater distances. 23 | % Antenna: The antenna converts the electrical energy into electromagnetic waves which radiate through the air, hit the target, and get reflected back toward the radar receiver antenna. The Antenna also increases the strength of the signal by focusing the energy in the desired direction. Additionally, the antenna pattern determines the field of view for the radar. 24 | % Mixer: In FMCW radar, the mixer multiplies the return signal with the sweeping signal generated by the frequency synthesizer. The operation works as frequency subtraction to give the frequency delta - also known as frequency shift or Intermediate frequency (IF). IF = Synthesizer Frequency - Return Signal Frequency. 25 | % Processor: The processor is the processing unit where all the Digital Signal processing, Detection, Tracking, Clustering, and other algorithms take place. This unit could be a microcontroller or even an FPGA. 26 | 27 | %% Resolution: 28 | % Range Resolution: it is the capability of the radar to distinguish between two targets that are very close to each other in range. If a radar has range resolution of 4 meters then it cannot separate on range basis a pedestrian standing 1 m away from the car. The range resolution is solely dependent on the bandwidth of the chirp (Bsweep) 29 | % Velocity Resolution: if two targets have the same range they can still be resolved if they are traveling at different velocities. The velocity resolution is dependent on the number of chirps. As discussed for our case we selected to send 128 chirps. A higher number of chirps increases the velocity resolution, but it also takes longer to process the signal. 30 | % Angle Resolution: radar is capable of separating two targets spatially. If two targets are at similar range travelling at same velocities, then they can still be resolved based on their angle in radar coordinate system. Angle resolution depends on different parameters depending on the angle estimation technique used. We will cover this in more detail in the next lesson. 31 | 32 | 33 | %% RADAR SIMULATION 34 | 35 | %% Radar Specs 36 | % Frequency of operation: 77GHz (quite common in automotive applications) 37 | % Max range: 200m 38 | % Range resolution: 1m 39 | % Max velocity: 100m/s 40 | 41 | %% Target Position & Velocity 42 | % initial position/ range 43 | d0 = 80; 44 | % velocity (assumed constant) 45 | v0 = -50; 46 | 47 | %% FMCW Waveform Design 48 | 49 | d_res = 1; 50 | speed_of_light = 3*10^8; % 3e8 51 | RMax = 200; 52 | 53 | Bsweep = speed_of_light / (2 * d_res); % bandwidth 54 | Tchirp = 5.5 * 2 * RMax / speed_of_light; % chirp time 55 | alpha = Bsweep / Tchirp; % slope of FMCW chirps 56 | fc = 77e9; % carrier frequency of radar 57 | 58 | Nd = 128; % number of chirps in one sequence 59 | Nr = 1024; % number of samples on each chirp 60 | 61 | t = linspace(0, Nd * Tchirp, Nr * Nd); % total time for samples 62 | 63 | % vectors for Tx, Rx and Mix based on the total samples input 64 | Tx = zeros(1, length(t)); % transmitted signal 65 | Rx = zeros(1, length(t)); % received signal 66 | Mix = zeros(1, length(t)); % beat signal 67 | 68 | % vectors for range covered and time delay 69 | r_t = zeros(1, length(t)); 70 | td = zeros(1, length(t)); 71 | 72 | %% Signal generation and Moving Target simulation 73 | % Running the radar scenario over the time. 74 | 75 | for i = 1:length(t) 76 | % for each timestamp update the range of the target for constant velocity 77 | r_t(i) = d0 + v0 * t(i); 78 | td(i) = 2 * r_t(i) / speed_of_light; 79 | 80 | % for each time sample update the transmitted and received signal 81 | Tx(i) = cos(2 * pi * (fc * t(i) + alpha * t(i)^2 / 2)); 82 | Rx(i) = cos(2 * pi * (fc * (t(i) - td(i)) + (alpha * (t(i) - td(i))^2) / 2)); 83 | 84 | % now by mixing the transmit and receive generate the beat signal by performing 85 | % element-wise matrix multiplication of transmit and receiver signal 86 | Mix(i) = Tx(i) .* Rx(i); % beat signal 87 | end 88 | 89 | 90 | %% RANGE MEASUREMENT 91 | 92 | 93 | % reshaping vector into Nr*Nd array. Nr and Nd here also define the size of range and doppler FFT respectively 94 | 95 | % running the Fast Fourier Transform (FFT) on the beat signal along the range bins dimension (Nr) and normalise 96 | sig_fft = fft(Mix, Nr) ./ Nr; 97 | 98 | % taking absolute value of FFT output 99 | sig_fft = abs(sig_fft); 100 | 101 | % output of FFT is double-sided signal, but since we are interested in one side of the spectrum only, we throw out half of the samples 102 | sig_fft = sig_fft(1 : (Nr / 2)); 103 | 104 | figure('Name', 'Range from first FFT') % plot range 105 | plot(sig_fft); grid minor % plot FFT output 106 | axis([0 200 0 1]); 107 | xlabel('Measured range'); 108 | 109 | 110 | %% RANGE DOPPLER RESPONSE 111 | 112 | % Running a 2D FFT on the mixed signal (beat signal) output and generate a Range Doppler Map (RDM) 113 | 114 | % The output of the 2D FFT is an image that has reponse in the range and doppler FFT bins. 115 | % Therefore, it is important to convert the axis from bin sizes to range and doppler based on their max values 116 | 117 | Mix = reshape(Mix, [Nr, Nd]); 118 | 119 | % 2D FFT using the FFT size for both dimensions 120 | sig_fft2 = fft2(Mix, Nr, Nd); 121 | 122 | % taking just one side of signal from range dimension 123 | sig_fft2 = sig_fft2(1 : Nr / 2, 1 : Nd); 124 | sig_fft2 = fftshift(sig_fft2); 125 | RDM = abs(sig_fft2); 126 | RDM = 10*log10(RDM); 127 | 128 | % use surf function to plot output of 2D-FFT and show axis in both dimensions 129 | doppler_axis = linspace(-100, 100, Nd); 130 | range_axis = linspace(-200, 200, Nr/2) * ((Nr / 2) / 400); 131 | figure('Name', 'Range Doppler Map'), surf(doppler_axis, range_axis, RDM); 132 | 133 | 134 | %% CFAR Implementation 135 | 136 | % sliding window through the complete Range Doppler Map (RDM) 137 | 138 | % selecting number of training cells in both the dimensions 139 | Tcr = 10; 140 | Tcd = 4; 141 | 142 | % selecting number of guard cells in both dimensions around the Cell Under Test (CUT) for accurate estimation 143 | Gcr = 5; 144 | Gcd = 2; 145 | 146 | % offsetting the threshold by signal-to-noise-ratio (SNR) value in dB 147 | offset = 1.4; 148 | 149 | % creating vector to store noise level for each iteration on training cells 150 | noise_level = zeros(Nr / 2 - 2 * (Tcd + Gcd), Nd - 2 * (Tcr + Gcr)); 151 | gridSize = (2 * Tcr + 2 * Gcr + 1) * (2 * Tcd + 2 * Gcd + 1); 152 | trainingCellsNum = gridSize - (2 * Gcr + 1) * (2 * Gcd + 1); 153 | 154 | % designing loop - slide the CUT across range doppler map by giving margins 155 | % at the edges for training and guard cells. 156 | % For every iteration sum the signal level within all the training cells 157 | % To sum convert the value from logarithmic to linear using db2pow function 158 | % Average the summed values for all of the training cells used 159 | % After averaging, convert it back to logarithimic using pow2db 160 | % Add the offset to it to determine the threshold 161 | % Next, compare the signal under CUT with this threshold: 162 | % if the CUT level > threshold, assign it a value of 1, else equate it to 0 163 | 164 | CFAR_sig = zeros(size(RDM)); 165 | 166 | % Using RDM[x,y] as the matrix from the output of 2D FFT for implementing CFAR 167 | for j = 1 : Nd - 2 * (Tcr + Gcr) 168 | for i = 1 : Nr / 2 - 2 * (Tcd + Gcd) 169 | % to extract only the training cells, first get the sliding patch and, 170 | % after converting it to power from decibel, set to zero whatever isn't 171 | % in the position of training cells; 172 | % the zero submatrix will not contribute to the sum over the whole patch and, 173 | % by dividing for the number of training cells I will get the noise mean level 174 | 175 | trainingCellsPatch = db2pow(RDM( i : i + 2 * (Tcd + Gcd), j : j + 2 * (Gcr + Tcr))); 176 | trainingCellsPatch(Tcd + 1 : end - Tcd, Tcr + 1 : end - Tcr) = 0; 177 | 178 | noise_level(i,j) = pow2db(sum(sum(trainingCellsPatch))/trainingCellsNum); 179 | sigThresh = noise_level(i, j) * offset; 180 | if RDM(i + (Tcd + Gcd), j + (Tcd + Gcr)) > sigThresh 181 | CFAR_sig(i + (Tcd + Gcd), j + (Tcd + Gcr)) = 1; 182 | else 183 | CFAR_sig(i + (Tcd + Gcd), j + (Tcd + Gcr)) = 0; 184 | end 185 | end 186 | end 187 | 188 | % The process above will generate a thresholded block, which is smaller than the Range Doppler Map as the CUT cannot be located at the edges of matrix 189 | % Hence, few cells will not be thresholded. To keep the map size same set those values to 0 190 | 191 | % display CFAR output using the surf function 192 | figure('Name', 'CA-CFAR Filtered RDM'), surf(doppler_axis, range_axis, CFAR_sig); 193 | colorbar; 194 | --------------------------------------------------------------------------------