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

66 行
1.4KB

  1. package mock
  2. import (
  3. "math"
  4. "math/rand"
  5. "sync"
  6. "time"
  7. "sdr-visual-suite/internal/sdr"
  8. )
  9. type Source struct {
  10. mu sync.Mutex
  11. phase float64
  12. phase2 float64
  13. phase3 float64
  14. sampleRate float64
  15. noise float64
  16. }
  17. func New(sampleRate int) *Source {
  18. rand.Seed(time.Now().UnixNano())
  19. return &Source{
  20. sampleRate: float64(sampleRate),
  21. noise: 0.02,
  22. }
  23. }
  24. func (s *Source) Start() error { return nil }
  25. func (s *Source) Stop() error { return nil }
  26. func (s *Source) UpdateConfig(sampleRate int, centerHz float64, gainDb float64, agc bool, bwKHz int) error {
  27. s.mu.Lock()
  28. defer s.mu.Unlock()
  29. if sampleRate > 0 {
  30. s.sampleRate = float64(sampleRate)
  31. }
  32. return nil
  33. }
  34. func (s *Source) ReadIQ(n int) ([]complex64, error) {
  35. s.mu.Lock()
  36. defer s.mu.Unlock()
  37. out := make([]complex64, n)
  38. f1 := 50e3
  39. f2 := -120e3
  40. f3 := 300e3
  41. for i := 0; i < n; i++ {
  42. s.phase += 2 * math.Pi * f1 / s.sampleRate
  43. s.phase2 += 2 * math.Pi * f2 / s.sampleRate
  44. s.phase3 += 2 * math.Pi * f3 / s.sampleRate
  45. re := math.Cos(s.phase) + 0.7*math.Cos(s.phase2) + 0.4*math.Cos(s.phase3)
  46. im := math.Sin(s.phase) + 0.7*math.Sin(s.phase2) + 0.4*math.Sin(s.phase3)
  47. re += s.noise * rand.NormFloat64()
  48. im += s.noise * rand.NormFloat64()
  49. out[i] = complex(float32(re), float32(im))
  50. }
  51. return out, nil
  52. }
  53. func (s *Source) Stats() sdr.SourceStats {
  54. return sdr.SourceStats{}
  55. }
  56. func (s *Source) Flush() {}