%% Data from ultrasound sensors

close all; clear all; clc;


%% a3_objecto_80cm
close all; clear all; clc;
[time,s1,s2,s3] = textread('a3_objecto_80cm','%d %f %f %f','headerlines',1);

s1(s1==0)=NaN;
s2(s2==0)=NaN;
s3(s3==0)=NaN;
time=linspace(1, length(s1), length(s1));
windowSize = 10;

tmax=max(time);
%  s1=filter(ones(1,windowSize)/windowSize,1,s1);
%  s2=filter(ones(1,windowSize)/windowSize,1,s2);
%  s3=filter(ones(1,windowSize)/windowSize,1,s3);

x_min=0;
x_max=tmax;
y_min=0;
y_max=200;

subplot(1,3,1); plot(time, s1, 'b');
xlabel('Iterações');
ylabel('Distância (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('Obstaculo a 80 cm');
xlabel('Iterações');
ylabel('Distância (cm)');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('Iterações');
ylabel('Distância (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

min(s1)
min(s2)
min(s3)


%% a3_objecto_120cm
close all; clear all; clc;
[time,s1,s2,s3] = textread('a3_objecto_120cm','%d %f %f %f','headerlines',1);

s1(s1==0)=NaN;
s2(s2==0)=NaN;
s3(s3==0)=NaN;
time=linspace(1, length(s1), length(s1));
windowSize = 10;

tmax=max(time);
% s1=filter(ones(1,windowSize)/windowSize,1,s1);
% s2=filter(ones(1,windowSize)/windowSize,1,s2);
% s3=filter(ones(1,windowSize)/windowSize,1,s3);

x_min=0;
x_max=tmax;
y_min=0;
y_max=200;

subplot(1,3,1); plot(time, s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('a3_objecto_120cm');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

min(s1)
min(s2)
min(s3)

%% a3_objecto_200mm
close all; clear all; clc;
[time,s1,s2,s3] = textread('a3_objecto_200mm','%d %f %f %f','headerlines',1);

s1(s1==0)=NaN;
s2(s2==0)=NaN;
s3(s3==0)=NaN;
time=linspace(1, length(s1), length(s1));
windowSize = 10;

tmax=max(time);
% s1=filter(ones(1,windowSize)/windowSize,1,s1);
% s2=filter(ones(1,windowSize)/windowSize,1,s2);
% s3=filter(ones(1,windowSize)/windowSize,1,s3);

x_min=0;
x_max=tmax;
y_min=0;
y_max=300;

subplot(1,3,1); plot(time, s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('a3_objecto_200mm');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

min(s1)
min(s2)
min(s3)

%% a3_objecto_200mm_1
close all; clear all; clc;
[time,s1,s2,s3] = textread('a3_objecto_200mm_1','%d %f %f %f','headerlines',1);

s1(s1==0)=NaN;
s2(s2==0)=NaN;
s3(s3==0)=NaN;
time=linspace(1, length(s1), length(s1));
windowSize = 10;

tmax=max(time);
% s1=filter(ones(1,windowSize)/windowSize,1,s1);
% s2=filter(ones(1,windowSize)/windowSize,1,s2);
% s3=filter(ones(1,windowSize)/windowSize,1,s3);

x_min=0;
x_max=tmax;
y_min=0;
y_max=300;

subplot(1,3,1); plot(time, s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('a3_objecto_200mm_1');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

min(s1)
min(s2)
min(s3)