%% Data from ultrasound sensors

close all; clear all; clc;


%% Filtro media - 5 elementos

[time,dist_s1,dist_s2,dist_s3,dist_filt_s1,dist_filt_s2,dist_filt_s3] = textread('rcdu_test1_2runs','%d %f %f %f %f %f %f','headerlines',1);

time=linspace(1, length(dist_s1), length(dist_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=10;

subplot(1,3,1); plot(time, dist_s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, dist_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, dist_s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

figure(2)
subplot(1,3,1); plot(time, dist_filt_s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, dist_filt_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, dist_filt_s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

%% Filtro media - 5 elementos

[time,dist_s1,dist_s2,dist_s3,dist_filt_s1,dist_filt_s2,dist_filt_s3] = textread('rcdu_test2_2runs','%d %f %f %f %f %f %f','headerlines',1);

time=linspace(1, length(dist_s1), length(dist_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=10;

subplot(1,3,1); plot(time, dist_s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, dist_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, dist_s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

figure(2)
subplot(1,3,1); plot(time, dist_filt_s1, 'b');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, dist_filt_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, dist_filt_s3, 'g');
xlabel('time');
ylabel('distance (cm)');
legend('Sensor3')
axis([x_min x_max y_min y_max]);
%%