Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

82 linhas
2.3KB

  1. package classifier
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func makeToneIQ(n int, freqNorm float64, am float64) []complex64 {
  7. iq := make([]complex64, n)
  8. for i := range iq {
  9. phase := 2 * math.Pi * freqNorm * float64(i)
  10. env := 1.0 + am*math.Sin(2*math.Pi*0.01*float64(i))
  11. iq[i] = complex(float32(env*math.Cos(phase)), float32(env*math.Sin(phase)))
  12. }
  13. return iq
  14. }
  15. func TestMathClassifyAM(t *testing.T) {
  16. iq := makeToneIQ(4096, 0.1, 0.8)
  17. mf := ExtractMathFeatures(iq)
  18. if mf.AMIndex < 1.5 {
  19. t.Errorf("AM signal should have high AMIndex: got %.2f", mf.AMIndex)
  20. }
  21. cls := MathClassify(mf, 8000, 121.5e6, 25)
  22. if cls.ModType != ClassAM {
  23. t.Errorf("expected AM, got %s (scores: %v)", cls.ModType, cls.Scores)
  24. }
  25. }
  26. func TestMathClassifyFM(t *testing.T) {
  27. n := 4096
  28. iq := make([]complex64, n)
  29. phase := 0.0
  30. for i := range iq {
  31. freqDev := 0.3 * math.Sin(2*math.Pi*0.005*float64(i))
  32. phase += 2 * math.Pi * (0.1 + freqDev)
  33. iq[i] = complex(float32(math.Cos(phase)), float32(math.Sin(phase)))
  34. }
  35. mf := ExtractMathFeatures(iq)
  36. if mf.FMIndex < 2.0 {
  37. t.Errorf("FM signal should have high FMIndex: got %.2f", mf.FMIndex)
  38. }
  39. if mf.EnvCoV > 0.1 {
  40. t.Errorf("FM signal should have low EnvCoV: got %.3f", mf.EnvCoV)
  41. }
  42. cls := MathClassify(mf, 12000, 145.5e6, 25)
  43. if cls.ModType != ClassNFM {
  44. t.Errorf("expected NFM, got %s (scores: %v)", cls.ModType, cls.Scores)
  45. }
  46. }
  47. func TestMathClassifyCW(t *testing.T) {
  48. n := 4096
  49. iq := make([]complex64, n)
  50. for i := range iq {
  51. phase := 2 * math.Pi * 0.05 * float64(i)
  52. iq[i] = complex(float32(math.Cos(phase)), float32(math.Sin(phase)))
  53. }
  54. mf := ExtractMathFeatures(iq)
  55. cls := MathClassify(mf, 100, 7.02e6, 20)
  56. if cls.ModType != ClassCW {
  57. t.Errorf("expected CW, got %s (scores: %v, kurtosis: %.1f)", cls.ModType, cls.Scores, mf.EnvKurtosis)
  58. }
  59. }
  60. func TestCombinedClassify(t *testing.T) {
  61. n := 4096
  62. iq := make([]complex64, n)
  63. phase := 0.0
  64. for i := range iq {
  65. freqDev := 0.2 * math.Sin(2*math.Pi*0.003*float64(i))
  66. phase += 2 * math.Pi * (0.1 + freqDev)
  67. iq[i] = complex(float32(math.Cos(phase)), float32(math.Sin(phase)))
  68. }
  69. feat := Features{BW3dB: 12000, SpectralFlat: 0.3, PeakToAvg: 1.5, EnvVariance: 0.01, InstFreqStd: 0.8}
  70. mf := ExtractMathFeatures(iq)
  71. cls := CombinedClassify(feat, mf, 145.5e6, 25)
  72. if cls.ModType != ClassNFM {
  73. t.Errorf("expected NFM, got %s (scores: %v)", cls.ModType, cls.Scores)
  74. }
  75. }