% File: E5_112.M

clear;

% Use data shown in Fig. 5-34 and compute Type II MSK results.
                             
d = [1 -1 1 -1 -1 1 1 -1 1 -1];
Ac = 1;
fc = 3;
Tb = 1;
wc = 2*pi*fc;

dt = 1/(5*fc);
t = 0:dt:10*Tb;
nx = 2:2:10;
ny = 1:2:9;

% Generating x(t)
x = zeros(length(t),1);
for (i = 1:1:length(nx))
  temp = Ac * d(nx(i)) * cos(pi*(t - nx(i)*Tb)/2*Tb);
  temp = temp(:);
  x = x + temp .* (u_step(t,-Tb+nx(i)*Tb) - u_step(t,Tb+nx(i)*Tb));
end;

% Generating y(t)
y = zeros(length(t),1);
for (i = 1:1:length(ny))
  temp = Ac * d(ny(i)) * sin(pi*(t + Tb - ny(i)*Tb)/2*Tb);
  temp = temp(:);
  y = y + temp .* (u_step(t,-Tb+ny(i)*Tb) - u_step(t,Tb+ny(i)*Tb));
end;

% Generating s(t)
temp = cos(wc*t);
temp1 = sin(wc*t);
temp = temp(:);
temp1 = temp1(:);
s = x.*temp - y.*temp1;

% Generating Plots
plot_pr(2);
subplot(211);
plot(t,x);
xlabel('t');
ylabel('x(t)');

subplot(212);
plot(t,y);
xlabel('t');
ylabel('y(t)');
pause;

subplot(111);
plot(t,s);
xlabel('t');
ylabel('s(t)');






