Skip to content

Commit 45b18a8

Browse files
authored
Update fourier_transform.py
1 parent a608910 commit 45b18a8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

maths/transforms/fourier_transform.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import numpy as np
21
from typing import List, Union
2+
import numpy as np
33

4-
def fourier_transform(signal: List[Union[int, float]]) -> List[complex]:
4+
def fourier_transform(signal: list[int | float]) -> list[complex]:
55
"""
66
Compute the discrete Fourier transform (DFT) of a signal.
77
88
Args:
9-
signal (List[Union[int, float]]): A list of numerical values representing the input signal.
9+
signal (list[int | float]): A list of numerical values representing the input signal.
1010
1111
Returns:
12-
List[complex]: The Fourier transform of the input signal as a list of complex numbers.
12+
list[complex]: The Fourier transform of the input signal as a list of complex numbers.
1313
1414
Example:
15-
>>> fourier_transform([1, 2, 3, 4])
16-
[(10+0j), (-2+2j), (-2+0j), (-2-2j)]
15+
>>> fourier_transform([1, 2, 3, 4])
16+
[(10+0j), (-2+2j), (-2+0j), (-2-2j)]
1717
1818
Note:
19-
This is a basic implementation of the DFT and can be optimized using FFT for larger datasets.
19+
This is a basic implementation of the DFT and can be optimized using FFT for larger datasets.
2020
"""
2121
n = len(signal)
2222
result = []
23-
for k in range(n):
24-
summation = 0 + 0j
25-
for t in range(n):
23+
for k in range(n):
24+
summation = 0 + 0j
25+
for t in range(n):
2626
angle = -2j * np.pi * t * k / n
2727
summation += signal[t] * np.exp(angle)
2828
result.append(summation)

0 commit comments

Comments
 (0)