%function test
global ind;
global s2;
s2 = serial('COM2', 'BaudRate', 9600,'databits',7, 'timeout',15);
fopen(s2);
x = 1;
while x==1;
ind = fread(s2,257);
x=0;
end;

if ind (256) == 0;
    ind (256) = 127;
end

ind (256) = ind (256) -1;
ind (257) = ind (257) -1;
a = ind (256) + ind (257) * 2; 
b = a*255;
time = (a:a:b)';
time = time / 1000;
data = (ind(1:255) -1) * 5;
plot (time,data);
axis([0,b/1000,0,600]);
xlabel('Time [s]');
ylabel('RPM');
title('Actual Data');
fclose (s2);
%hold
%X=2;
%while X<255
%   X = X+1;
%   data2 (X) = (data (X) + data (X-1) + data (X-2)) / 3;
%   data2 (X-1) = data2 (X);
%   data2 (X-2) = data2 (X);
%end
%plot (time,data2, 'r')
%X=5;

%while X<255;
%   X = X+1;
%   data3 (X) = (data2 (X) + data2 (X-1) + data2 (X-2) + data2 (X-3)+ data2 (X-4)+ data2 (X-5)) / 6;
%   data3 (X-1) = data3 (X);
%   data3 (X-2) = data3 (X);
%end
%   data3 (1) = data2 (1);
%   data3 (2) = data2 (2);
%   data3 (3) = data2 (3);
  
%plot (time,data3, 'g')
%hold
%fclose(s2)
%end