Wideband autonomous SDR analysis engine forked from sdr-visual-suite
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.

65 líneas
1.6KB

  1. package gpudemod
  2. import "math"
  3. func runStreamingPolyphaseHostCore(
  4. iqNew []complex64,
  5. sampleRate int,
  6. offsetHz float64,
  7. stateNCOPhase float64,
  8. statePhaseCount int,
  9. stateNumTaps int,
  10. stateDecim int,
  11. stateHistory []complex64,
  12. polyphaseTaps []float32,
  13. ) ([]complex64, float64, int, []complex64) {
  14. out := make([]complex64, 0, len(iqNew)/maxInt(1, stateDecim)+2)
  15. phase := stateNCOPhase
  16. phaseCount := statePhaseCount
  17. hist := append([]complex64(nil), stateHistory...)
  18. phaseLen := PolyphasePhaseLen(len(polyphaseTaps)/maxInt(1, stateDecim)*maxInt(1, stateDecim), stateDecim)
  19. if phaseLen == 0 {
  20. phaseLen = PolyphasePhaseLen(len(polyphaseTaps), stateDecim)
  21. }
  22. phaseInc := -2.0 * math.Pi * offsetHz / float64(sampleRate)
  23. for _, x := range iqNew {
  24. rot := complex64(complex(math.Cos(phase), math.Sin(phase)))
  25. s := x * rot
  26. hist = append(hist, s)
  27. phaseCount++
  28. if phaseCount == stateDecim {
  29. var y complex64
  30. for p := 0; p < stateDecim; p++ {
  31. for k := 0; k < phaseLen; k++ {
  32. idxTap := p*phaseLen + k
  33. if idxTap >= len(polyphaseTaps) {
  34. continue
  35. }
  36. tap := polyphaseTaps[idxTap]
  37. if tap == 0 {
  38. continue
  39. }
  40. srcBack := p + k*stateDecim
  41. idx := len(hist) - 1 - srcBack
  42. if idx < 0 {
  43. continue
  44. }
  45. y += complex(tap, 0) * hist[idx]
  46. }
  47. }
  48. out = append(out, y)
  49. phaseCount = 0
  50. }
  51. if len(hist) > stateNumTaps-1 {
  52. hist = hist[len(hist)-(stateNumTaps-1):]
  53. }
  54. phase += phaseInc
  55. if phase >= math.Pi {
  56. phase -= 2 * math.Pi
  57. } else if phase < -math.Pi {
  58. phase += 2 * math.Pi
  59. }
  60. }
  61. return out, phase, phaseCount, append([]complex64(nil), hist...)
  62. }