3
$\begingroup$

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

S=sin(2*pi*100*t)+cos(pi*500*t);

X=sinc(2*pi*t);

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

We can easily find the spectra giving a time domain like

t=0:0.01:0.1;

And using the fft command for both signals

X=fft(S);

What did they mean by drawing the magnitude and phase?

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

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;

plot(f,S);

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

$\endgroup$
0
$\begingroup$

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

S=fftshift(fft(s))  
figure  
plot(f,abs(S)); %Plot of magnitude  
figure   
plot(f,unwrap(angle(S))); %Plot of phase  

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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