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.

57 líneas
1.6KB

  1. package classifier
  2. type ClassifierMode string
  3. const (
  4. ModeRule ClassifierMode = "rule"
  5. ModeMath ClassifierMode = "math"
  6. ModeCombined ClassifierMode = "combined"
  7. )
  8. func Classify(input SignalInput, spectrum []float64, sampleRate int, fftSize int, iq []complex64, mode ClassifierMode) *Classification {
  9. if len(spectrum) == 0 || input.FirstBin < 0 || input.LastBin < 0 {
  10. return nil
  11. }
  12. feat := ExtractFeatures(input, spectrum, sampleRate, fftSize)
  13. // Use the wider of spectral BW3dB and detector's occupied BWHz for hard rules.
  14. // BW3dB measures only the 3dB peak width which can be much narrower than the
  15. // actual occupied bandwidth (e.g. FM broadcast has a peaked spectrum).
  16. hardBW := feat.BW3dB
  17. if input.BWHz > hardBW {
  18. hardBW = input.BWHz
  19. }
  20. if hard := TryHardRule(input.CenterHz, hardBW); hard != nil {
  21. hard.Features = feat
  22. hard.BW3dB = hardBW
  23. return hard
  24. }
  25. if len(iq) > 0 {
  26. envVar, zc, instStd, crest := ExtractTemporalFeatures(iq)
  27. feat.EnvVariance = envVar
  28. feat.ZeroCross = zc
  29. feat.InstFreqStd = instStd
  30. feat.CrestFactor = crest
  31. }
  32. var cls Classification
  33. switch mode {
  34. case ModeMath:
  35. if len(iq) > 0 {
  36. mf := ExtractMathFeatures(iq)
  37. cls = MathClassify(mf, feat.BW3dB, input.CenterHz, input.SNRDb)
  38. cls.Features = feat
  39. } else {
  40. cls = RuleClassify(feat, input.CenterHz, input.SNRDb)
  41. }
  42. case ModeCombined:
  43. if len(iq) > 0 {
  44. mf := ExtractMathFeatures(iq)
  45. cls = CombinedClassify(feat, mf, input.CenterHz, input.SNRDb)
  46. } else {
  47. cls = RuleClassify(feat, input.CenterHz, input.SNRDb)
  48. }
  49. default:
  50. cls = RuleClassify(feat, input.CenterHz, input.SNRDb)
  51. }
  52. return &cls
  53. }