Wideband autonomous SDR analysis engine forked from sdr-visual-suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
959B

  1. package demod
  2. import "math"
  3. type USB struct{}
  4. type LSB struct{}
  5. func (USB) Name() string { return "USB" }
  6. func (LSB) Name() string { return "LSB" }
  7. func (USB) OutputSampleRate() int { return 48000 }
  8. func (LSB) OutputSampleRate() int { return 48000 }
  9. func (USB) Demod(iq []complex64, sampleRate int) []float32 { return ssb(iq, sampleRate, true) }
  10. func (LSB) Demod(iq []complex64, sampleRate int) []float32 { return ssb(iq, sampleRate, false) }
  11. func ssb(iq []complex64, sampleRate int, usb bool) []float32 {
  12. if len(iq) == 0 {
  13. return nil
  14. }
  15. out := make([]float32, len(iq))
  16. bfo := 700.0
  17. if !usb {
  18. bfo = -700.0
  19. }
  20. phase := 0.0
  21. inc := 2 * math.Pi * bfo / float64(sampleRate)
  22. for i := 0; i < len(iq); i++ {
  23. phase += inc
  24. c := math.Cos(phase)
  25. s := math.Sin(phase)
  26. v := iq[i]
  27. // product detector
  28. out[i] = float32(float64(real(v))*c - float64(imag(v))*s)
  29. }
  30. return out
  31. }
  32. func init() {
  33. Register(USB{})
  34. Register(LSB{})
  35. }