{"id":16162443,"url":"https://github.com/sunsided/sfnd_radar_2d_cfar","last_synced_at":"2025-03-18T22:31:08.126Z","repository":{"id":47121825,"uuid":"264017386","full_name":"sunsided/SFND_Radar_2D_CFAR","owner":"sunsided","description":"Radar Target Generation and Detection using 2D CA-CFAR","archived":false,"fork":false,"pushed_at":"2020-05-15T00:18:17.000Z","size":1285,"stargazers_count":37,"open_issues_count":0,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T00:09:26.621Z","etag":null,"topics":["cfar-processing","matlab","nanodegree","radar","sensor-fusion","udacity","udacity-nanodegree","udacity-sensor-fusion-nanodegree"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunsided.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-14T20:24:09.000Z","updated_at":"2025-03-09T06:01:54.000Z","dependencies_parsed_at":"2022-08-12T13:11:45.071Z","dependency_job_id":null,"html_url":"https://github.com/sunsided/SFND_Radar_2D_CFAR","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2FSFND_Radar_2D_CFAR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2FSFND_Radar_2D_CFAR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2FSFND_Radar_2D_CFAR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2FSFND_Radar_2D_CFAR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunsided","download_url":"https://codeload.github.com/sunsided/SFND_Radar_2D_CFAR/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244318531,"owners_count":20433929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cfar-processing","matlab","nanodegree","radar","sensor-fusion","udacity","udacity-nanodegree","udacity-sensor-fusion-nanodegree"],"created_at":"2024-10-10T02:30:09.172Z","updated_at":"2025-03-18T22:31:07.786Z","avatar_url":"https://github.com/sunsided.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Radar Target Generation and Detection (2D CA-CFAR)\n\nThis project implements 2D [CA-CFAR](https://en.wikipedia.org/wiki/Constant_false_alarm_rate)\n(Cell-Averaging Constant False Alarm Rate) to detect target measurements against\na noisy background for a frequency modulated continuous-wave (FMCW) radar.\n\nThe following picture shows a FMCW measurement of a target at 100 m distance\nwith a velocity of 37 m/s. The left plot shows the noisy measurement obtained\nfrom the frequency mixer, whereas the right plot shows the CA-CFAR filtered\nRadar response.\n\n![](.readme/ca-cfar.png)\n\n---\n\n## Project Overview\n\n![](.readme/image11.png)\n\n\u003e - Configure the FMCW waveform based on the system requirements.\n\u003e - Define the range and velocity of target and simulate its displacement.\n\u003e - For the same simulation loop process the transmit and receive signal to determine the beat signal\n\u003e - Perform Range FFT on the received signal to determine the Range\n\u003e - Towards the end, perform the CFAR processing on the output of 2nd FFT to display the target.\n\n\u003cdetails\u003e\n\n### Radar System Requirements\n\n\u003e The sensor fusion design for different\n\u003e driving scenarios requires different system configurations from a Radar. In this project,\n\u003e you will designing a Radar based on the given system requirements:\n\u003e\n\u003e ![](.readme/image14.png)\n\u003e\n\u003e Max Range and Range Resolution will be considered here for waveform design.\n\u003e - The sweep bandwidth can be determined according to the range resolution and the sweep\n\u003e   slope is calculated using both sweep bandwidth and sweep time.\n\u003e   ```\n\u003e   Bandwidth(B_sweep) = speed of light / (2*rangeResolution)\n\u003e   ```\n\u003e - The sweep time can be computed based on the time needed for the signal to travel the\n\u003e   unambiguous maximum range. In general, for an FMCW radar system, the sweep time should\n\u003e   be at least 5 to 6 times the round trip time. This example uses a factor of 5.5.\n\u003e   ```\n\u003e   T_chirp = 5.5 * 2 * R_max / c\n\u003e   ```\n\u003e   Giving the slope of the chirp signal\n\u003e   ```\n\u003e   Slope=Bandwidth/T_chirp\n\u003e   ```\n\u003e\n\u003e #### Initial Range and velocity of the Target\n\u003e\n\u003e You will provide the initial range and velocity of the target.\n\u003e Range cannot exceed the max value of 200m and velocity can be\n\u003e any value in the range of -70 to + 70 m/s.\n\n### Target Generation and Detection\n\n\u003e Next, you will be simulating the signal propagation and moving target scenario.\n\u003e\n\u003e ![](.readme/image.png)\n\u003e\n\u003e #### Theory\n\u003e\n\u003e In terms of wave equation, FMCW transmit and received signals are defined using\n\u003e these wave equations, where `α = Slope of the signal`.\n\u003e The Transmit Signal is given by:\n\u003e\n\u003e ![](.readme/transmit-signal.png)\n\u003e\n\u003e The received signal is nothing but the time delayed version of the Transmit Signal.\n\u003e In digital signal processing the time delayed version is defined by (t−τ),\n\u003e where τ represents the delay time, which in radar processing is the trip time for the signal.\n\u003e Replacing t with (t−τ) gives the Receive Signal:\n\u003e\n\u003e ![](.readme/receive-signal.png)\n\u003e\n\u003e On mixing these two signals, we get the beat signal, which holds the values for both\n\u003e range as well as doppler. By implementing the 2D FFT on this beat signal,\n\u003e we can extract both Range and Doppler information.\n\u003e\n\u003e The beat signal can be calculated by multiplying the Transmit signal with Receive signal.\n\u003e This process in turn works as frequency subtraction. It is implemented by element by element\n\u003e multiplication of transmit and receive signal matrices.\n\u003e ```\n\u003e Mixed or Beat Signal = Tx .* Rx\n\u003e ```\n\u003e The above operation gives:\n\u003e\n\u003e ![](.readme/mixed-or-beat-signal.png)\n\n### FFT Operation\n\n\u003e - Implement the 1D FFT on the Mixed Signal\n\u003e - Reshape the vector into Nr*Nd array.\n\u003e - Run the FFT on the beat signal along the range bins dimension (Nr)\n\u003e - Normalize the FFT output.\n\u003e - Take the absolute value of that output.\n\u003e - Keep one half of the signal\n\u003e - Plot the output\n\u003e - There should be a peak at the initial position of the target\n\u003e\n\u003e ![](.readme/image10.png)\n\u003e\n\u003e The 2nd FFT is already implemented in the code.\n\u003e It will generate a Range Doppler Map as seen in the image below and it will be given by\n\u003e variable `RDM`. Next task is to implement the CFAR on this Range Doppler Map.\n\u003e\n\u003e ![](.readme/image12.jpg)\n\n### 2D CFAR\n\n\u003e - Determine the number of Training cells for each dimension. Similarly, pick the number of guard cells.\n\u003e - Slide the cell under test across the complete matrix. Make sure the CUT has margin for Training and Guard cells from the edges.\n\u003e - For every iteration sum the signal level within all the training cells. To sum convert the value from logarithmic to linear using db2pow function.\n\u003e - Average the summed values for all of the training cells used. After averaging convert it back to logarithmic using pow2db.\n\u003e - Further add the offset to it to determine the threshold.\n\u003e - Next, compare the signal under CUT against this threshold.\n\u003e - If the CUT level \u003e threshold assign it a value of 1, else equate it to 0.\n\nThe process above will generate a thresholded block, which is smaller than the Range Doppler Map as the CUTs cannot be located at the edges of the matrix due to the presence of Target and Guard cells. Hence, those cells will not be thresholded.\n\n\u003e - To keep the map size same as it was before CFAR, equate all the non-thresholded cells to 0.\n\u003e\n\u003e ![](.readme/image13.png)\n\u003e\n\u003e Once you have completed this, you are done.\n\n## Project Rubric\n\n### FMCW Waveform Design\n\n- **Criteria:** Using the given system requirements, design\na FMCW waveform. Find its Bandwidth (B), chirp time (Tchirp) and slope of the chirp.\n\n  **Meets Specification:** For given system requirements the calculated slope should be around 2e13\n\n### Simulation Loop\n\n- **Criteria:** Simulate Target movement and calculate the beat or mixed signal for every timestamp.\n\n  **Meets Specifications:** A beat signal should be generated such that once range FFT implemented, it gives the correct range i.e the initial position of target assigned with an error margin of +/- 10 meters.\n\n### Range FFT (1st FFT)\n\n- **Criteria:** Implement the Range FFT on the Beat or Mixed Signal and plot the result.\n\n  **Meets Specifications:** A correct implementation should generate a peak at the correct range, i.e the initial position of target assigned with an error margin of +/- 10 meters.\n\n### 2D CFAR\n\n- **Criteria:** Implement the 2D CFAR process on the output of 2D FFT operation, i.e the Range Doppler Map.\n\n  **Meets Specifications:** The 2D CFAR processing should be able to suppress the noise and separate the target signal. The output should match the image shared in walkthrough.\n\n- **Criteria:** Create a CFAR README file.\n\n  **Meets Specifications:** In a README file, write brief explanations for the following:\n  - Implementation steps for the 2D CFAR process.\n  - Selection of Training, Guard cells and offset.\n  - Steps taken to suppress the non-thresholded cells at the edges.\n\n---\n\n\u003c/details\u003e\n\n## Project Implementation\n\nGiven the specifications above and a sweep-to-roundtrip factor of 5.5 (given in the lectures\nas a typical value for an FMCW radar system), the following values were determined:\n\n- **Sweep bandwidth:** 150 MHz\n- **Chirp time:** 7.33 μs (7.3333e-06 s)\n- **Frequency drift / slope:** 20.45 THz/s (2.045e13 Hz/s)\n\nFor the following simulation, a target was defined with the following parameters:\n\n- **Distance:** 100 m\n- **Velocity:** 37 m/s\n\nAfter simulating the beat signal was been for every time step, the Fourier transformation of it\nwas taken in order to determine the distance to target. This resulted in a peak at\n\n- **Estimated distance:** 101 m\n\nNext, CA-CFAR was implemented as a march over each range/doppler cell (the cell-under-test, CUT),\ntaking the integral of the training cells around it. The scan was limited to the extents of the\nCFAR signal storage array and normalization was done by the number of valid cells examined.\nDue to this procedure and since the CFAR signal array was initialized to zero, no edge suppression\nwas required. If a signal were to be received in these edge areas however, we would have to expect\nslightly degraded results since a lower number of training cells is involved.\n\nIn the next step, the mean noise level of the sampled cells was determined, converted from\npower to dB scale and compared against a threshold. Cells below threshold were suppressed, whereas\ncell values equal to or above threshold were kept. Note that this differs from the project description\nin that no further normalization is done here (specifically, good values are not simply set to one).\nUsing the CFAR array as a multiplicative mask would be certainly possible with the approach\ndescribed in the project, but the end result would be the same.\n\nInitially, the following setup was used by arbitrarily picking values from the lessons as defaults\nand determining a threshold by fair dice roll:\n\n- **Distance training cells:** 8\n- **Distance guard cells:** 4\n- **Doppler training cells:** 8\n- **Doppler training cells:** 4\n- **Threshold:** 4 dB\n\nThis resulted in the following outcome:\n\n![](.readme/ca-cfar-too-low.png)\n\nAs can be seen, the correct spike was kept, but is very wide along the velocity\naxis; in addition, a couple of false positives were kept as well.\n\nSince the estimate along the range axis was very sharp and spot on, the\nnumber of doppler training cells was increased to suppress velocity errors better.\nIn addition, the threshold was increased to 8 dB, such that\n\n- **Distance training cells:** 8\n- **Distance guard cells:** 4\n- **Doppler training cells:** 8\n- **Doppler training cells:** 8\n- **Threshold:** 8 dB\n\nThe result - as already shown in the very beginning of this README - is this plot.\nAs can be seen, the spike at 100 m and 37 m / s is reasonably sharp, although the\nprecision along the doppler / velocity axis could be better:\n\n![](.readme/ca-cfar.png)\n\nHere's the same scenario in a top view:\n\n![](.readme/ca-cfar-top.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fsfnd_radar_2d_cfar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunsided%2Fsfnd_radar_2d_cfar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fsfnd_radar_2d_cfar/lists"}