The Fourier principle states that any signal can be represented as a sum of sine and cosine waves of different frequencies. In Matlab, we can use the "fft" (fast Fourier transform) function to transform a signal from the time domain to the frequency domain. Here is an example code:
main.m534 chars22 lines
This code creates a signal composed of a 50 Hz sine wave and a 120 Hz sine wave, computes the Fourier transform using "fft", and then plots the magnitude of the spectrum up to the Nyquist frequency. This code can be modified for other signals by changing the values of the frequency and amplitude of the sine waves in the signal.
gistlibby LogSnag