Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

29 lines
680B

  1. package dsp
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func TestGoertzelDetectsTone(t *testing.T) {
  7. fs := 228000.0
  8. n := 22800 // 100ms
  9. freq := 19000.0
  10. samples := make([]float64, n)
  11. for i := range samples {
  12. samples[i] = math.Sin(2 * math.Pi * freq * float64(i) / fs)
  13. }
  14. energy := GoertzelEnergy(samples, fs, freq)
  15. noiseEnergy := GoertzelEnergy(samples, fs, 5000)
  16. if energy < noiseEnergy*100 {
  17. t.Fatalf("expected strong energy at %.0f Hz: got %.4f vs noise %.4f", freq, energy, noiseEnergy)
  18. }
  19. }
  20. func TestGoertzelSilence(t *testing.T) {
  21. samples := make([]float64, 1000)
  22. if GoertzelEnergy(samples, 228000, 19000) > 1e-12 {
  23. t.Fatal("expected near-zero energy for silence")
  24. }
  25. }