File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+ from typing import List , Union
3
+
4
+ def fourier_transform (signal : List [Union [int , float ]]) -> List [complex ]:
5
+ """
6
+ Compute the discrete Fourier transform (DFT) of a signal.
7
+
8
+ Args:
9
+ signal (List[Union[int, float]]): A list of numerical values representing the input signal.
10
+
11
+ Returns:
12
+ List[complex]: The Fourier transform of the input signal as a list of complex numbers.
13
+
14
+ Example:
15
+ >>> fourier_transform([1, 2, 3, 4])
16
+ [(10+0j), (-2+2j), (-2+0j), (-2-2j)]
17
+
18
+ Note:
19
+ This is a basic implementation of the DFT and can be optimized using FFT for larger datasets.
20
+ """
21
+ n = len (signal )
22
+ result = []
23
+ for k in range (n ):
24
+ summation = 0 + 0j
25
+ for t in range (n ):
26
+ angle = - 2j * np .pi * t * k / n
27
+ summation += signal [t ] * np .exp (angle )
28
+ result .append (summation )
29
+ return result
30
+
31
+ if __name__ == "__main__" :
32
+ sample_signal = [1 , 2 , 3 , 4 ]
33
+ result = fourier_transform (sample_signal )
34
+ print ("Fourier Transform of the signal:" , result )
You can’t perform that action at this time.
0 commit comments