Jump to content

Discrete Fourier transform: Difference between revisions

m
2d added
m (comments)
m (2d added)
Line 39:
 
=={{header|Julia}}==
The cispi function was added in Julia 1.6. The cispi of x is e to the power of (pi times i times x). Other syntax, such as {T,N} in the function signature and real() and tuplentuple() in the loop, is designed to support arbitrary dimensional arrays and to cue the compiler so as to have mostly constants in the loop at runtime, speeding run time with large arrays.
<lang julia>function dft(A::AbstractArray{T,N}) where {T,N}
F = zeros(complex(float(T)), size(A)...)
Line 58:
end
 
const seq = [2, 3, 5, 7, 11]
const fseq = dft(seq)
newseq = idft(fseq)
println("$seq =>\n$fseq =>\n$newseq =>\n", Int.(round.(newseq)))
 
seq2 = [2 7; 3 11; 5 13]
const fseq = dft(seq)
fseq = dft(seq2)
 
const newseq = idft(fseq)
println("$seq2 =>\n$fseq =>\n$newseq =>\n", Int.(round.(newseq)))
 
println("$seq =>\n$fseq =>\n$newseq =>\n", Int.(round.(newseq)))
</lang>{{out}}
<pre>
Line 71 ⟶ 73:
ComplexF64[2.0000000000000013 - 1.4210854715202005e-15im, 2.999999999999996 + 7.993605777301127e-16im, 5.000000000000002 + 2.1316282072803005e-15im, 6.999999999999998 - 8.881784197001252e-16im, 11.0 + 0.0im] =>
[2, 3, 5, 7, 11]
[2 7; 3 11; 5 13] =>
ComplexF64[41.0 + 0.0im -21.0 + 0.0im; -7.000000000000002 + 3.46410161513775im 3.0000000000000053 + 7.105427357601002e-15im; -6.9999999999999964 - 3.4641016151377606im 3.0000000000000053 + 7.105427357601002e-15im] =>
ComplexF64[2.000000000000002 + 5.921189464667501e-16im 6.999999999999997 - 4.144832625267251e-15im; 2.9999999999999996 - 8.881784197001252e-16im 11.000000000000002 + 1.0362081563168128e-15im; 4.999999999999999 + 0.0im 13.000000000000002 + 1.924386576016938e-15im] =>
[2 7; 3 11; 5 13]
</pre>
 
4,108

edits

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