01.05.2017 Views

563489578934

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

102<br />

Signals and Spectra Chap. 2<br />

TABLE 2–3 MATLAB LISTING FOR CALCULATING THE SPECTRUM OF A RECTANGULAR<br />

PULSE, USING THE FFT<br />

File: Example2_20.m for Example 2–20<br />

clear;<br />

% Using the DFT, calculate the spectrum for a rectangular pulse.<br />

% Let tend be the end of the step.<br />

M = 7;<br />

N = 2^M;<br />

n = 0:1:N-1;<br />

tend = 1;<br />

T = 10;<br />

dt = T/N;<br />

t = n*dt;<br />

% Creating time waveform<br />

w = zeros(length(t),1);<br />

for (i = 1:1:length(w))<br />

if (t(i) < = tend)<br />

w(i) = 1;<br />

end;<br />

end;<br />

% Calculating FFT<br />

W = dt*fft(w);<br />

f = n/T;<br />

% Calculating position of 4th NULL<br />

pos = INDEX(f,4/tend);<br />

subplot(411)<br />

plot(t,w);<br />

axis([0 T 0 1.5]);<br />

xlabel('t (sec) —>');<br />

ylabel('w(t)');<br />

title('Time Waveform');<br />

subplot(412);<br />

plot(f(1:pos),abs(W(1:pos)));<br />

xlabel('f (Hz) —>');<br />

ylabel('W(f)');<br />

titl--e('Magnitude Spectrum out to 4th Null');<br />

subplot(413);<br />

plot(f(1:pos),180/pi*angle(W(1:pos)));<br />

xlabel('f (Hz) —>');<br />

ylabel('theta(f) (degrees)');<br />

title('Phase Spectrum out to 4th Null');<br />

grid;<br />

subplot(414);<br />

plot(f,abs(W));<br />

xlabel('f (Hz) —>');<br />

ylabel('W(f)');<br />

title('Magnitude Spectrum over whole FFT frequency range');

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!