function [Values_L_conc] = L_conc(weight,height,time_L_conc,ch4_L_conc, ch7_L_conc, ch8_L_conc, ch12_L_conc) 
%funkcia na spracovanie nameraných signálov koncentrického merania ľavej končatiny
%vstupmi je hmotnosť a výška subjekta a ďalej sú na vstupe výstupy z funkcie imp2vect
%výstupom funkcie je tabuľka parametrov slúžiacich na vyhodnotenie výsledkov
%spustenie funkcie: [Values_L_conc] = L_conc(60,1.69,time_L_conc,ch4_L_conc, ch7_L_conc, ch8_L_conc, ch12_L_conc) 

% weight = _ v kg (subjekt D --> 60)
% height = _ v m (subjekt D --> 1.69)

%vzorkovacia frekvencia
fvz_L_conc = 4000;

%kolko sekund zo zaznamu nas zaujima
s_L_conc = 24.4; 
time_L_conc = time_L_conc(1:(s_L_conc*fvz_L_conc));
ch4_L_conc = ch4_L_conc(1:(s_L_conc*fvz_L_conc));
ch7_L_conc = ch7_L_conc(1:(s_L_conc*fvz_L_conc));
ch7_L_conc(21000:23000) = 15;
ch8_L_conc = ch8_L_conc(1:(s_L_conc*fvz_L_conc));
ch12_L_conc = ch12_L_conc(1:(s_L_conc*fvz_L_conc));

%prepočty signálov
angle_L_conc = ch12_L_conc *2*1000/10; %uhol v °
torque_L_conc = ch4_L_conc *2*1000/5; %krútiaci moment v Nm
EMG_VM_L_conc = ch7_L_conc./1000; %EMG vastus medialis v mV
EMG_VL_L_conc= ch8_L_conc./1000; %EMG vastus lateralis v mV

%% izokineticky dynamometer

% filtracia signalov z izokinetickeho dynamometra
[b_L_conc,a_L_conc]=butter(3,20/fvz_L_conc,'low');
torque_filtered_L_conc=filtfilt(b_L_conc,a_L_conc,torque_L_conc);
angle_filtered_L_conc = filtfilt(b_L_conc,a_L_conc,angle_L_conc);

%detekcia maximálnych hodnôt sily
[yPKS1_L_conc, xPKS1_L_conc]=findpeaks(torque_filtered_L_conc, 'MinPeakHeight', 38, 'MinPeakDistance', 6000); %flexia
[yPKS2_L_conc, xPKS2_L_conc]=findpeaks(-torque_filtered_L_conc, 'MinPeakHeight', 70, 'MinPeakDistance', 6000); %extenzia 

%uhly kedy došlo k maximám
yANG1_L_conc = angle_filtered_L_conc(xPKS1_L_conc); %flexia
yANG2_L_conc = angle_filtered_L_conc(xPKS2_L_conc); %extenzia

%priemery sily
EXTENSION_L_conc = mean(yPKS2_L_conc); %extenzia...koncentricky kvadriceps
FLEXION_L_conc = mean(yPKS1_L_conc); %flexia...koncentricky hamstring
HAMQUAD_L_conc = FLEXION_L_conc/EXTENSION_L_conc; %pomer H/Q

%priemery uhlov
ANG_EXTENSION_L_conc = mean(yANG2_L_conc); %extenzia
ANG_FLEXION_L_conc = mean(yANG1_L_conc); %flexia

%data na normalizáciu - body mass index
BMI_L_conc = weight/(height^2);

%% EMG

%filtracia signalov EMG
% pohybové artefakty a nestabilita spojení elektroda-koža
% zasahuju do pásma 0 až 20 Hz … filtrace HP s fm=15-20 Hz
[e_L_conc,f_L_conc]=butter(4,20/fvz_L_conc,'high');
EMG_VL_filtered_L_conc =filtfilt(e_L_conc,f_L_conc,EMG_VL_L_conc); %vastus lateralis
EMG_VM_filtered_L_conc=filtfilt(e_L_conc,f_L_conc,EMG_VM_L_conc); %vastus medialis

%RMS
rmsv_EMG_VL_L_conc = sqrt(movmean(EMG_VL_filtered_L_conc.^2, 10)); % alebo rectified_EMG
rmsv_EMG_VM_L_conc = sqrt(movmean(EMG_VM_filtered_L_conc.^2, 10));

%detekcia maximálnych hodnôt aktivacie
[EMG_VL_yPKS1_L_conc, EMG_VL_xPKS1_L_conc]=findpeaks(rmsv_EMG_VL_L_conc, 'MinPeakHeight', 0.35, 'MinPeakDistance', 6000);
[EMG_VM_yPKS1_L_conc, EMG_VM_xPKS1_L_conc]=findpeaks(rmsv_EMG_VM_L_conc, 'MinPeakHeight', 0.5, 'MinPeakDistance', 6000);

%uhly kedy k maximám došlo
EMG_VL_yPKS1_ANG_L_conc = angle_filtered_L_conc(EMG_VL_xPKS1_L_conc);
EMG_VM_yPKS1_ANG_L_conc = angle_filtered_L_conc(EMG_VM_xPKS1_L_conc);

%data na normalizáciu EMG
rectified_EMG_VL_L_conc =abs(EMG_VL_L_conc);
max_rectified_EMG_VL_L_conc = max(rectified_EMG_VL_L_conc);
rectified_EMG_VM_L_conc =abs(EMG_VM_L_conc);
max_rectified_EMG_VM_L_conc = max(rectified_EMG_VM_L_conc);

%priemery EMG
VL_L_conc = mean(EMG_VL_yPKS1_L_conc);
VM_L_conc = mean(EMG_VM_yPKS1_L_conc);
EMG_L_conc = VM_L_conc/VL_L_conc;

%priemery uhlov EMG
ANG_VL_L_conc = mean(EMG_VL_yPKS1_ANG_L_conc);
ANG_VM_L_conc = mean(EMG_VM_yPKS1_ANG_L_conc);                                                               

%% surove signaly
figure
subplot 411
plot(time_L_conc, ch12_L_conc)
title('Pozícia - uhol končatiny')
xlabel('Čas [s]')
ylabel('Napätie [V]')
subplot 412
plot(time_L_conc, ch4_L_conc)
title('Krútiaci moment')
xlabel('Čas [s]')
ylabel('Napätie [V]')
subplot 413
plot (time_L_conc, ch7_L_conc)
title('EMG vastus medialis')
xlabel('Čas [s]')
ylabel('Napätie [mikroV]')
subplot 414
plot(time_L_conc, ch8_L_conc) 
title('EMG vastus lateralis')
xlabel('Čas [s]')
ylabel('Napätie [mikroV]')

sgtitle('Ľavá končatina/koncentrické meranie - surové signály')

%% torque spracovanie
figure
subplot 311
plot(time_L_conc,ch4_L_conc)
title('Krútiaci moment')
xlabel('Čas [s]')
ylabel('Napätie [V]')
subplot 312
plot(time_L_conc,torque_filtered_L_conc)
title('Krútiaci moment: prepočty a filtrácia')
xlabel('Čas [s]')
ylabel('Krútiaci moment [Nm]')
subplot 313
hold on
plot(time_L_conc,abs(torque_filtered_L_conc))
scatter(xPKS2_L_conc./fvz_L_conc, abs(yPKS2_L_conc), 'magenta')
scatter(xPKS1_L_conc./fvz_L_conc, abs(yPKS1_L_conc), 'black')
title('Krútiaci moment: detekcia max. hodnôt a prevod do absolútnych hodnôt')
xlabel('Čas[s]')
ylabel('Krútiaci moment [Nm]')

sgtitle('Ľavá končatina/koncentrické meranie - spracovanie krútiaceho momentu') 

%% angle spracovanie
figure
subplot 311
plot(time_L_conc, ch12_L_conc)
title('Pozícia - uhol končatiny')
xlabel('Čas [s]')
ylabel('Napätie [V]')
subplot 312
plot(time_L_conc, angle_filtered_L_conc)
title('Pozícia - uhol končatiny: prepočty a filtrácia')
xlabel('Čas [s]')
ylabel('Uhol [°]')
subplot 313
hold on
plot(time_L_conc,angle_filtered_L_conc)
scatter(xPKS1_L_conc./fvz_L_conc,yANG1_L_conc, 'black')
scatter(xPKS2_L_conc./fvz_L_conc,yANG2_L_conc,'magenta')
scatter(EMG_VL_xPKS1_L_conc./fvz_L_conc,EMG_VL_yPKS1_ANG_L_conc, 'red')
scatter(EMG_VM_xPKS1_L_conc./fvz_L_conc,EMG_VM_yPKS1_ANG_L_conc, 'green')
title('Pozícia - uhol končatiny')
xlabel('Čas[s]')
ylabel('Uhol [°]')
legend('uhol v čase', 'krútiaci moment - flexia', 'krútiaci moment - extenzia','EMG VL', 'EMG VM')

sgtitle('Ľavá končatina/koncentrické meranie - spracovanie pozície = uhlu končatiny') 

%% emg spracovanie - rovnaké pre VL aj VM
figure
subplot 311
plot(time_L_conc, ch8_L_conc) 
title('EMG vastus lateralis')
xlabel('Čas [s]')
ylabel('Napätie [mikroV]')
subplot 312
plot(time_L_conc, EMG_VL_filtered_L_conc)
title('EMG vastus lateralis: prepočet a filtrácia')
xlabel('Čas [s]')
ylabel('Napätie [mV]')
subplot 313
plot(time_L_conc, rmsv_EMG_VL_L_conc)
hold on
scatter(EMG_VL_xPKS1_L_conc./fvz_L_conc, EMG_VL_yPKS1_L_conc, 'black')
hold off
title('EMG vastus lateralis: RMS a detekcia max. hodnôt')
xlabel('Čas [s]')
ylabel('Napätie [mV]')

sgtitle('Pravá končatina/koncentrické meranie - spracovanie EMG signálu')

%% spracované data
figure
subplot 411
hold on
plot(time_L_conc,angle_filtered_L_conc)
scatter(xPKS1_L_conc./fvz_L_conc,yANG1_L_conc, 'black')
scatter(xPKS2_L_conc./fvz_L_conc,yANG2_L_conc,'magenta')
scatter(EMG_VL_xPKS1_L_conc./fvz_L_conc,EMG_VL_yPKS1_ANG_L_conc, 'red')
scatter(EMG_VM_xPKS1_L_conc./fvz_L_conc,EMG_VM_yPKS1_ANG_L_conc, 'green')
title('Pozícia - uhol končatiny')
xlabel('Čas[s]')
ylabel('Uhol [°]')
legend('0° -> 90° = flexia končatiny, 90° -> 0° = extenzia končatiny', 'krútiaci moment - flexia', 'krútiaci moment - extenzia','EMG vastus lateralis', 'EMG vastus medialis')
subplot 412
hold on
plot(time_L_conc,abs(torque_filtered_L_conc))
scatter(xPKS1_L_conc./fvz_L_conc, abs(yPKS1_L_conc), 'black')
scatter(xPKS2_L_conc./fvz_L_conc, abs(yPKS2_L_conc), 'magenta')
title('Krútiaci moment')
xlabel('Čas[s]')
ylabel('Krútiaci moment [Nm]')
legend('Krútiaci moment v čase', 'maximá počas flexie', 'maximá počas extenzie');
subplot 413
plot(time_L_conc, rmsv_EMG_VM_L_conc)
hold on
scatter(EMG_VM_xPKS1_L_conc./fvz_L_conc, EMG_VM_yPKS1_L_conc, 'green')
hold off
title('EMG vastus medialis - RMS')
xlabel('Čas [s]')
ylabel('Napätie [mV]')
legend('EMG vastus medialis v čase' , 'maximálne aktivácie')
subplot 414
plot(time_L_conc, rmsv_EMG_VL_L_conc)
hold on
scatter(EMG_VL_xPKS1_L_conc./fvz_L_conc, EMG_VL_yPKS1_L_conc, 'red')
title('EMG vastus lateralis - RMS')
xlabel('Čas [s]')
ylabel('Napätie [mV]')
legend('EMG vastus leteralis v čase' , 'maximálne aktivácie')

sgtitle('Ľavá končatina/koncentrické meranie - spracované signály') 

%% hodnoty
values_L_conc = zeros(11,1);
values_L_conc(1,1) = BMI_L_conc;
values_L_conc(2,1) = EXTENSION_L_conc;
values_L_conc(3,1) = ANG_EXTENSION_L_conc;
values_L_conc(4,1) = FLEXION_L_conc;
values_L_conc(5,1) = ANG_FLEXION_L_conc;
values_L_conc(6,1) = VM_L_conc;
values_L_conc(7,1) = ANG_VM_L_conc;
values_L_conc(8,1) = VL_L_conc;
values_L_conc(9,1) = ANG_VL_L_conc;
values_L_conc(10,1)= max_rectified_EMG_VM_L_conc; 
values_L_conc(11,1)= max_rectified_EMG_VL_L_conc;

values_L_conc = values_L_conc.';
column_L_conc = {'BMI','Kvadricep_Konc','Uhol_KK','Hamstring_Konc','Uhol_HK','VM_Konc','Uhol_VMK ','VL_Konc','Uhol_VLK','Max_VMK','Max_VLK'};
row_L_conc = {'Subjekt'};
Values_L_conc = array2table(values_L_conc, 'RowNames', row_L_conc, 'VariableNames', column_L_conc);


