function [S,F,T,mod_S,faz_S]=spektralnianalyza(x,Fs,wintime,steptime,power,zobraz)  
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%Funkce pro výpocet spekra vzorku
%--------------------------------------------------------------------------
%Bc. árka Sobotková                                               2013
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
winpts=ceil(wintime*Fs/1000);
steppts=ceil(steptime*Fs/1000);

NFFT=2^(ceil(log(winpts)/log(2)));
WINDOW=hamming(winpts);
NOVERLAP=winpts-steppts;
SAMPRATE=Fs;

[S,F,T]=specgram(x,512,SAMPRATE,WINDOW,NOVERLAP);

if power
    mod_S=abs(S).^2;
    faz_S=180*angle(S)/pi;
    
else
     mod_S=abs(S);
    faz_S=180*angle(S)/pi;
    
end

mod_S_dB=20*log10(abs(S)+eps);
[m,n]=size(S);
f=linspace(0,Fs/2,m);
t=linspace(0,Fs/2,n);

if zobraz==1
    
    figure;
    subplot(2,1,1);
    imagesc(t,f,mod_S_dB);
    axis xy;
    colormap(jet)
    title('modul');
    xlabel('time(s)')
    ylabel('frequency(Hz)')
    subplot(2,1,2);
    imagesc(t,f,faz_S);
    axis xy;
    colormap(jet)
    title('Faze');
    xlabel('time(s)')
    ylabel('frequency(Hz)')
       
    % ____spektralni histogram
    
   [osa,hist,dist]=histogram_2D(mod_S_dB);
   figure; 
   subplot(2,1,1);
   surf(f,osa,hist);
    axis xy;
    colormap(jet)
    title('rozlozeni pst');
    xlabel('frequency(Hz)')
    ylabel('V [dB]')
    subplot(2,1,2);
    subplot(2,1,2);
    surf(f,osa,dist);
    axis xy;
    colormap(jet)
    title('distribucni funkce');
    xlabel('frequency(Hz)')
    ylabel('V [dB')
       
    
end