24 lines
468 B
Python
24 lines
468 B
Python
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)
|
|
|