% function data_pacient = convert(a,b,c,d)
close all, clear all, clc
load('AnalogData.mat');load('Events.mat');load('FPdata.mat');load('Markers.mat');
% data_pacient=cell(12,2);


Lkrok_c=[20,125];                % krokový cyklus levá noha
Rkrok_c=[70,170];                % krokový cyklus pravá noha
%% Kinematika
% LHipAngles, RHipAngles; x-Hip Flexion/Extension,y-Hip Ab/Adduction,z-Hip Rotation
% LKneeAngles, RKneeAngles; x-Knee Flexion/Extension,y-Knee Ab/Adduction,z-Knee Rotation
% LAnkleAngles, RAnkleAngles; x-Ankle Dorsi/Plantar,y-Ankle Ab/Adduction,,z-Foot Progress Angles
% LPelvisAngles, RPelvisAngles; x-Pelvic Tilt,y-Pelvic Obliquity,z-Pelvic Rotation

%% %%%%%%%%%%%%%%%%%%%%%%% HIP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LEFT FOOT
LHipAnglesx1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),157))'; %Hip Flexion/Extension
LHipAnglesy1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),158))'; %Hip Ab/Adduction
LHipAnglesz1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),159))'; %Hip Rotation

%  RIGHT FOOT
RHipAnglesx1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),169))';   %Hip Flexion/Extension
RHipAnglesy1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),170))';   %Hip Ab/Adduction
RHipAnglesz1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),171))';   %Hip Rotation

x_L=1:length(LHipAnglesx1);x_R=1:length(RHipAnglesx1);
LHipAnglesx1 = interp1(x_L,LHipAnglesx1 ,linspace(1,length(LHipAnglesx1),100));
LHipAnglesy1 = interp1(x_L,LHipAnglesy1 ,linspace(1,length(LHipAnglesy1),100));
LHipAnglesz1 = interp1(x_L,LHipAnglesz1 ,linspace(1,length(LHipAnglesz1),100));
RHipAnglesx1 = interp1(x_R,RHipAnglesx1 ,linspace(1,length(RHipAnglesx1),100));
RHipAnglesy1 = interp1(x_R,RHipAnglesy1 ,linspace(1,length(RHipAnglesy1),100));
RHipAnglesz1 = interp1(x_R,RHipAnglesz1 ,linspace(1,length(RHipAnglesz1),100));

%% %%%%%%%%%%%%%%%%%%%%%%%% KNEE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LEFT FOOT
LKneeAnglesx1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),160))'; % Knee Flexion/Extension
LKneeAnglesy1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),161))'; % Knee Ab/Adduction
LKneeAnglesz1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),162))'; % Knee Rotation

% RIGHT FOOT
RKneeAnglesx1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),172))'; % Knee Flexion/Extension
RKneeAnglesy1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),173))'; % Knee Ab/Adduction
RKneeAnglesz1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),174))'; % Knee Rotation

LKneeAnglesx1 = interp1(x_L,LKneeAnglesx1 ,linspace(1,length(LKneeAnglesx1),100));
LKneeAnglesy1 = interp1(x_L,LKneeAnglesy1 ,linspace(1,length(LKneeAnglesy1),100));
LKneeAnglesz1 = interp1(x_L,LKneeAnglesz1 ,linspace(1,length(LKneeAnglesz1),100));
RKneeAnglesx1 = interp1(x_R,RKneeAnglesx1 ,linspace(1,length(RKneeAnglesx1),100));
RKneeAnglesy1 = interp1(x_R,RKneeAnglesy1 ,linspace(1,length(RKneeAnglesy1),100));
RKneeAnglesz1 = interp1(x_R,RKneeAnglesz1 ,linspace(1,length(RKneeAnglesz1),100));

%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ANKLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LEFT FOOT
LAnkleAnglesx1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),163))'; % Ankle Dorsi/Plantar
LAnkleAnglesy1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),164))'; % Ankle Ab/Adduction
LAnkleAnglesz1 = (Markers.RawData(Lkrok_c(1):Lkrok_c(2),165))'; % Foot Progress Angles

% RIGHT FOOT
RAnkleAnglesx1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),175))'; % Ankle Dorsi/Plantar
RAnkleAnglesy1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),176))'; % Ankle Ab/Adduction
RAnkleAnglesz1 = (Markers.RawData(Rkrok_c(1):Rkrok_c(2),177))'; % Foot Progress Angles

LAnkleAnglesx1 = interp1(x_L,LAnkleAnglesx1 ,linspace(1,length(LAnkleAnglesx1),100));
LAnkleAnglesy1 = interp1(x_L,LAnkleAnglesy1 ,linspace(1,length(LAnkleAnglesy1),100));
LAnkleAnglesz1 = interp1(x_L,LAnkleAnglesz1 ,linspace(1,length(LAnkleAnglesz1),100));
RAnkleAnglesx1 = interp1(x_R,RAnkleAnglesx1 ,linspace(1,length(RAnkleAnglesx1),100));
RAnkleAnglesy1 = interp1(x_R,RAnkleAnglesy1 ,linspace(1,length(RAnkleAnglesy1),100));
RAnkleAnglesz1 = interp1(x_R,RAnkleAnglesz1 ,linspace(1,length(RAnkleAnglesz1),100));
%% %%%%%%%%%%%%%%%%%%%%%%%%% PELVIS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LEFT FOOT
LPelvisAnglesx1 = Markers.RawData(Lkrok_c(1):Lkrok_c(2),181); % Pelvic Tilt
LPelvisAnglesy1 = Markers.RawData(Lkrok_c(1):Lkrok_c(2),182); % Pelvic Obliquity
LPelvisAnglesz1 = Markers.RawData(Lkrok_c(1):Lkrok_c(2),183); % Pelvic Rotation

% RIGHT FOOT
RPelvisAnglesx1 = Markers.RawData(Rkrok_c(1):Rkrok_c(2),184); % Pelvic Tilt
RPelvisAnglesy1 = Markers.RawData(Rkrok_c(1):Rkrok_c(2),185); % Pelvic Obliquity
RPelvisAnglesz1 = Markers.RawData(Rkrok_c(1):Rkrok_c(2),186); % Pelvic Rotation

LPelvisAnglesx1 = interp1(x_L,LPelvisAnglesx1 ,linspace(1,length(LPelvisAnglesx1),100));
LPelvisAnglesy1 = interp1(x_L,LPelvisAnglesy1 ,linspace(1,length(LPelvisAnglesy1),100));
LPelvisAnglesz1 = interp1(x_L,LPelvisAnglesz1 ,linspace(1,length(LPelvisAnglesz1),100));
RPelvisAnglesx1 = interp1(x_R,RPelvisAnglesx1 ,linspace(1,length(RPelvisAnglesx1),100));
RPelvisAnglesy1 = interp1(x_R,RPelvisAnglesy1 ,linspace(1,length(RPelvisAnglesy1),100));
RPelvisAnglesz1 = interp1(x_R,RPelvisAnglesz1 ,linspace(1,length(RPelvisAnglesz1),100));
%% %%%% VYKRESLENÍ 
% osa x - % krokového cyklu levá noha
xl=1:length(LHipAnglesx1);
xl=(xl./length(LHipAnglesx1))*100;

% osa x - % krokového cyklu pravá noha
xr=1:length(RHipAnglesx1);
xr=(xr./length(RHipAnglesx1))*100;

% HipAngles
figure();
plot(xl,LHipAnglesx1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RHipAnglesx1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Hip Flexion/Extension','Right Hip Flexion/Extension');
figure();
plot(xl,LHipAnglesy1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RHipAnglesy1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Hip Ab/Adduction','Right Hip Ab/Adduction');
figure();
plot(xl,LHipAnglesz1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RHipAnglesz1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Hip Rotation','Right Hip Rotation');

%KneeAngles
figure();
plot(xl,LKneeAnglesx1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RKneeAnglesx1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Knee Flexion/Extension','Right Knee Flexion/Extension');
figure();
plot(xl,LKneeAnglesy1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RKneeAnglesy1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Knee Ab/Adduction','Right Knee Ab/Adduction');
figure();
plot(xl,LKneeAnglesz1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RKneeAnglesz1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Knee Rotation','Right Knee Rotation');

%AnkleAngles
figure();
plot(xl,LAnkleAnglesx1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RAnkleAnglesx1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Ankle Dorsi/Plantar','Right Ankle Dorsi/Plantar');
figure();
plot(xl,LAnkleAnglesy1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RAnkleAnglesy1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Ankle Ab/Adduction','Right Ankle Ab/Adduction');
figure();
plot(xl,LAnkleAnglesz1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RAnkleAnglesz1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Foot Progress Angles','Right Foot Progress Angles');

%PelvisAngles
figure();
plot(xl,LPelvisAnglesx1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RPelvisAnglesx1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Pelvic Tilt','Right Pelvic Tilt');
figure();
plot(xl,LPelvisAnglesy1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RPelvisAnglesy1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Pelvic Obliquity','Right Pelvic Obliquity');
figure();
plot(xl,LPelvisAnglesz1,'r'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
hold on
plot(xr,RPelvisAnglesz1,'g'),xlabel('% krokového cyklu');ylabel('Úhel [°]');
legend('Left Pelvic Rotation','Right Pelvic Rotation');
%% 
data_pacient_1_trial= {LHipAnglesx1,RHipAnglesx1;LHipAnglesy1,RHipAnglesy1;LHipAnglesz1,RHipAnglesz1;LKneeAnglesx1,RKneeAnglesx1;LKneeAnglesy1,RKneeAnglesy1;LKneeAnglesz1',RKneeAnglesz1';LAnkleAnglesx1',RAnkleAnglesx1';LAnkleAnglesy1',RAnkleAnglesy1';LAnkleAnglesz1',RAnkleAnglesz1';LPelvisAnglesx1',RPelvisAnglesx1';LPelvisAnglesy1',RPelvisAnglesy1';LPelvisAnglesz1',RPelvisAnglesz1'};

save data_pacient_1_trial data_pacient_1_trial;
% prumer=mean(interpolace,1);
% DMO_5{12,2}=prumer;



% end