% File: E5_094.M

clear;

Ts = 1;
% tinc = The number of points every Ts seconds
tinc = 20;
dt = Ts/tinc;
t = 0:dt:16*Ts;
wc = 2*pi*5;
n = 4;

% Generating x(t), a staircase waveform that repeats every 4Ts seconds
x = zeros(length(t),1);
for (i = 1:1:n)
  for (j = 1:1:n)
    x = x + (2*i-5)*(u_step(t,(i-1)*Ts+(j-1)*4*Ts) - u_step(t,i*Ts+(j-1)*4*Ts));
  end;
end;
x(length(t)) = x(length(t)-1);
x = x(:);

% Generating y(t)
t1 = 0.24*t;
y = zeros(length(t),1);
for (i = 1:1:n);
  y = y + (2*i-5)*(u_step(t1,(i-1)*Ts) - u_step(t1,i*Ts));
end;

temp1 = cos(wc*t + pi/4);
temp2 = sin(wc*t + pi/4);
temp1 = temp1(:);
temp2 = temp2(:);

s = x.*temp1 - y.*temp2;

% Plotting x(t) versus y(t)
plot_pr(3);
axis([-4 4 -4 4]);
plot(x,y,'x');
xlabel('x(t)');
ylabel('y(t)');
axis;
pause;

% Plotting x(t) & y(t)
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)');




 



