To convert a signal from the time domain to the frequency domain in Matlab, we can use the Fast Fourier Transform (FFT) function. Here's an example:
main.m445 chars18 lines
In this example, we first generated a time series signal y
consisting of two sine waves with frequencies 10 Hz and 20 Hz. We then computed the FFT of the signal using fft(y)
. This returns a vector Y
containing the complex values of the FFT coefficients.
To obtain the corresponding frequency vector, we first calculated the length L
of the signal and used it to create a vector f
from 0 to the Nyquist frequency (Fs/2
) with steps of Fs/L
. We then plotted the magnitude of the FFT to obtain the single-sided amplitude spectrum of the signal.
gistlibby LogSnag