File tree 1 file changed +10
-10
lines changed
1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change 1
- import numpy as np
2
1
from typing import List , Union
2
+ import numpy as np
3
3
4
- def fourier_transform (signal : List [ Union [ int , float ]] ) -> List [complex ]:
4
+ def fourier_transform (signal : list [ int | float ]) -> list [complex ]:
5
5
"""
6
6
Compute the discrete Fourier transform (DFT) of a signal.
7
7
8
8
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.
10
10
11
11
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.
13
13
14
14
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)]
17
17
18
18
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.
20
20
"""
21
21
n = len (signal )
22
22
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 ):
26
26
angle = - 2j * np .pi * t * k / n
27
27
summation += signal [t ] * np .exp (angle )
28
28
result .append (summation )
You can’t perform that action at this time.
0 commit comments