%% Data from ultrasound sensors

close all; clear all; clc;


%% No filter 46cm

[time,s1,s2,s3] = textread('no_filter_46cm','%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=100;

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('No filter - object at 46cm');
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]);

%% No filter 94cm

[time,s1,s2,s3] = textread('no_filter_94cm','%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=150;

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('No filter - object at 94cm');
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]);

%% No filter 176cm

[time,s1,s2,s3] = textread('no_filter_176cm','%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');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('No filter - object at 176cm');
xlabel('time');
ylabel('distance');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('time');
ylabel('distance');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

%% No filter 120cm_salt_grain

[time,s1,s2,s3] = textread('no_filter_120cm_salt_grain','%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');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('No filter - object at 120cm');
xlabel('time');
ylabel('distance');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('time');
ylabel('distance');
legend('Sensor3')
axis([x_min x_max y_min y_max]);

%% No filter 120cm_salt_grain

[time,s1,s2,s3] = textread('no_filter_movement','%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');
legend('Sensor1')
axis([x_min x_max y_min y_max]);
subplot(1,3,2); plot(time, s2, 'r');
TITLE('No filter - object moving');
xlabel('time');
ylabel('distance');
legend('Sensor2')
axis([x_min x_max y_min y_max]);
subplot(1,3,3); plot(time, s3, 'g');
xlabel('time');
ylabel('distance');
legend('Sensor3')
axis([x_min x_max y_min y_max]);