% File: E2_178.M

clear;

% Calculate the FFT for a truncated step
% Let tend be the end of the step. 

M = 8;
N = 2^M;
n = 0:1:N-1;
tend = 1;
T = 10;
dt = T/N;
t = n*dt;

w = zeros(length(t),1);
for (i = 1:1:length(w))
  if (t(i) <= tend)
    w(i) = 1;
  end;
end;

% Calculating FFT
W = dt*fft(w);
f = n/T;


subplot(211);
plot(t,w);
xlabel('t');
ylabel('w(t)');
title('Time Waveform');

subplot(212);
plot(f(1:N/2),abs(W(1:N/2)));
xlabel('f');
title('MAGNITUDE SPECTRUM to fs/2');
subplot(111);



