To obtain the Fourier coefficients of a discrete signal in Python, one can use the numpy.fft.fft
function. Here's a simple example:
main.py288 chars14 lines
In this example, we first define a discrete signal y
that consists of 100 samples of a sine wave. We then compute the Fourier coefficients of this signal using the numpy.fft.fft
function. Finally, we plot the magnitude of the Fourier coefficients using matplotlib.pyplot.plot
.
Note that the output of numpy.fft.fft
is an array of complex numbers. The magnitude of each complex number corresponds to the amplitude of the corresponding Fourier coefficient, while the argument (angle) corresponds to the phase shift.
gistlibby LogSnag