Ciro Santilli OurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
Output:
sin(t)
fft
real 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
imag 0 -10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10
rfft
real 0 0 0 0 0 0 0 0 0 0 0
imag 0 -10 0 0 0 0 0 0 0 0 0

sin(t) + sin(4t)
fft
real 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
imag 0 -10 0 0 -10 0 0 0 0 0 0 0 0 0 0 0 10 0 0 10
rfft
real 0 0 0 0 0 0 0 0 0 0 0
imag 0 -10 0 0 -10 0 0 0 0 0 0
With our understanding of the discrete Fourier transform we see clearly that:
  • the signal is being decomposed into sinusoidal components
  • because we are doing the Discrete Fourier transform of a real signal, for the fft, so there is redundancy in the. We also understand that rfft simply cuts off and only keeps half of the coefficients
numpy/fft.py
#!/usr/bin/env python
import math
import numpy as np

def printi(X):
    # Round to int otherwise there is a lot of small numerical noise.
    print('real ' + ' '.join(str(int(np.real(x))) for x in X))
    print('imag ' + ' '.join(str(int(np.imag(x))) for x in X))

def analyze(x):
    # FFT
    X = np.fft.fft(x)
    print('fft')
    printi(X)

    # Real FFT
    Xr = np.fft.rfft(x)
    print('rfft')
    printi(Xr)

N = 20

print('sin(t)')
x = np.array([math.sin(i * 2 * math.pi / N) for i in range(N)])
analyze(x)
print()

print('sin(t) + sin(4t)')
x = np.array([math.sin(i * 2 * math.pi / N) + math.sin(i * 2 * math.pi * 4 / N) for i in range(N)])
analyze(x)
print()

Ancestors

  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