DeaD_EyE

CFAR

Mar 23rd, 2018
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def apply(func):
  2.     def inner(data, **kwargs):
  3.         Z = func(data, **kwargs)
  4.         result = []
  5.         for element in data:
  6.             if abs(element) > abs(Z):
  7.                 result.append(element)
  8.             else:
  9.                 result.append(0.0)
  10.         return result
  11.     return inner
  12.  
  13.  
  14. @apply
  15. def cfar(data, N=3):
  16.     return 1 / N * len(data) * sum(data)
  17.  
  18.  
  19. @apply
  20. def cago_cfar(data, N=3):
  21.     return max(_cfar(data, N))
  22.  
  23.  
  24. @apply
  25. def caso_cfar(data, N=3):
  26.     return min(_cfar(data, N))
  27.  
  28.  
  29. @apply
  30. def caos_cfar(data, percent):
  31.     N = int(len(data) / 100 * percent)
  32.     return sum(sorted(data)[:N]) / (N or 1)
  33.  
  34.  
  35. def _cfar(data, N):
  36.     n = len(data) * N
  37.     res1 = (2/n) * sum(data[:n//2])
  38.     res2 = (2/n) * sum(data[(n//2)+1:])
  39.     return res1, res2
RAW Paste Data