# Amplitude and phase spectrum in MATLAB

I have a little problem with the subject Theory of signal. We were told to make amplitude and phase spectrum of cosinus in MATLAB, but we don't have results nor materials from our teachers, so we have to study from many different materials and you can imagine what this is like. So I'm a little confused.

However, I did some graphs, that should be what I want, according to instructions, but I have never seen something like that, so I'm not sure, if that's right.

Do these graphs make any sense to you? I used fast Fourier transform (fft(y) in MATLAB) on the signal and then plot the result of transform versus sample frequency and I thought it's possible to get phase of the signal by angle(fft(y)), so I plotted this on the last graph.

I would like to apologize for incorrect notions I might use, 'cause I'm not a native english speaker.

Thanks for any help.

• Your time-domain signal looks like 10Hz and this matches the 2nd graph indicating the spectrum does contain 10Hz but it also indicates 90Hz and this makes me think you are using a sampling speed of 100Hz to analyze the original signal. This will produce the 90Hz content in the spectrum dude to aliasing. Other than that I think you may have achieved what is asked of you. The last graph doesn't really tell me anything but maybe someone can interpret it. – Andy aka Mar 18 '13 at 11:36

This probably fits dsp.stackexchange.com better.

This is the most simple FT that you should understand. The basic rule is: a sine of frequency f0 in time domain is a delta at f0 and -f0 in frequency. You can do this theoretically, as shown in http://mathworld.wolfram.com/FourierTransformCosine.html.

Those peaks in your graph are consistent with this. However, it isn't true that there is a peak in at 90Hz. The peaks should be at 10 Hz and -10 Hz. There are two possible approaches here:

a) Use fftshift to correct this issue. This will take each frequency to its real place.

Fs=100; %sampling frequency
T=1; %signal length
N=T*Fs;     %number of samples
f=-Fs/2:Fs/N:Fs/2-Fs/N; %frequency vector
x=cos(2*pi*10*t);
Xf=fft(x);
Xf=fftshift(Xf);
plot(f,abs(Xf)) %magnitude


b) Assume the signal is real, so the spectrum is symmetric. It is true in this case, but it doesn't have to. You could just plot the first half of your fft, i.e. from 0 Hz to 50 Hz.