Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

126 строки
4.6KB

  1. package pipeline
  2. import (
  3. "sdr-wideband-suite/internal/classifier"
  4. "sdr-wideband-suite/internal/detector"
  5. )
  6. // Candidate is the coarse output of the surveillance detector.
  7. // It intentionally stays lightweight and cheap to produce.
  8. type Candidate struct {
  9. ID int64 `json:"id"`
  10. CenterHz float64 `json:"center_hz"`
  11. BandwidthHz float64 `json:"bandwidth_hz"`
  12. PeakDb float64 `json:"peak_db"`
  13. SNRDb float64 `json:"snr_db"`
  14. FirstBin int `json:"first_bin"`
  15. LastBin int `json:"last_bin"`
  16. NoiseDb float64 `json:"noise_db,omitempty"`
  17. Source string `json:"source,omitempty"`
  18. Hint string `json:"hint,omitempty"`
  19. Evidence []LevelEvidence `json:"evidence,omitempty"`
  20. EvidenceState *CandidateEvidenceState `json:"evidence_state,omitempty"`
  21. MonitorMatches []MonitorWindowMatch `json:"monitor_matches,omitempty"`
  22. }
  23. // LevelEvidence captures which analysis level produced a candidate.
  24. // This is intentionally lightweight for later multi-level fusion.
  25. type LevelEvidence struct {
  26. Level AnalysisLevel `json:"level"`
  27. Provenance string `json:"provenance,omitempty"`
  28. }
  29. // MonitorWindow describes a monitoring window to gate candidates.
  30. type MonitorWindow struct {
  31. Index int `json:"index,omitempty"`
  32. Label string `json:"label,omitempty"`
  33. StartHz float64 `json:"start_hz,omitempty"`
  34. EndHz float64 `json:"end_hz,omitempty"`
  35. CenterHz float64 `json:"center_hz,omitempty"`
  36. SpanHz float64 `json:"span_hz,omitempty"`
  37. Source string `json:"source,omitempty"`
  38. PriorityBias float64 `json:"priority_bias,omitempty"`
  39. }
  40. // MonitorWindowMatch captures how a candidate overlaps a monitor window.
  41. type MonitorWindowMatch struct {
  42. Index int `json:"index"`
  43. Label string `json:"label,omitempty"`
  44. Source string `json:"source,omitempty"`
  45. StartHz float64 `json:"start_hz,omitempty"`
  46. EndHz float64 `json:"end_hz,omitempty"`
  47. CenterHz float64 `json:"center_hz,omitempty"`
  48. SpanHz float64 `json:"span_hz,omitempty"`
  49. OverlapHz float64 `json:"overlap_hz,omitempty"`
  50. Coverage float64 `json:"coverage,omitempty"`
  51. DistanceHz float64 `json:"distance_hz,omitempty"`
  52. Bias float64 `json:"bias,omitempty"`
  53. }
  54. // MonitorWindowStats summarizes candidate attribution per monitor window.
  55. type MonitorWindowStats struct {
  56. Index int `json:"index"`
  57. Label string `json:"label,omitempty"`
  58. Source string `json:"source,omitempty"`
  59. StartHz float64 `json:"start_hz,omitempty"`
  60. EndHz float64 `json:"end_hz,omitempty"`
  61. CenterHz float64 `json:"center_hz,omitempty"`
  62. SpanHz float64 `json:"span_hz,omitempty"`
  63. PriorityBias float64 `json:"priority_bias,omitempty"`
  64. Candidates int `json:"candidates,omitempty"`
  65. Planned int `json:"planned,omitempty"`
  66. Dropped int `json:"dropped,omitempty"`
  67. }
  68. // RefinementWindow describes the local analysis span that refinement should use.
  69. type RefinementWindow struct {
  70. CenterHz float64 `json:"center_hz"`
  71. SpanHz float64 `json:"span_hz"`
  72. Source string `json:"source,omitempty"`
  73. }
  74. // Refinement contains higher-cost local analysis derived from a candidate.
  75. type Refinement struct {
  76. Candidate Candidate `json:"candidate"`
  77. Window RefinementWindow `json:"window"`
  78. Signal detector.Signal `json:"signal"`
  79. SnippetRate int `json:"snippet_rate"`
  80. Class *classifier.Classification `json:"class,omitempty"`
  81. Stage string `json:"stage,omitempty"`
  82. }
  83. func CandidatesFromSignals(signals []detector.Signal, source string) []Candidate {
  84. out := make([]Candidate, 0, len(signals))
  85. for _, s := range signals {
  86. hint := ""
  87. if s.Class != nil {
  88. hint = string(s.Class.ModType)
  89. }
  90. out = append(out, Candidate{
  91. ID: s.ID,
  92. CenterHz: s.CenterHz,
  93. BandwidthHz: s.BWHz,
  94. PeakDb: s.PeakDb,
  95. SNRDb: s.SNRDb,
  96. FirstBin: s.FirstBin,
  97. LastBin: s.LastBin,
  98. NoiseDb: s.NoiseDb,
  99. Source: source,
  100. Hint: hint,
  101. })
  102. }
  103. return out
  104. }
  105. func CandidatesFromSignalsWithLevel(signals []detector.Signal, source string, level AnalysisLevel) []Candidate {
  106. out := CandidatesFromSignals(signals, source)
  107. if level.Name == "" && level.FFTSize == 0 && level.SampleRate == 0 {
  108. return out
  109. }
  110. evidence := LevelEvidence{Level: level, Provenance: source}
  111. for i := range out {
  112. AddCandidateEvidence(&out[i], evidence)
  113. }
  114. return out
  115. }