No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

74 líneas
2.2KB

  1. package cfar
  2. import "testing"
  3. func makeSpectrum(n int, noiseDb float64, signals [][2]int, sigDb float64) []float64 {
  4. s := make([]float64, n)
  5. for i := range s {
  6. s[i] = noiseDb
  7. }
  8. for _, sig := range signals {
  9. for i := sig[0]; i <= sig[1] && i < n; i++ {
  10. s[i] = sigDb
  11. }
  12. }
  13. return s
  14. }
  15. func TestAllVariantsDetectSignal(t *testing.T) {
  16. spec := makeSpectrum(1024, -100, [][2]int{{500, 510}}, -20)
  17. for _, mode := range []Mode{ModeCA, ModeOS, ModeGOSCA, ModeCASO} {
  18. c := New(Config{Mode: mode, GuardCells: 2, TrainCells: 16, Rank: 24, ScaleDb: 6, WrapAround: true})
  19. if c == nil {
  20. t.Fatalf("%s: nil", mode)
  21. }
  22. th := c.Thresholds(spec)
  23. if len(th) != 1024 {
  24. t.Fatalf("%s: len=%d", mode, len(th))
  25. }
  26. if spec[505] < th[505] {
  27. t.Fatalf("%s: signal not above threshold", mode)
  28. }
  29. if spec[200] >= th[200] {
  30. t.Fatalf("%s: noise above threshold", mode)
  31. }
  32. }
  33. }
  34. func TestWrapAroundEdges(t *testing.T) {
  35. spec := makeSpectrum(256, -100, [][2]int{{0, 5}}, -20)
  36. c := New(Config{Mode: ModeCA, GuardCells: 2, TrainCells: 8, ScaleDb: 6, WrapAround: true})
  37. th := c.Thresholds(spec)
  38. if th[0] <= -200 || th[0] > 0 {
  39. t.Fatalf("edge threshold bad: %v", th[0])
  40. }
  41. if th[255] <= -200 || th[255] > 0 {
  42. t.Fatalf("wrap threshold bad: %v", th[255])
  43. }
  44. }
  45. func TestGOSCAMaskingProtection(t *testing.T) {
  46. spec := makeSpectrum(1024, -100, [][2]int{{500, 510}, {530, 540}}, -20)
  47. cGosca := New(Config{Mode: ModeGOSCA, GuardCells: 2, TrainCells: 16, ScaleDb: 6, WrapAround: true})
  48. cCA := New(Config{Mode: ModeCA, GuardCells: 2, TrainCells: 16, ScaleDb: 6, WrapAround: true})
  49. thG := cGosca.Thresholds(spec)
  50. thC := cCA.Thresholds(spec)
  51. midBin := 520
  52. if thG[midBin] < thC[midBin] {
  53. t.Logf("GOSCA=%f CA=%f at bin %d — GOSCA correctly higher", thG[midBin], thC[midBin], midBin)
  54. }
  55. }
  56. func BenchmarkCFAR(b *testing.B) {
  57. spec := makeSpectrum(2048, -100, [][2]int{{500, 510}, {1000, 1020}}, -20)
  58. for _, mode := range []Mode{ModeCA, ModeOS, ModeGOSCA, ModeCASO} {
  59. cfg := Config{Mode: mode, GuardCells: 2, TrainCells: 16, Rank: 24, ScaleDb: 6, WrapAround: true}
  60. c := New(cfg)
  61. b.Run(string(mode), func(b *testing.B) {
  62. for i := 0; i < b.N; i++ {
  63. c.Thresholds(spec)
  64. }
  65. })
  66. }
  67. }