Created
July 16, 2019 03:50
-
-
Save hallazzang/bc100b27c22753edddc1c0f03eed5d4e to your computer and use it in GitHub Desktop.
fourier transform playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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