% File: E3_065.M

clear;

% Let the data be given by
data = [1 0 0 1 0 1 1 0 1 0];
% Let he be the impulse response of an RC low-pass filter
% (see Fig. 2-15) where the 3dB bandwidth is B

B = 0.25;
tauo = 1/(2*pi*B);
% tinc must be power of 10;
tinc = 0.1;
Ts = 1/tinc;
t = 0:tinc:10;

he = zeros(length(t),1);
for (i = 1:1:length(t))
  he(i) = 1/tauo*exp(-t(i)/tauo);
end;

% Generating the filter output signal.
wo = zeros(length(t),1);

for (i = 1:1:length(data))
  Wtemp = zeros(length(t),1);
  if (data(i) == 1)
    for (j = (i-1)*Ts+1:1:length(he))
      Wtemp(j) = he(j - (i-1)*Ts);
    end;
    wo = wo + Wtemp;
  end;
end;


subplot(211);
plot(t,he);
xlabel('t');
ylabel('he(t)');
title('Filter Impulse Response');
 
subplot(212);
plot(t,wo);
xlabel('t');
ylabel('wo(t)');
title('Filter Output Signal');
subplot(111); 




     



