Skip to content

Instantly share code, notes, and snippets.

@con-mo8
Created July 28, 2016 14:35
Show Gist options
  • Save con-mo8/edf749f106dfe14a7a1bc0b23a30f50c to your computer and use it in GitHub Desktop.
Save con-mo8/edf749f106dfe14a7a1bc0b23a30f50c to your computer and use it in GitHub Desktop.
Discrete Fourier Transform in Perl 6 using complex case
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