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.

24 lines
641B

  1. package dsp
  2. import "math"
  3. // FreqShift mixes IQ by -offsetHz to shift signal to baseband.
  4. func FreqShift(iq []complex64, sampleRate int, offsetHz float64) []complex64 {
  5. if len(iq) == 0 || sampleRate <= 0 || offsetHz == 0 {
  6. out := make([]complex64, len(iq))
  7. copy(out, iq)
  8. return out
  9. }
  10. out := make([]complex64, len(iq))
  11. phase := 0.0
  12. inc := -2 * math.Pi * offsetHz / float64(sampleRate)
  13. for i := 0; i < len(iq); i++ {
  14. phase += inc
  15. re := math.Cos(phase)
  16. im := math.Sin(phase)
  17. v := iq[i]
  18. out[i] = complex(float32(float64(real(v))*re-float64(imag(v))*im), float32(float64(real(v))*im+float64(imag(v))*re))
  19. }
  20. return out
  21. }