Wideband autonomous SDR analysis engine forked from sdr-visual-suite
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

82 行
2.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. }
  21. // LevelEvidence captures which analysis level produced a candidate.
  22. // This is intentionally lightweight for later multi-level fusion.
  23. type LevelEvidence struct {
  24. Level AnalysisLevel `json:"level"`
  25. Provenance string `json:"provenance,omitempty"`
  26. }
  27. // RefinementWindow describes the local analysis span that refinement should use.
  28. type RefinementWindow struct {
  29. CenterHz float64 `json:"center_hz"`
  30. SpanHz float64 `json:"span_hz"`
  31. Source string `json:"source,omitempty"`
  32. }
  33. // Refinement contains higher-cost local analysis derived from a candidate.
  34. type Refinement struct {
  35. Candidate Candidate `json:"candidate"`
  36. Window RefinementWindow `json:"window"`
  37. Signal detector.Signal `json:"signal"`
  38. SnippetRate int `json:"snippet_rate"`
  39. Class *classifier.Classification `json:"class,omitempty"`
  40. Stage string `json:"stage,omitempty"`
  41. }
  42. func CandidatesFromSignals(signals []detector.Signal, source string) []Candidate {
  43. out := make([]Candidate, 0, len(signals))
  44. for _, s := range signals {
  45. hint := ""
  46. if s.Class != nil {
  47. hint = string(s.Class.ModType)
  48. }
  49. out = append(out, Candidate{
  50. ID: s.ID,
  51. CenterHz: s.CenterHz,
  52. BandwidthHz: s.BWHz,
  53. PeakDb: s.PeakDb,
  54. SNRDb: s.SNRDb,
  55. FirstBin: s.FirstBin,
  56. LastBin: s.LastBin,
  57. NoiseDb: s.NoiseDb,
  58. Source: source,
  59. Hint: hint,
  60. })
  61. }
  62. return out
  63. }
  64. func CandidatesFromSignalsWithLevel(signals []detector.Signal, source string, level AnalysisLevel) []Candidate {
  65. out := CandidatesFromSignals(signals, source)
  66. if level.Name == "" && level.FFTSize == 0 && level.SampleRate == 0 {
  67. return out
  68. }
  69. evidence := LevelEvidence{Level: level, Provenance: source}
  70. for i := range out {
  71. out[i].Evidence = append(out[i].Evidence, evidence)
  72. }
  73. return out
  74. }