I would like to find the frequency spectrum by drawing magnitude and phase for the following signal:



Is there something particular to this problem that I should be noticing?

We can easily find the spectra giving a time domain like


And using the fft command for both signals


What did they mean by drawing the magnitude and phase?

  • $\begingroup$ @lennon310 Please try to grab any spelling or grammar issues in the text as well. $\endgroup$
    – jonsca
    Jan 5, 2014 at 3:36
  • $\begingroup$ @jonsca Thank you Jonsca. Will pay more attention next time. $\endgroup$
    – lennon310
    Jan 5, 2014 at 3:38

2 Answers 2


for plotting magnitude spectrum versus frequency you can use the following script:

t = 0:0.001:0.2;
s = sin(2*pi*100*t)+cos(pi*500*t);
S = abs(fftshift(fft(s)));

Fs = 1000;
df = 1000/(length(s));
f = -Fs/2:df:Fs/2-df;


Here I used your first signal and plotted its magnitude spectrum. You must notice for your signal min choosable Nyquist frequency is 500 Hz But we use it two times of it(which is 1000Hz), because we also want to see the part before f =0 in the frequency spectrum. Using this we find df(delta f) frequency spacing. frequency vector must be multiples of df. By this way spectrum will be drawn correctly.

Here is the output:

enter image description here


For plotting the magnitude and phase using the above, but with the following (slight) modifications

plot(f,abs(S)); %Plot of magnitude  
plot(f,unwrap(angle(S))); %Plot of phase  

Note - unwrap() tries to take care of any 2*pi jumps in the phase.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.