Created
July 28, 2016 14:35
-
-
Save con-mo8/edf749f106dfe14a7a1bc0b23a30f50c to your computer and use it in GitHub Desktop.
Discrete Fourier Transform in Perl 6 using complex case
This file contains 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
sub discrete-fourier-transform(Complex @input) returns Array[Complex] is export { | |
my Int $n = @input.elems; | |
my Complex @output = 0i xx $n; | |
for ^$n -> $k { | |
my Complex $s = 0i; | |
for ^$n -> $t { | |
$s += @input[$t] * exp(-2i * pi * $t * $k / $n); | |
} | |
@output[$k] = $s; | |
} | |
return @output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment