Wideband autonomous SDR analysis engine forked from sdr-visual-suite
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

48 satır
824B

  1. package gpudemod
  2. import "math/cmplx"
  3. type CompareStats struct {
  4. MaxAbsErr float64
  5. RMSErr float64
  6. Count int
  7. }
  8. func CompareComplexSlices(a []complex64, b []complex64) CompareStats {
  9. n := len(a)
  10. if len(b) < n {
  11. n = len(b)
  12. }
  13. if n == 0 {
  14. return CompareStats{}
  15. }
  16. var sumSq float64
  17. var maxAbs float64
  18. for i := 0; i < n; i++ {
  19. err := cmplx.Abs(complex128(a[i] - b[i]))
  20. if err > maxAbs {
  21. maxAbs = err
  22. }
  23. sumSq += err * err
  24. }
  25. return CompareStats{
  26. MaxAbsErr: maxAbs,
  27. RMSErr: mathSqrt(sumSq / float64(n)),
  28. Count: n,
  29. }
  30. }
  31. func mathSqrt(v float64) float64 {
  32. // tiny shim to keep the compare helper self-contained and easy to move
  33. // without importing additional logic elsewhere
  34. z := v
  35. if z <= 0 {
  36. return 0
  37. }
  38. x := z
  39. for i := 0; i < 12; i++ {
  40. x = 0.5 * (x + z/x)
  41. }
  42. return x
  43. }