Ciro Santilli OurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
Generates numpy/fft_plot.svg, the plot of with 25 points and its DFT.
The output was also uploaded to: commons.wikimedia.org/wiki/File:DFT_2sin(t)_%2B_sin(4t).svg and added to en.wikipedia.org/w/index.php?title=Discrete_Fourier_transform&oldid=1176616763 only to be later removed of course: Deletionism on Wikipedia.
Figure 3.
DFT of with 25 points
. Source code at: numpy/fft_plot.py.
numpy/fft_plot.py
#!/usr/bin/env python
# Python 3.12.3, Ubuntu 24.04.

import math

import matplotlib.pyplot as plt
import numpy as np

N = 25
x = np.array([2 * math.sin(i * 2 * math.pi / N) + math.cos(i * 2 * math.pi * 4 / N) for i in range(N)])
X = np.fft.fft(x)

fig, axs = plt.subplots(3, 1)
fig.suptitle('X = DFT(x)')
fig.tight_layout(rect=[0, 0.03, 1, 0.94])

ax = axs[0]
ax.set_title('x(t) = 2 sin(2 $\\pi$ t / 25) + cos(8 $\\pi$ t / 25)')
#ax.set_title('x(t) = 2 sin(t) + sin(4t) = $-25 e^{1 \\times 2\\pi i t/25} -12.5 e^{4 \\times 2\\pi i t/25} + 12.5 e^{21 \\times 2\\pi i t/25} + -25 e^{24 \\times 2\\pi i t/25}$')
ax.plot(np.arange(0., N, 1.), x, '.')
ax.axis([-0.5, N, -3.5, 3.5])
ax.set_yticks([-3, 0, 3], minor=False)
ax.grid()

ax = axs[1]
ax.set_title('Re(X(t))')
ax.plot(np.arange(0., N, 1.), np.real(X), '.')
ax.axis([-0.5, N, -30, 30])
ax.set_yticks([-25.0, -12.5, 0.0, 12.5, 25.0], minor=False)
ax.grid()

ax = axs[2]
ax.set_title('Im(X(t))')
ax.plot(np.arange(0., N, 1.), np.imag(X), '.')
ax.axis([-0.5, N, -30, 30])
ax.set_yticks([-25, -12.5, 0.0, 12.5, 25], minor=False)
ax.grid()

plt.savefig(
    'fft_plot.svg',
    format='svg',
    dpi=1000/plt.gcf().get_size_inches()[1],
    bbox_inches='tight',
)

Ancestors (13)

  1. Numpy.fft
  2. NumPy
  3. Python scientific library
  4. Python library
  5. Python
  6. List of programming languages
  7. Programming language
  8. Software
  9. Computer
  10. Information technology
  11. Area of technology
  12. Technology
  13. Ciro Santilli's Homepage