pysim/dft.py

25 lines
468 B
Python
Raw Permalink Normal View History

2024-04-28 23:02:14 +02:00
import numpy as np
def DFT(x):
"""
Compute the Discrete Fourier Transform (DFT) of the input signal x.
Parameters:
x (array-like): Input signal
Returns:
X (array-like): DFT of the input signal
"""
N = len(x)
n = np.arange(N)
k = n.reshape((N, 1))
e = np.exp(-2j * np.pi * k * n / N)
X = np.dot(e, x)
return X
# Example usage:
x = np.array([0, 1, 2, 3])
X = DFT(x)
print("DFT of", x, ":", X)