Fast Fourier transform: Difference between revisions

Content added Content deleted
(→‎Tcl: Added implementation)
m (→‎{{header|Tcl}}: Make it clearer what is produced)
Line 102: Line 102:
printwave wave
printwave wave
# Uses FFT if input length is power of 2, and a less efficient algorithm otherwise
# Uses FFT if input length is power of 2, and a less efficient algorithm otherwise
set fft [waveMagnitude [math::fourier::dft $wave]]
set fft [math::fourier::dft $wave]
# Convert to magnitudes for printing
printwave fft</lang>
set fft2 [waveMagnitude $fft]
printwave fft2</lang>
Output:
Output:
<pre>
<pre>
wave: 0.000 0.924 0.707 -0.383 -1.000 -0.383 0.707 0.924 0.000 -0.924 -0.707 0.383 1.000 0.383 -0.707 -0.924
wave: 0.000 0.924 0.707 -0.383 -1.000 -0.383 0.707 0.924 0.000 -0.924 -0.707 0.383 1.000 0.383 -0.707 -0.924
fft: 0.000 0.000 0.000 8.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 8.000 0.000 0.000
fft2: 0.000 0.000 0.000 8.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 8.000 0.000 0.000
</pre>
</pre>