Skip to content

Instantly share code, notes, and snippets.

@hallazzang
Created July 16, 2019 03:50
Show Gist options
  • Save hallazzang/bc100b27c22753edddc1c0f03eed5d4e to your computer and use it in GitHub Desktop.
Save hallazzang/bc100b27c22753edddc1c0f03eed5d4e to your computer and use it in GitHub Desktop.
fourier transform playground
package main
import (
"fmt"
"math"
"math/cmplx"
)
func comp(v int) complex128 {
return complex(float64(v), 0)
}
func dft(x []complex128) []complex128 {
N := len(x)
X := make([]complex128, N)
for k := 0; k < N; k++ {
X[k] = complex128(0)
for n := 0; n < N; n++ {
X[k] += x[n] * cmplx.Exp(-complex(0, 2*math.Pi)/comp(N)*comp(k)*comp(n))
}
}
return X
}
func main() {
fmt.Println(dft([]complex128{1i, 2i, 3i}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment