Consider that we have a discrete signal of finite length. How can we find the amplitude and phase corresponding to different harmonics of this signal in Matlab?
As Florent told: you must take fourier transform from your signal, by
fft, then you will get your spectrum in normalized frequency, actual frequency is correspond to your sampling rate, then you can see amplitude and phase of each frequency(or harmonic) by these command:
For example, assume
x is signal and
T is time interval between your samples and
x=[10 -10 10 -10 10 -10 -10 10 10 -10 -10] X=fft(x);%you can set frequency resolution by setting fft(x,resolution) Fs=1000; f=linspace(1,Fs,length(X)); plot(f,angle(X)) figure plot(f,abs(X))
The Fourier transform of a periodic signal is the discretisation of the Fourier transform of one of the signal's period. In other words, the only difference between the Fourier transform of a finite signal and its periodic version is that the former is continuous whereas the latter is discrete (Fourier series). To speak in mathematical terms, periodisation of a signal is equivalent to convolution with a Dirac train, which in the frequency domain results in the multiplication by a Dirac train, i.e. discretisation. Here is an explicative link
However, if your signal is not finite length but you're just analysing one finite portion of it (which is called windowing of the signal), this is equivalent to multiplying your time signal by a window function. In the frequency domain, it is like convolution with a sinc function (granted that your window is a rectangle window). More about this here.
So the bottom line is: if your fft window is big enough to analyse your whole signal, then the fft coefficients are a direct image of your harmonics. If you fft window truncates the signal however, you loose information and there is no way of knowing the original signal's real harmonics.
Note : I'm on my phone now so I can't illustrate with math equations but I'll edit later