M= csvread('fff.csv'); %open csv
n= size(M,1); % num of lines
a0 = 0.0005;
a1 = 0.0003731;
a2 = 0.0005;
a3= 0.0005;

a4 = 1.0963;
a5 = 1.0958;
a6 = 1.09;
a7 = 1.0809;

b0 = -0.00004;
b1 = 0.000049;
b2 = 0.0001;
b3 = 0.00001;

 b4 = 65.881;
 b5 = 69.702;
 b6 = 65;
 b7 = 63.568;
 
% variables -> y
for i=1:n
    F1(i)=M(i,1);
    F2(i)=M(i,2);
    F3(i)=M(i,3);
    F4(i)=M(i,4);
    F5(i)=M(i,5);
    F6(i)=M(i,6);
    F7(i)=M(i,7);
    F8(i)=M(i,8);
    Time_send(i)= M(i,9);
    Time_receive(i)= M(i,10);
end

Time_send = (Time_send - Time_send(1))/1000000;


plot(Time_send,F1); hold on;
plot(Time_send,F2+500);
plot(Time_send,F3+1000);
plot(Time_send,F4+1500);
% time - > x
for j=1:n-1
    Time(1)=0;
Time(j+1)= Time_send(j+1) - Time_send(j);
end

Vout0 = F1 * (5.0 / 1023.0);
Vout1 = F2 * (5.0 / 1023.0);
Vout2 = F3 * (5.0 / 1023.0);
Vout3 = F4 * (5.0 / 1023.0);
  
for k=1:n
 Rfsr0(k) = (6000/Vout0(k))-1200;
 Rfsr1(k) = (6000/Vout1(k))- 1200;
Rfsr2(k) = (6000/Vout2(k))- 1200;
  Rfsr3(k)= (6000/Vout3(k))- 1200;
end

for h=1:n
 F0a(h) = ((1/Rfsr0(h)) - b0) *(4.44822162825/a0);
 F1a(h) = ((1/Rfsr1(h)) - b1) *(4.44822162825/a1);
F2a(h) = ((1/Rfsr2(h)) - b2) *(4.44822162825/a2);
 F3a(h) = ((1/Rfsr3(h)) - b3) *(4.44822162825/a3); 
end

F4a = ((F5-b4)/a4)/100;
 F5a = ((F6-b5)/a5)/100;
 F6a = ((F7-b6)/a6)/100;
 F7a = ((F8-b7)/a7)/100;
%graph

%%
%for u=1:n/5
 %   Ftt(u)=(F0a(u)+F0a(u+1)+F0a(u+2)+F0a(u+3)+F0a(u+4))/5;
%end
%Tteste = Time_send(1:3130)
%plot(Tteste,Ftt)
%%%

figure; hold on

 M1 = 'F1';
 M2 = 'F2';
 M3 = 'F3';
 M4= 'F4';
  M5 = 'F5';
 M6 = 'F6';
 M7 = 'F7';
 M8= 'F8';


a1= plot(Time_send,F0a); 
a2 =plot(Time_send,F1a+20); 
a3 =plot(Time_send,F2a+40);
a4 =plot(Time_send,F3a+80);


a5=plot(Time_send,F4a); 
a6=plot(Time_send,F5a+2);
a7=plot(Time_send,F6a+4);
a8=plot(Time_send,F7a+6);


legend([a1;a2;a3;a4;a5;a6;a7;a8], M1, M2, M3, M4, M5, M6, M7, M8)
fhmov=F4a*0.7071+F5a*0.7071-F6a*0.7071-F7a*0.7071;
fn=F0a+F1a+F2a+F3a;


for l=1:n
uy(l)=fhmov(l)/fn(l);
end

plot(Time_send,uy)