Fast Fourier transform: Difference between revisions

m
Line 75:
 
print fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])</lang>
 
'''Output:'''
<pre>[(4+0j), (1-2.4142135623730949j), 0j, (1-0.41421356237309492j), 0j, (0.99999999999999989+0.41421356237309492j), 0j, (0.99999999999999967+2.4142135623730949j)]</pre>
 
===Using module [http://numpy.scipy.org/ numpy].===
<lang python>>>> from numpy.fft import fft
>>> from numpy import array
>>> a = array((0.0, 0.924, 0.707, -0.383, -1.0, -0.383, 0.707, 0.924, 0.0, -0.924, -0.707, 0.383, 1.0, 0.383, -0.707, -0.924))
>>> print( ' '.join("%5.3f" % abs(f) for f in fft(a)) )
>>> fft(a)
0.000 0.001 0.000 8.001 0.000 0.001 0.000 0.001 0.000 0.001 0.000 0.001 0.000 8.001 0.000 0.001</lang>
array([ 0.00000000e+00 +0.00000000e+00j,
-7.77156117e-16 +1.28750059e-03j,
0.00000000e+00 +0.00000000e+00j,
-7.66053887e-15 -8.00062775e+00j,
0.00000000e+00 +0.00000000e+00j,
-8.88178420e-16 -1.23179335e-03j,
0.00000000e+00 +0.00000000e+00j,
2.33146835e-15 +6.83454981e-04j,
0.00000000e+00 +0.00000000e+00j,
-7.77156117e-16 -6.83454981e-04j,
0.00000000e+00 +0.00000000e+00j,
2.99760217e-15 +1.23179335e-03j,
0.00000000e+00 +0.00000000e+00j,
2.44249065e-15 +8.00062775e+00j,
0.00000000e+00 +0.00000000e+00j, 2.33146835e-15 -1.28750059e-03j])</lang>
 
=={{header|Tcl}}==
Anonymous user