% Read data
X = TEXTREAD('x.txt');
Y = TEXTREAD('y.txt');
Z = TEXTREAD('z.txt');

% Output
close all;
plot(0:length(X)-1, X, 0:length(Y)-1, Y, 0:length(Z)-1, Z);
title ('Output');
legend('X','Y','Z');
grid;

W= 2*pi/100;
phi = 0;

xd = -cos(phi+W*(0:length(X)-1))';
yd = -sin(phi+W*(0:length(Y)-1))';

VarErrorX = var(X-xd)
VarErrorY = var(Y-yd)
MeanErrorX = mean(X-xd)
MeanErrorY = mean(Y-yd)

figure;
plot(0:length(X)-1, X-xd, 0:length(Y)-1, Y-yd, 0:length(Z)-1, Z);
title ('Error');
legend('X - X_D','Y - Y_D', 'Z');
grid;

figure;
plot(0:length(X)-1, X, 0:length(Y)-1, Y, 0:length(Z)-1, xd, 0:length(yd)-1, yd);
title ('Output');
legend('X','Y','X_D','Y_D');
grid;
