% File: E3_003.M

clear;

% Spectrum of Naturally Sampled PAM.
% Assume analog waveform has a rectangular spectrum with
% bandwidth B

B = 5;
fs = 15;
f = -10:1:100;

W = zeros(length(f),1);
W = pulse(W,f,-B,B);

n = 0:1:6;
% d is the sample pulse width divided by the sampling period.
d = 0.26;
x = pi*n*d;
a = Sa(x);

% Generating spectrum of Natural Pulse PAM signal.
Ws = zeros(length(f),1);

% Generating Shifted versions of W due to sampling.
for (i = 1:1:length(n))
  Wtemp = zeros(length(f),1);
  for (j = n(i)*fs+1:1:length(W))
    Wtemp(j) = W(j - n(i)*fs);
  end;
  Ws = Ws + d*a(i)*Wtemp;
end;

subplot(211);
plot(f,abs(W));
xlabel('f');
ylabel('Magnitude of W(f)');
title('MAGNITUDE SPECTRUM of analog signal');

subplot(212);
plot(f,abs(Ws));
xlabel('f');
ylabel('Magnitude of Ws(f)');
title('MAGNITUDE SPECTRUM of NATURAL SAMPLED PAM signal');
subplot(111);




     



