Skip to content

Latest commit

 

History

History
224 lines (162 loc) · 6.77 KB

cfar-hls-python.md

File metadata and controls

224 lines (162 loc) · 6.77 KB

Ordered-Statistic CFAR mathematical modelling and HLS implementation

PhD, Senior R&D Engineer
Aleksei Rostov
Munich, 2022

Agenda


Theory

Constant False Alarm Rate or CFAR is used in radar signal processing for adaptive thresholding with predetermined constant probability of false alarm [1]. Radar detectors based on CFAR are implemented in many RADAR processing chains. The main idea of adaptive thresholding - is to detect targets in case of noise floor or Signal-To-Noise Ratio changing (Fig. 1.1).

butterfly

Figure 1.1 Simulation of constant and adaptive thresholding

The generic structure of CFAR detector is depicted on Fig. 1.2. There are two sliding windows with reference and guard (may be ommited) cells, the Cell-Under-Test between, processor with Linear or Nonlinear operation and multiplier with comparator. Adaptive Threshold for comparator depends on value Z (calculated by processor unit) and coefficient $\Alpha$ (determined by desired probability of false alarm).

butterfly

Figure 1.2 Generic structure of CFAR detector

The comparator compares Cell-Under-Test and Threshold after the processor unit. The processor unit can implement different algorithms for calculation Threshold. Here is considered only nonlinear Ordered-Statistic algorithms (OS CFAR). The principle of OS CFAR is very simple: all samples from the sliding windows are sorted in ascending order and then k-th sample (order statistic) is choosen for calculating Threshold. Thus OS-CFAR implementation is based on simple sorting algorithm and sliding window.

TODO add information about calculation parameters for CFAR (order, scaling coeficient)

Mathematical Modelling

Mathematical modelling of CFAR allows to figure out hardware design of the algorithm and proof outputs during HLS Co-Simulation. For mathematical modelling two Python scripts were created: cfar_generator.py and cfar_model.py. First script generates a synthetic input for HLS testbench and header parameters.h file for initialization of HLS CFAR implementation. The synthetic input is scaled to unsigned 16-bits value (from 0 to 65536) and consists of 2 peaks (targets) with several SNR zones (Fig. 1.1).

python3 cfar_generator.py --h

Input signal size and CFAR parameters

positional arguments:
  NPOINTS     Number of points
  REFWIND     Number of cells in CFAR window
  PFA         Probability of false alarm

python3 cfar_generator.py 1024 40 1e-2

what means - the synthetic signal consist of 1024 samples and CFAR parameters: window size is 32 and 28 sample is choosen as k-th for calculating Threshold. The script will generate several files:

cfarIn_float.txt
cfarIn_u16.txt
cfarPy_param.txt
parameters.h

cfarIn_float.txt and cfarIn_u16.txt files is float and unsigned 16-bits representation of input data.

The cfar_model.py consists of mathematical model of OS CFAR and test of the model by using data from cfar_generator.py. The model is implemented in cfar_1d(s, GrdHalf, RefHalf, T, k_th, Type) and sort_insertion(x) functions

View code
def cfar_1d(s, GrdHalf, RefHalf, T, k_th, Type):
    """CFAR for one-dimentional array.

    Args:
    s (numpy.ndarray)	: Input array.
            GrdHalf(int): Half of guard window.
            RefHalf(int): Half of reference window.
                T(float): Scaling factor for thresholding.
               k_th(int): cell for ordered-statistic
            Type(String): OS - ordered statistic
                          CA - cell-averaging
                          GO - greatest-of
                          SO - smallest-of

    Returns:
        s_cfar(numpy.ndarray): output array of thresholding.
        t_cfar(numpy.ndarray): output array of detection.
    """
    if s.ndim > 1:
        print('numpy.ndarray error')
        return -1
    N 			= np.size(s)
    s_cfar 		= np.empty(N)
    t_cfar 		= np.zeros(N)
    s_cfar[:] 	= np.nan 
    ref_win 	= np.zeros(2*RefHalf)
    
    for idx in range(GrdHalf+RefHalf, N-(GrdHalf+RefHalf)):
        ref_win[0:RefHalf] = s[idx-(GrdHalf + RefHalf):idx-GrdHalf]
        ref_win[RefHalf :] = s[idx+ GrdHalf + 1: idx + GrdHalf + RefHalf + 1]
        ref_win 	= sort_insertion(ref_win)
        Z 			= T*ref_win[k_th]
            
        s_cfar[idx + 0] = Z
        t_cfar[idx + 1] = comp_geb(Z, s[idx + 1])
    return s_cfar, t_cfar

The sort_insertion(x) function implements sorting algorithm by using Insertion sort algorithm [2] which is good for FPGA implementation by using network based on Systolic Array [3].

View code
def PE(din, staticVar, k):
    """
    Processing Element - part of systolic array
    @param uint32_t din: new input 
    @param uint32_t staticVar: array for static var
    @param uint32_t k: index
    @return dout uint32_t
    """   
    if din > staticVar[k]: # 
        dout = staticVar[k] # 
        staticVar[k] = din
    else:
        dout = din
    return dout


def sort_insertion(x):
    """
    Sorting network (insertion algorithm)
    @param uint32_t x: input array
    @return y uint32_t: output array
    """  
    # length of input array
    N = np.size(x)
    y = np.zeros(N)
    d = np.zeros(N)
    stVar = np.zeros(N)
    
    for k in range(2*N):
        if k < N:
            d[0] = PE(x[k], stVar, 0)
        else:
            d[0] = PE(MAX_VALUE, stVar, 0)

        for k_th in range(N-1):
            d[k_th + 1] = PE(d[k_th],   stVar, k_th + 1)

        if k > N - 1:
            y[k - N] = d[N-1]
            
    return y
	

OS CFAR model slides accross input data, sorts samples from sliding window, takes k-th sample and calculates Threshold based on predetermined meaning of constant probability of false alarm.

High Level Synthesis Implementation


References


  1. Mark A. Richards - Fundamentals of RADAR Signal Processing - 2005
  2. [Insertion sort Wiki] (https://en.wikipedia.org/wiki/Insertion_sort)
  3. [Systolic array Wiki] (https://en.wikipedia.org/wiki/Systolic_array)