Jump to content

Fast Fourier transform: Difference between revisions

no edit summary
No edit summary
Line 4,419:
0.000e+00+0.000e+00j,
1.000e+00+2.414e+00j>)</pre>
 
=={{header|Vlang}}==
{{trans|Go}}
<lang vlang>import math.complex
import math
fn ditfft2(x []f64, mut y []Complex, n int, s int) {
if n == 1 {
y[0] = complex(x[0], 0)
return
}
ditfft2(x, mut y, n/2, 2*s)
ditfft2(x[s..], mut y[n/2..], n/2, 2*s)
for k := 0; k < n/2; k++ {
tf := cmplx.Rect(1, -2*math.pi*f64(k)/f64(n)) * y[k+n/2]
y[k], y[k+n/2] = y[k]+tf, y[k]-tf
}
}
fn main() {
x := [f64(1), 1, 1, 1, 0, 0, 0, 0]
mut y := []Complex{len: x.len}
ditfft2(x, mut y, x.len, 1)
for c in y {
println("${c:8.4f}")
}
}</lang>
 
{{out}}
<pre>
i d
2 3.21851142
3 4.38567760
4 4.60094928
5 4.65513050
6 4.66611195
7 4.66854858
8 4.66906066
9 4.66917155
10 4.66919515
11 4.66920026
12 4.66920098
13 4.66920537
</pre>
 
=={{header|Wren}}==
338

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.