%% Data from ultrasound sensors

close all; clear all; clc;


%% Passagem 12cm

[time,s1,s2,s3] = textread('2_esq&dir_passagem_12cm','%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=600;

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('2 - Passagem 12cm');
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]);

%% 2 - Passagem 5cm

[time,s1,s2,s3] = textread('2_esq&dir_passagem_5cm','%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=600;

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('2 - Passagem 5cm');
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]);

%% 2- Cantos 6cm

[time,s1,s2,s3] = textread('2_esq&dir_cantos_6cm','%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=600;

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('2- Cantos 6cm');
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]);
%%