function Program6(Data)
%----inicializace-------------------------------------------------------
close all
%---------------nacteni dat---------------------------------------------
%%
 EMG=Data.List1; % vyber dat z jednotlivych listu
 EMG2=Data.List2;
 EMG3=Data.List3;
 EMG4=Data.List4;
 EMG5=Data.List5;
 EMG6=Data.List6;
 %-------vyber dat - cas ---------------------------------------
cas=EMG(:,1);
cas2=EMG2(:,1);
cas3=EMG3(:,1);
cas4=EMG4(:,1);
cas5=EMG5(:,1);
cas6=EMG6(:,1);
%-------vyber dat - sila --------------------------------------
sila=EMG(:,2);
sila2=EMG2(:,2);
sila3=EMG3(:,2);
sila4=EMG4(:,2);
sila5=EMG5(:,2);
sila6=EMG6(:,2);
%-------vyber dat - signal -------------------------------------
signal=EMG(:,3);
signal2=EMG2(:,3);
signal3=EMG3(:,3);
signal4=EMG4(:,3);
signal5=EMG5(:,3);
signal6=EMG6(:,3);
%%
%-------uprava casove osy ---------------------------
%------prvni usek------------------------------------
cas=cas*60;
maximum_casu=max(cas);
korekce_casu=maximum_casu-60;
cas=cas-korekce_casu;
%------druhy usek------------------------------------
cas2=cas2*60;
maximum_casu2=max(cas2);
korekce_casu2=maximum_casu2-60;
cas2=cas2-korekce_casu2;
%------treti usek------------------------------------
cas3=cas3*60;
maximum_casu3=max(cas3);
korekce_casu3=maximum_casu3-60;
cas3=cas3-korekce_casu3;
%------ctvrty usek------------------------------------
cas4=cas4*60;
maximum_casu4=max(cas4);
korekce_casu4=maximum_casu4-60;
cas4=cas4-korekce_casu4;
%------paty usek------------------------------------
cas5=cas5*60;
maximum_casu5=max(cas5);
korekce_casu5=maximum_casu5-60;
cas5=cas5-korekce_casu5;
%------sesty usek------------------------------------
cas6=cas6*60;
maximum_casu6=max(cas6);
korekce_casu6=maximum_casu6-60;
cas6=cas6-korekce_casu6;

%%
%-----------filtrace---------------------------------------------------
%------------filtrace----horní_propust---------------------------------

fvz = 1000;          % fvz = vzorkovaci frekvence [Hz]
fmez = 17;           % fmez = mezni frekvence horni propusti [Hz]

%------ nastaveni koeficientu filtru-----------------------------------
b=fir1(150,fmez/500,'high'); %150 = pocet polu, high = horni propust
a=1;                         % a = jmenovatel prenosve chrakteristiky
%                              b = citatel prenosve chrakteristiky                           
%----- filtrace--------------------------------------------------------
signal=filter(b,a,signal);
signal2=filter(b,a,signal2);
signal3=filter(b,a,signal3);
signal4=filter(b,a,signal4);
signal5=filter(b,a,signal5);
signal6=filter(b,a,signal6);
%---------zobrazeni chrakteristik filtru------------------------------
figure('Name','Amplitudová a fázová frekvenční charakteristika - horní propusť')
%  frekvencni charakteristika
freqz(b,a,1024,fvz)% 1024 = počet vykreslených bodu frekvencni charakteristiky
title('Amplitudová a fázová frekvenční charakteristika - horní propusť')
subplot(2,1,1)
xlabel('Frekvence (Hz)')
ylabel('Amplituda (dB)')
subplot(2,1,2)
xlabel('Frekvence (Hz)')
ylabel('Fáze (stupně)')
%------impuzni charakteristika----------------------------------------
% impuls = [1 zeros(1,499)];%vytvoreni impuzniho signalu
% vystup2=[];
% vystup2=filter(b,a,impuls);%filtrace impuzniho signalu
% figure(figure('Name','Vykreslení impulzní charakteristiky'));
% subplot(2,1,1);
% stem(impuls); %vykresleni impulzu
% subplot(2,1,2);
% stem(vystup2); %vykresleni filtrovaneho impulzu = impulzni chrakteristika
% % rozlozeni nul a polu
% figure('Name','Rozložení nulových bodů a pólů'))
% zplane(b,a);
%%
%------------filtrace----50Hz-zadrz------------------------------------
fvz = 1000;          % fvz = vzorkovaci frekvence [Hz]
fmez2 = 50;          % fmez2 = frekvence, ktera ma byt potlacena [Hz]
fp=0.5;              %  Hz - šířka filtru (vyrezu)
%------ nastaveni koeficientu filtru------------------
wo= fmez2/500;% frekvence ktera ma byt potlačena
bw= fp/500;% sirka filtru (vyrezu - pasmove zadrze)
[b50,a50] = iirnotch(wo,bw);
%                              a = jmenovatel prenosve chrakteristiky
%                              b = citatel prenosve chrakteristiky
%----- filtrace--------------------------------------------------------
signal=filter(b50,a50,signal);
signal2=filter(b50,a50,signal2);
signal3=filter(b50,a50,signal3);
signal4=filter(b50,a50,signal4);
signal5=filter(b50,a50,signal5);
signal6=filter(b50,a50,signal6);
%---------zobrazeni chrakteristik filtru-------------------------------
figure('Name','Amplitudová a fázová frekvenční charakteristika - pásmová zádrž: 50Hz')

freqz(b50,a50,1024,fvz)% 1024 = počet vykreslených bodu frekvencni charakteristiky
title('Amplitudová a fázová frekvenční charakteristika - pásmová zádrž: 50Hz') % 
subplot(2,1,1)
xlabel('Frekvence (Hz)')
ylabel('Amplituda (dB)')
axis([0 500 -6 1])
subplot(2,1,2)
xlabel('Frekvence (Hz)')
ylabel('Fáze (stupně)')
% %------impuzni charakteristika---------------------------------------
% impuls1 = [1 zeros(1,499)];%vytvoreni impuzniho signalu
% out21=[];
% out21=filter(b50,a50,impuls1);
% figure('Name','Vykreslení impulzní charakteristiky 50 Hz'))
% subplot(2,1,1);
% stem(impuls1);
% subplot(2,1,2);
% stem(out21);
% % rozlozeni nul a polu
% figure('Name','Rozložení nulových bodů a pólů 50 Hz')
% zplane(b1,a1);
%%
%-----------Zobrazeni signalu a sily-----------------------------------
figure('Name','Zobrazeni signálu a síly')
maximum_signal = max([signal',signal2', signal3', signal4', signal5', signal6']);
minimum_signal = min([signal',signal2', signal3', signal4', signal5', signal6']);
%----------signal 1----------------------------------------------------
axes('position',[0.10 0.863 0.85 0.073],  'fontsize', 6)
plot(cas,signal)
text(24,maximum_signal*1.6 ,'Zobrazení signálu a síly', 'fontsize', 10)
ylabel('EMG1(mV)',  'fontsize', 6 )
axis([-1 61 minimum_signal maximum_signal])
%----------sila 1 -----------------------------------------------------
axes('position',[0.10 0.79 0.85 0.073], 'fontsize', 6)
plot(cas,sila)
ylabel('Síla1(kg)',  'fontsize', 6 )
axis([-1 61 1 35])
%----------------------------------------------------------------------
%----------signal 2----------------------------------------------------
axes('position',[0.10 0.717 0.85 0.073], 'fontsize', 6) 
plot(cas2,signal2)
ylabel('EMG2(mV)',  'fontsize', 6 )
axis([-1 61 minimum_signal maximum_signal])
%----------sila 2 ----------------------------------------------------
axes('position',[0.10 0.644 0.85 0.073], 'fontsize', 6)

plot(cas2,sila2)
ylabel('Síla2(kg)', 'fontsize', 6 )
axis([-1 61 1 35])
%----------------------------------------------------------------------
%----------signal 3----------------------------------------------------
axes('position',[0.10 0.571 0.85 0.073], 'fontsize', 6)
plot(cas3,signal3)
ylabel('EMG3(mV)', 'fontsize', 6 )
axis([-1 61 minimum_signal maximum_signal])
%----------sila 3 -----------------------------------------------------
axes('position',[0.10 0.498 0.85 0.073], 'fontsize', 6)

plot(cas3,sila3)
ylabel('Síla3(kg)', 'fontsize', 6 )
axis([-1 61 1 35])
%-----------------------------------------------------------------------
%----------signal 4-----------------------------------------------------
axes('position',[0.10 0.425 0.85 0.073], 'fontsize', 6)
plot(cas4,signal4)
ylabel('EMG4(mV)', 'fontsize', 6 )
axis([-1 61 minimum_signal maximum_signal])
%----------sila 4 ------------------------------------------------------
axes('position',[0.10 0.352 0.85 0.073], 'fontsize', 6)
plot(cas4,sila4)
ylabel('Síla4(kg)', 'fontsize', 6 )
axis([-1 61 1 35])
%------------------------------------------------------------
%----------signal 5-----------------------------------------
axes('position',[0.10 0.279 0.85 0.073], 'fontsize', 6)
plot(cas5,signal5)
ylabel('EMG5(mV)', 'fontsize', 6 )
axis([-1 61 minimum_signal maximum_signal])
%----------sila 5 -------------------------------------------
axes('position',[0.10 0.206 0.85 0.073], 'fontsize', 6)
plot(cas5,sila5)
ylabel('Síla5(kg)', 'fontsize', 6 )
axis([-1 61 1 35])
%------------------------------------------------------------
%----------signal 6-----------------------------------------
axes('position',[0.10 0.133 0.85 0.073], 'fontsize', 6)
plot(cas6,signal6)
ylabel('EMG6(mV)', 'fontsize', 7 )
axis([-1 61 minimum_signal maximum_signal])
%----------sila 6 -------------------------------------------
axes('position',[0.10 0.06 0.85 0.073], 'fontsize', 6)
plot(cas6,sila6)
ylabel('Síla6(kg)', 'fontsize', 7 )
axis([-1 61 1 35])
text(52,-6,'čas (s)', 'fontsize', 7)
%%
%-------------vypocet amplitudovych hodnot----------------------------
%-------------pro prvni usek------------------------------------------
N=length(signal);
MAV1=(sum(abs(signal)))/N; % MAV = Prumer absolutnich hodnot EMG signalu
RMS1=sqrt((1/N)*(sum(signal.^2)));  % RMS = Prumer kvadratu hodnot EMG signalu
%-------------pro druhy usek-----------------------------------------
N2=length(signal2);
MAV2=(sum(abs(signal2)))/N2;
RMS2=sqrt((1/N2)*(sum(signal2.^2)));
%-------------pro treti usek-----------------------------------------
N3=length(signal3);
MAV3=(sum(abs(signal3)))/N3;
RMS3=sqrt((1/N3)*(sum(signal3.^2)));
%-------------pro ctvrty usek----------------------------------------
N4=length(signal4);
MAV4=(sum(abs(signal4)))/N4;
RMS4=sqrt((1/N4)*(sum(signal4.^2)));
%-------------pro paty usek-----------------------------------------
N5=length(signal5);
MAV5=(sum(abs(signal5)))/N5;
RMS5=sqrt((1/N5)*(sum(signal5.^2)));
%-------------pro sesty usek-----------------------------------------
N6=length(signal6);
MAV6=(sum(abs(signal6)))/N6;
RMS6=sqrt((1/N6)*(sum(signal6.^2)));
%%
%-------Zobrazeni hodnot amplitudy---------------------------------
figure('Name','Hodnoty amplitudy')
Vse_RMS=[RMS1, RMS2, RMS3, RMS4,  RMS5,  RMS6];
Vse_MAV=[MAV1, MAV2, MAV3, MAV4, MAV5, MAV6];
casova_osa = linspace(1,360,length(Vse_RMS));
%------------Vykresleni:--------------------------------------------
%%
subplot(2,1,1)

plot(casova_osa,Vse_MAV,  'bs-', 'LineWidth',2, 'MarkerEdgeColor','b', 'MarkerFaceColor','c','MarkerSize',10)
title('Hodnoty MAV = Střední absolutní hodnota EMG')
ylabel('MAV')
xlabel('Čas (s)')
    str_MAV1=num2str(MAV1);
    text(casova_osa(1),MAV1+0.3,str_MAV1,'HorizontalAlignment','left')
    str_MAV2=num2str(MAV2);
    text(casova_osa(2),MAV2+0.3,str_MAV2,'HorizontalAlignment','left')
    str_MAV3=num2str(MAV3);
    text(casova_osa(3),MAV3+0.3,str_MAV3,'HorizontalAlignment','left')
    str_MAV4=num2str(MAV4);
    text(casova_osa(4),MAV4+0.3,str_MAV4,'HorizontalAlignment','left')
     str_MAV5=num2str(MAV5);
    text(casova_osa(5),MAV5+0.3,str_MAV5,'HorizontalAlignment','left')
     str_MAV6=num2str(MAV6);
    text(casova_osa(6),MAV6+0.3,str_MAV6,'HorizontalAlignment','right')
axis([-1 365 min(Vse_MAV)-1 max(Vse_MAV)+1])
legend('Střední absolutní hodnota EMG', 'Location','NorthEast')
grid on

%hold on 

%regrese MAV:-------------------------------------------------------------
[~,m_MAV,b_MAV] = regression(casova_osa,Vse_MAV);

str1_MAV11 = ['MAV = ', num2str(m_MAV), '*t +', num2str(b_MAV)];

text(1,max(Vse_MAV)+1, 'Rovnice regrese:', 'fontsize', 11, ...
    'verticalAlignment', 'top', 'horizontalAlignment', 'left')
text(1,max(Vse_MAV)+0.7, str1_MAV11, 'EdgeColor','blue','LineWidth',1.5,...
    'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontsize', 11);

% plot(casova_osa, m_MAV*casova_osa+b_MAV, 'k', 'LineWidth',1)
%--------------------------------------------------------------------------
subplot(2,1,2)

plot(casova_osa,Vse_RMS,  'rs-', 'LineWidth',2, 'MarkerEdgeColor','r', 'MarkerFaceColor','c','MarkerSize',10)
title('Hodnoty RMS = Průměr kvadrátů EMG')
ylabel('RMS')
xlabel('Čas (s)')
    str_RMS1=num2str(RMS1);
    text(casova_osa(1),RMS1+0.3,str_RMS1,'HorizontalAlignment','left')
    str_RMS2=num2str(RMS2);
    text(casova_osa(2),RMS2+0.3,str_RMS2,'HorizontalAlignment','left')
    str_RMS3=num2str(RMS3);
    text(casova_osa(3),RMS3+0.3,str_RMS3,'HorizontalAlignment','left')
    str_RMS4=num2str(RMS4);
    text(casova_osa(4),RMS4+0.3,str_RMS4,'HorizontalAlignment','left')
    str_RMS5=num2str(RMS5);
    text(casova_osa(5),RMS5+0.3,str_RMS5,'HorizontalAlignment','left')
    str_RMS6=num2str(RMS6);
    text(casova_osa(6),RMS6+0.3,str_RMS6,'HorizontalAlignment','right')
axis([-1 365 min(Vse_RMS)-1 max(Vse_RMS)+1])
grid on
legend('Průměr kvadrátů EMG', 'Location','NorthEast')

grid on

%regrese RMS:-------------------------------------------------------------
% hold on
[~,m_RMS,b_RMS] = regression(casova_osa,Vse_RMS);

str1_RMS11 = ['RMS = ', num2str(m_RMS), '*t +', num2str(b_RMS)];

text(1,max(Vse_RMS)+1, 'Rovnice regrese:', 'fontsize', 11, ...
    'verticalAlignment', 'top', 'horizontalAlignment', 'left')
text(1,max(Vse_RMS)+0.7, str1_RMS11, 'EdgeColor','blue','LineWidth',1.5,...
    'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontsize', 11);

% plot(casova_osa, m_RMS*casova_osa+b_RMS, 'k', 'LineWidth',1)
%%
%---------------------vypočet sily - průměr ------------------------
sila=sila';
sila2=sila2'; 
sila3=sila3'; 
sila4=sila4';
sila5=sila5';
sila6=sila6';

sily=[sila sila2 sila3 sila4 sila5 sila6];

pocet_useku=36;%nastavitelné
delka_sily=length(sily);
sily_okno = floor(delka_sily/pocet_useku);
kroky=sily_okno;
sily_nove=[];

for k=1:kroky:delka_sily
    if k+sily_okno-1<=delka_sily;
    useky = sily(k:k+sily_okno-1);
    prumer = (sum(useky))/(length(useky));
    sily_nove = [sily_nove, prumer];
    end
end
%--------sest hodnot sily-------------------------------------------
pocet_useku44=6; %nastavitelné
sily_okno44 = floor(delka_sily/pocet_useku44);
kroky=sily_okno44;
sily_nove44=[];

for k=1:kroky:delka_sily
    if k+sily_okno44-1<=delka_sily;
    useky44 = sily(k:k+sily_okno44-1);
    prumer44 = (sum(useky44))/(length(useky44));
    sily_nove44 = [sily_nove44, prumer44];
    end
end
%------vykresleni sil--------------------------------------------
figure('Name','Průměrné hodnoty síly')
xo=linspace(0,360,length(sily_nove));
plot(xo,sily_nove, 'r', 'LineWidth',2)

title('Průměrné hodnoty síly - celý signál') 
ylabel('Síla (kg)',  'fontsize', 10 )
xlabel('Čas (s)',  'fontsize', 10 )
axis([-1 365 min(sily_nove)-5 max(sily_nove)+5])
grid on

xs = linspace(1,360,length(sily_nove44));
    str_sily_nove441=num2str(sily_nove44(1));
    text(xs(1),sily_nove44(1)*1.05,'\downarrow','HorizontalAlignment','left')
    text(xs(1),sily_nove44(1)*1.1, str_sily_nove441, 'HorizontalAlignment','left')
    str_sily_nove442=num2str(sily_nove44(2));
    text(xs(2),sily_nove44(2)*1.05,'\downarrow','HorizontalAlignment','left')
    text(xs(2),sily_nove44(2)*1.1,str_sily_nove442,'HorizontalAlignment','left')
    str_sily_nove443=num2str(sily_nove44(3));
    text(xs(3),sily_nove44(3)*1.05,'\downarrow','HorizontalAlignment','left')
    text(xs(3),sily_nove44(3)*1.1,str_sily_nove443,'HorizontalAlignment','left')
    str_sily_nove444=num2str(sily_nove44(4));
    text(xs(4),sily_nove44(4)*1.05,'\downarrow','HorizontalAlignment','left')
    text(xs(4),sily_nove44(4)*1.1,str_sily_nove444,'HorizontalAlignment','left')
     str_sily_nove445=num2str(sily_nove44(5));
    text(xs(5),sily_nove44(5)*1.05,'\downarrow','HorizontalAlignment','left')
    text(xs(5),sily_nove44(5)*1.1,str_sily_nove445,'HorizontalAlignment','left')
    str_sily_nove446=num2str(sily_nove44(6));
    text(xs(6),sily_nove44(6)*1.05,'\downarrow','HorizontalAlignment','left')
    text(xs(6),sily_nove44(6)*1.1,str_sily_nove446,'HorizontalAlignment','right')
legend('Průměrné hodnoty síly', 'Location','NorthEast')

%regrese Sily:-------------------------------------------------------------

hold on
[~,m_sily,b_sily] = regression(xo,sily_nove);

str1_sily11 = ['Síla = ', num2str(m_sily), '*t +', num2str(b_sily)];

text(1,max(sily_nove)+5, 'Rovnice regrese:', 'fontsize', 11, ...
    'verticalAlignment', 'top', 'horizontalAlignment', 'left')
text(1,max(sily_nove)+4, str1_sily11, 'EdgeColor','blue','LineWidth',1.5,...
    'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontsize', 11);

plot(xo, m_sily*xo+b_sily, 'k', 'LineWidth',1)
%%
% ---------------boxplot sily---------------------------------------
LS=length(sila);
LS2=length(sila2);
LS3=length(sila3);
LS4=length(sila4);
LS5=length(sila5);
LS6=length(sila6);

LSs=min([LS, LS2, LS3, LS4, LS5, LS6]);

sila=sila(1:LSs);
sila2=sila2(1:LSs);
sila3=sila3(1:LSs);
sila4=sila4(1:LSs);
sila5=sila5(1:LSs);
sila6=sila6(1:LSs);

sily2=[sila' sila2' sila3' sila4' sila5' sila6'];

figure('Name','Boxploty síly')
popis=char('sila', 'sila2', 'sila3', 'sila4', 'sila5', 'sila6');
boxplot(sily2, popis)
title('Boxploty síly')
ylabel('Síla (kg)', 'fontsize', 14, 'fontsize', 14 )
xlabel('Jednotlivé úseky signálu', 'fontsize', 14 )
axis([0.54 6.38 1 35])

grid on 
%%
% -----vypocet spektra-----------------------------------------------
fvz=1000;
%-------prvni usek ---------------------------
[xxx,modul]=spektrum(signal,fvz);%funkce na vypocet spektra
%-------druky usek ---------------------------
[xxx2,modul2]=spektrum(signal2,fvz);
%-------treti usek ---------------------------
[xxx3,modul3]=spektrum(signal3,fvz);
%-------ctvrty usek ---------------------------
[xxx4,modul4]=spektrum(signal4,fvz);
%-------paty usek ---------------------------
[xxx5,modul5]=spektrum(signal5,fvz);
%-------sesty usek ---------------------------
[xxx6,modul6]=spektrum(signal6,fvz);

%%
%-----------zobrazeni muduloveho spektra-----------------------------
figure('Name', 'Modulové spektrum')
grid off
maximum_m=max([modul', modul2', modul3', modul4', modul5', modul6']);
minimum_m=min([modul', modul2', modul3', modul4', modul5', modul6']);
%-------prvni usek --------------------------------------------------
axes('position',[0.10 0.795 0.85 0.138], 'fontsize', 8)

plot(xxx,modul,'-');
text(200,maximum_m*1.2,'Modulové spektrum', 'fontsize', 12)
ylabel('Ampliuda^2 (1)', 'fontsize', 8 )
axis([0 500 0 maximum_m])
%-------druky usek -------------------------------------------------
axes('position',[0.10 0.652 0.85 0.138], 'fontsize', 8)

plot(xxx2,modul2,'-');
ylabel('Ampliuda^2 (2)', 'fontsize', 8 )
axis([0 500 0 maximum_m])
%-------treti usek -------------------------------------------------
axes('position',[0.10 0.509 0.85 0.138], 'fontsize', 8)

plot(xxx3,modul3,'-');
ylabel('Ampliuda^2 (3)', 'fontsize', 8 )
axis([0 500 0 maximum_m])
%-------ctvrty usek -------------------------------------------------
axes('position',[0.10 0.366 0.85 0.138], 'fontsize', 8)

plot(xxx4,modul4,'-');
ylabel('Ampliuda^2 (4)', 'fontsize', 8 )
axis([0 500 0 maximum_m])
%-------paty usek -------------------------------------------------
axes('position',[0.10 0.223 0.85 0.138], 'fontsize', 8)

plot(xxx5,modul5,'-');
ylabel('Ampliuda^2 (5)', 'fontsize', 8 )
axis([0 500 0 maximum_m])
%-------sesty usek -------------------------------------------------
axes('position',[0.10 0.08 0.85 0.138], 'fontsize', 8)

plot(xxx6,modul6,'-');
ylabel('Ampliuda^2 (6)', 'fontsize', 8 )
xlabel('Frekvence (Hz)', 'fontsize', 8)
axis([0 500 0 maximum_m])

%---vypocet tresu, funguje pouze při vypnutém filtru horni proput

% tres1=max(modul(1:1200));
% tres2=max(modul2(1:1200));
% tres3=max(modul3(1:1200));
% tres4=max(modul4(1:1200));
% tres5=max(modul5(1:1200));
% tres6=max(modul6(1:1200));
% 
% tresy = [tres1, tres2, tres3, tres4, tres5, tres6];

%%
%----------vypocet frekvencnich hodnot---------------------------------
%-------prvni usek ----------------------------------------------------
modul=modul';
Fmed1 = Fmed(xxx,modul);
Fmean1 = Fmean(xxx,modul);
%-------druky usek -------------------------------------------------
modul2=modul2';
Fmed2 = Fmed(xxx2,modul2);
Fmean2 = Fmean(xxx2,modul2);
%------- treti usek -------------------------------------------------
modul3=modul3';
Fmed3 = Fmed(xxx3,modul3);
Fmean3 = Fmean(xxx3,modul3);
%------- ctvrty usek -------------------------------------------------
modul4=modul4';
Fmed4 = Fmed(xxx4,modul4);
Fmean4 = Fmean(xxx4,modul4);
%------- paty usek -------------------------------------------------
modul5=modul5';
Fmed5 = Fmed(xxx5,modul5);
Fmean5 = Fmean(xxx5,modul5);
%------- sesty usek -------------------------------------------------
modul6=modul6';
Fmed6 = Fmed(xxx6,modul6);
Fmean6 = Fmean(xxx6,modul6);
%%
%-------Vykresleni a vypocet f med v oknech--------------------------
cely_signal=[signal; signal2; signal3; signal4; signal5; signal6];% slozeni signulu za sebe
delka_cely_signal=length(cely_signal);
pocet_useku2=12;
okno = floor((delka_cely_signal)/pocet_useku2);% menitelny parametr
krok = okno;% menitelny parametr

%--------------------------------------------------------------------
Fmed_okno = [];
for n = 1:krok:delka_cely_signal 
    if n+okno-1<=delka_cely_signal;
    usek = cely_signal(n:n+okno-1);
    [xx,mod1]=spektrum(usek,fvz);
    vysled = Fmed(xx,mod1);
    Fmed_okno = [Fmed_okno, vysled];
    end
end
%%
% --------Prubeh medianove frekvence-----------------------------------
figure('Name', 'Frekvenční hodnoty')
subplot(3,1,1)

y= [Fmed1 Fmed2 Fmed3 Fmed4 Fmed5 Fmed6];
x = linspace(1,360,length(y));
plot(x,y, 'ro-', 'LineWidth',2, 'MarkerEdgeColor','r', 'MarkerFaceColor','c','MarkerSize',10)
title('Šet hodnot mediánové frekvence')
    str_Fmed1=num2str(Fmed1);
    text(x(1),Fmed1+3,str_Fmed1,'HorizontalAlignment','left')
    str_Fmed2=num2str(Fmed2);
    text(x(2),Fmed2+3,str_Fmed2,'HorizontalAlignment','left')
    str_Fmed3=num2str(Fmed3);
    text(x(3),Fmed3+3,str_Fmed3,'HorizontalAlignment','left')
    str_Fmed4=num2str(Fmed4);
    text(x(4),Fmed4+3,str_Fmed4,'HorizontalAlignment','left')
    str_Fmed5=num2str(Fmed5);
    text(x(5),Fmed5+3,str_Fmed5,'HorizontalAlignment','left')
    str_Fmed6=num2str(Fmed6);
    text(x(6),Fmed6+3,str_Fmed6,'HorizontalAlignment','right')
axis([-1 361 min(y)-5 max(y)+5])
grid on
ylabel('Mediánová frekvence (Hz)', 'fontsize', 10 )
xlabel('Čas (s)', 'fontsize', 10 )
legend('Mediánová frekvence (Hz) 6', 'Location','NorthEast')
%% ----------Dvanact hodnot------------------------------------------------

subplot(3,1,2)
osm = Fmed_okno;
xko = linspace(1,360,length(osm));
plot(xko,osm, 'bo-', 'LineWidth',2, 'MarkerEdgeColor','b', 'MarkerFaceColor','c','MarkerSize',10);
title('Dvanáct hodnot mediánové frekvence')
grid on 
    str_Fmed11=num2str(Fmed_okno(1));
    text(xko(1),Fmed_okno(1)+1,str_Fmed11,'HorizontalAlignment','left')
    str_Fmed12=num2str(Fmed_okno(2));
    text(xko(2),Fmed_okno(2)+3,str_Fmed12,'HorizontalAlignment','left')
    str_Fmed13=num2str(Fmed_okno(3));
    text(xko(3),Fmed_okno(3)+3,str_Fmed13,'HorizontalAlignment','left')
    str_Fmed14=num2str(Fmed_okno(4));
    text(xko(4),Fmed_okno(4)+3,str_Fmed14,'HorizontalAlignment','left')
    str_Fmed15=num2str(Fmed_okno(5));
    text(xko(5),Fmed_okno(5)+3,str_Fmed15,'HorizontalAlignment','left')
    str_Fmed16=num2str(Fmed_okno(6));
    text(xko(6),Fmed_okno(6)+3,str_Fmed16,'HorizontalAlignment','left')
    str_Fmed17=num2str(Fmed_okno(7));
    text(xko(7),Fmed_okno(7)+3,str_Fmed17,'HorizontalAlignment','left')
    str_Fmed18=num2str(Fmed_okno(8));
    text(xko(8),Fmed_okno(8)+3,str_Fmed18,'HorizontalAlignment','left')
    str_Fmed19=num2str(Fmed_okno(9));
    text(xko(9),Fmed_okno(9)+3,str_Fmed19,'HorizontalAlignment','left')
    str_Fmed110=num2str(Fmed_okno(10));
    text(xko(10),Fmed_okno(10)+3,str_Fmed110,'HorizontalAlignment','left')
    str_Fmed111=num2str(Fmed_okno(11));
    text(xko(11),Fmed_okno(11)+3,str_Fmed111,'HorizontalAlignment','left')
    str_Fmed112=num2str(Fmed_okno(12));
    text(xko(12),Fmed_okno(12)+3,str_Fmed112,'HorizontalAlignment','right')
axis([-1 241 min(osm)-5 max(osm)+5])
ylabel('Mediánová frekvence (Hz)', 'fontsize', 10)
xlabel('Čas (s)', 'fontsize', 10)
legend('Mediánová frekvence (Hz) 8', 'Location','NorthEast')
%%
%-------hodnoty -----------------Fmean---------------------------------
subplot(3,1,3)
Vse_fmean = [Fmean1, Fmean2, Fmean3,Fmean4, Fmean5, Fmean6];
plot(x ,Vse_fmean, 'go-', 'LineWidth',2, 'MarkerEdgeColor','g', 'MarkerFaceColor','c','MarkerSize',10)
title('Hodnoty střední frekvence')
ylabel('Střední frekvence (Hz)', 'fontsize', 10)
xlabel('Čas (s)', 'fontsize', 10)
legend('Střední frekvence (Hz)', 'Location','NorthEast')

    str_Fmean1=num2str(Fmean1);
    text(x(1),Fmean1+3,str_Fmean1,'HorizontalAlignment','left')
    str_Fmean2=num2str(Fmean2);
    text(x(2),Fmean2+3,str_Fmean2,'HorizontalAlignment','left')
    str_Fmean3=num2str(Fmean3);
    text(x(3),Fmean3+3,str_Fmean3,'HorizontalAlignment','left')
    str_Fmean4=num2str(Fmean4);
    text(x(4),Fmean4+3,str_Fmean4,'HorizontalAlignment','left')
    str_Fmean5=num2str(Fmean5);
    text(x(5),Fmean5+3,str_Fmean5,'HorizontalAlignment','left')
    str_Fmean6=num2str(Fmean6);
    text(x(6),Fmean6+3,str_Fmean6,'HorizontalAlignment','right')
    
axis([-1 361 min(Vse_fmean)-5 max(Vse_fmean)+5])

grid on


%%
%----------------------regrese----------------------------------
%---------------------sest hodnoty------------------------------------

figure(1000)
grid off
[r,m,b] = regression(x,y,'one');
plotregression(x,y)
title('Lineární regrese: Šest hodnot mediánové frekvence', 'fontweight', 'bold', 'fontsize', 12)


str1 = ['Fmed = ', num2str(m), '*t +', num2str(b)];
str_r = ['Korelcni faktor r = ', num2str(r)];

text(0,75-1, 'Rovnice regrese:', 'fontsize', 11, 'fontweight', 'bold')
text(1,75-3, str1, 'fontweight', 'bold', 'EdgeColor','red','LineWidth',2, 'fontsize', 11);
text(0,75-5, str_r, 'fontsize', 11, 'fontweight', 'bold');

ylabel('Mediánová frekvence (Hz)', 'fontsize', 12)
xlabel('Čas (s)', 'fontsize', 12)
legend('Korelace f a času','Lineární regrese', 'Mediánová frekvence', 'Location','NorthEast')

axis([-1 360 35 75])
%-----------dvanact hodnot-------------------------------------------------
figure(1001)
[r12,m12,b12] = regression(xko,osm);

% m = sklon přímky
% b = korekce
% r = závislost x a y (jak moc jsou korelovány)

plotregression(xko,osm)
title('Lineární regrese: Dvanáct hodnot mediánové frekvence', 'fontweight', 'bold', 'fontsize', 12)

str = ['Fmed = ', num2str(m12), '*t +', num2str(b12)];
str_r12 = ['Korelační faktor r = ', num2str(r12)];
text(0,75-1, 'Rovnice regrese:', 'fontsize', 11, 'fontweight', 'bold')
text(0,75-3, str, 'fontweight', 'bold', 'EdgeColor','red','LineWidth',2, 'fontsize', 11);
text(0,75-5, str_r12, 'fontsize', 11, 'fontweight', 'bold');

ylabel('Mediánová frekvence (Hz)', 'fontsize', 12)
xlabel('Čas (s)', 'fontsize', 12)
legend('Korelace f a času','Lineární regrese', 'Mediánová frekvence', 'Location','NorthEast')

axis([-1 360 35 75])

%%
%-----------Prehledne zobrazeni hodnot--------------------------------
%--------------MAV----------------------------------------------------
figure('Name', 'Zobrazení všech hodnot')
str_MAV33 = ['MAV1 =   ' num2str(MAV1,'%f');...
'MAV2 =   ' num2str(MAV2,'%f');...
'MAV3 =   ' num2str(MAV3,'%f');...
'MAV4 =   ' num2str(MAV4,'%f');...
'MAV5 =   ' num2str(MAV5,'%f');...
'MAV6 =   ' num2str(MAV6,'%f');...
[] [];];
%--------------RMS----------------------------------------------------
str_RMS33 = [ 'RMS1 =   ' num2str(RMS1,'%f');...
'RMS2 =   ' num2str(RMS2,'%f');...
'RMS3 =   ' num2str(RMS3,'%f');...
'RMS4 =   ' num2str(RMS4,'%f');...
'RMS5 =   ' num2str(RMS5,'%f');...
'RMS6 =   ' num2str(RMS6,'%f');...
[] [];];
%--------------Fmean----------------------------------------------------
str_Fmean33 = ['Fmean1 = ' num2str(Fmean1,'%f');...
'Fmean2 = ' num2str(Fmean2,'%f');...
'Fmean3 = ' num2str(Fmean3,'%f');...
'Fmean4 = ' num2str(Fmean4,'%f');...
'Fmean5 = ' num2str(Fmean5,'%f');...
'Fmean6 = ' num2str(Fmean6,'%f');...
[] [];];
%--------------Fmed-4---------------------------------------------------
str_Fmed33=['Fmed1  = ' num2str(Fmed1,'%f');...
'Fmed2  = ' num2str(Fmed2,'%f');...
'Fmed3  = ' num2str(Fmed3,'%f');...
'Fmed4  = ' num2str(Fmed4,'%f');...
'Fmed5  = ' num2str(Fmed5,'%f');...
'Fmed6  = ' num2str(Fmed6,'%f')];
%----Fmed-8------------------------------------------------------------
str_vysledky_osm3=['Fmed1 =  '  num2str(osm(1),'%f');...
'Fmed2 =  '  num2str(osm(2),'%f');...
'Fmed3 =  '  num2str(osm(3),'%f');...
'Fmed4 =  '  num2str(osm(4),'%f');...
'Fmed5 =  '  num2str(osm(5),'%f');...
'Fmed6 =  '  num2str(osm(6),'%f');...
'Fmed7 =  '  num2str(osm(7),'%f');...
'Fmed8 =  '  num2str(osm(8),'%f');...
'Fmed9 =  '  num2str(osm(9),'%f');...
'Fmed10 = '  num2str(osm(10),'%f');...
'Fmed11 = '  num2str(osm(11),'%f');...
'Fmed12 = '  num2str(osm(12),'%f')];
%-------hodnoty sily------------------------------------------------
if sily_nove44(1)<10 && sily_nove44(2)<10 && sily_nove44(3)<10 && sily_nove44(4)<10 && sily_nove44(5)<10 && sily_nove44(6)<10|| ...
    sily_nove44(1)>=10 && sily_nove44(2)>=10 && sily_nove44(3)>=10 && sily_nove44(4)>=10 && sily_nove44(5)>=10 && sily_nove44(6)>=10

str_sily=['sila1 = ' num2str(sily_nove44(1), '%f');...
'sila2 = ' num2str(sily_nove44(2), '%f');...
'sila3 = ' num2str(sily_nove44(3), '%f');...
'sila4 = ' num2str(sily_nove44(4), '%f');...
'sila5 = ' num2str(sily_nove44(5), '%f');...
'sila6 = ' num2str(sily_nove44(6), '%f');];
else
 str_sily=('sily neze zobrazit');       
end
%--------regrece---------------------------------------------------
if m<0 && m12<0 ||  m>0 && m12>0
    str_sklon=['sklon6  = ' num2str(m, '%f');...
'sklon12 = ' num2str(m12, '%f');];  
end

if m<0 && m12>0
     str_sklon=['sklon6  = ' num2str(m, '%f');...
'sklon12 =  ' num2str(m12, '%f');];  
end

if m>0 && m12<0
     str_sklon=['sklon6  =  ' num2str(m, '%f');...
'sklon12 = ' num2str(m12, '%f');];
end
%-------pokles sily, MAV a RMS-----------------------------------------------
str_sklon_sily=['sklon_S =  ' num2str(m_sily, '%f')];
str_sklon_MAV=['sklon_M =  ' num2str(m_MAV, '%f')];
str_sklon_RMS=['sklon_R =  ' num2str(m_RMS, '%f')];
%--------vypishodnot------------------------------------------------

title('Přehled hodnot:','fontweight', 'bold', 'fontsize', 12)
text(0.05, 1, 'Střední amlituda:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.05, 0.95, str_MAV33, 'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')
text(0.05, 0.67, 'Průměr kvadrátů:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.05, 0.62, str_RMS33,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')
text(0.05, 0.34, 'Průměr síly:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.05, 0.29, str_sily,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')    
text(0.35, 1, 'Mediánová frekvence6:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.35, 0.95, str_Fmed33,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')    
text(0.35, 0.65, 'Mediánová frekvence12:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.35, 0.6, str_vysledky_osm3,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')    
text(0.7, 1, 'Střední frekvence:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.7, 0.95, str_Fmean33,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')  
text(0.7, 0.65, 'Sklon přímky:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.7, 0.6, str_sklon,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')      
 %  
text(0.7, 0.5, 'Sklon přímky síly:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.7, 0.45, str_sklon_sily,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')      
text(0.7, 0.35, 'Sklon přímky MAV:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.7, 0.3, str_sklon_MAV,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')      
text(0.7, 0.2, 'Sklon přímky RMS:', 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left', 'fontweight', 'bold')    
    text(0.7, 0.15, str_sklon_RMS,  'EdgeColor','black','LineWidth',2, 'fontsize', 10, 'verticalAlignment', 'top', 'horizontalAlignment', 'left')      
   
    grid off

%%
%------------------Eport do excelu----------------------------------
vysledky8={...
'sila1' sily_nove44(1);...
'sila2' sily_nove44(2);...
'sila3' sily_nove44(3);...
'sila4' sily_nove44(4);...
'sila5' sily_nove44(5);...
'sila6' sily_nove44(6);...
[] [];	...
'MAV1' MAV1;...
'MAV2' MAV2;...
'MAV3' MAV3;...
'MAV4' MAV4;...
'MAV5' MAV5;...
'MAV6' MAV6;...
[] [];	...
'RMS1' RMS1;...
'RMS2' RMS2;...
'RMS3' RMS3;...
'RMS4' RMS4;...
'RMS5' RMS5;...
'RMS6' RMS6;...
[] [];	...
'Fmean1' Fmean1;...
'Fmean2' Fmean2;...
'Fmean3' Fmean3;...
'Fmean4' Fmean4;...
'Fmean5' Fmean5;...
'Fmean6' Fmean6;...
[] [];	...
'Fmed1' Fmed1;...
'Fmed2' Fmed2;...
'Fmed3' Fmed3;...
'Fmed4' Fmed4;...
'Fmed5' Fmed5;...
'Fmed6' Fmed6;...
[] [];	...
'Fmed1' osm(1);...
'Fmed2' osm(2);...
'Fmed3' osm(3);...
'Fmed4' osm(4);...
'Fmed5' osm(5);...
'Fmed6' osm(6);...
'Fmed7' osm(7);...
'Fmed8' osm(8);...
'Fmed9' osm(9);...
'Fmed10' osm(10);...
'Fmed11' osm(11);...
'Fmed12' osm(12);...
[] [];	...
'sklon6' m;...
'sklon12' m12;...
[] [];	...
'sklon_Síly' m_sily;...
[] [];	...
'sklon_MAV' m_MAV;...
[] [];...
'sklon_RMS' m_RMS;...
[] []};

%xlswrite('Zesit1.xls',vysledky8) %nacteni do excelu

end


