function F=seminar_gitara(ime_dat)

 close all
 clear 

trashold=0.35;

% ulazni signal
%[x, fs] = wavread(ime_dat);
%[x, fs] = wavread('tito01');
% [x, fs] = wavread('E2');
 [x, fs] = wavread('brasilian1');
 %[x, fs] = wavread('brasilian2');
% [x, fs] = wavread('rock');
 
x = x(1:8:length(x),1); % decimiranje s 8


T = 1/fs*8;             
t = [0:length(x)-1]' * T;  
 
a3 = scal2frq(1, 'cmor32-1', T) / 440; % a3 tone (440 Hz)
 
%              F#,  F,  E, D#,  D, C#,  C,  B, A#,  A, G#, G
%        2.^([ -9, -8, -7, -6, -5, -4, -3, -2, -1, 0 , 1 , 2 ]/12) * frek_a
step = 1;
octave = a3 * 2.^([-9:step:2+(1/step-1)*step]/12);   % Octave=3
 
scales = [octave 2*octave 4*octave 8*octave(1:3)];
frequencies = scal2frq(scales, 'cmor32-1', T); 
 
%racunanje  CWT
X = cwt(x, scales, 'cmor32-1');

X=abs(X);
I_max=max(max(X));
I_min=min(min(X));
X=(X-I_min)/(I_max-I_min);
X_tr=X>trashold;        %trashold rezultata

%--------------------------------------------------------------------------
% prikaz CWT 
figure, h=imagesc(t, frequencies, abs(X)); ylabel('Hertza'), xlabel('sekundi'),
set(get(h, 'Parent'), 'YDir', 'normal')
set(get(h, 'Parent'), 'YScale', 'log')

oct = a3 * 2.^([-9:2]/12);   % Octave=3
fre = fliplr(scal2frq([oct 2*oct 4*oct 8*oct(1:3)], 'cmor32-1', T));
set(get(h, 'Parent'), 'YTick', fre)
grid
grid minor

[y_labele, tonovi]=radi_labele(fre);

set(gca,'YTickLabel',y_labele)


% prikaz trasholdirane CWT
figure, h=imagesc(t, frequencies, abs(X_tr)); ylabel('Hertza'), xlabel('sekundi'),
set(get(h, 'Parent'), 'YDir', 'normal')
set(get(h, 'Parent'), 'YScale', 'log')

oct = a3 * 2.^([-9:2]/12);   % Octave=3
fre = fliplr(scal2frq([oct 2*oct 4*oct 8*oct(1:3)], 'cmor32-1', T));
set(get(h, 'Parent'), 'YTick', fre)
grid
%grid minor

[y_labele, tonovi, akordi]=radi_labele(fre);

set(gca,'YTickLabel',y_labele)



%--------------------------------------------------------------------------
%popravak X_tr
X_tr=popravak(X,X_tr,frequencies,fs,1/15,1/17,0);


% prikaz prepravljene trasholdirane CWT
figure; h=imagesc(t, frequencies, abs(X_tr)); ylabel('Hertza'), xlabel('sekundi'),
set(get(h, 'Parent'), 'YDir', 'normal')
set(get(h, 'Parent'), 'YScale', 'log')

oct = a3 * 2.^([-9:2]/12);   % Octave=3
fre = fliplr(scal2frq([oct 2*oct 4*oct 8*oct(1:3)], 'cmor32-1', T));
set(get(h, 'Parent'), 'YTick', fre)
grid
grid minor

[y_labele, tonovi]=radi_labele(fre);

set(gca,'YTickLabel',y_labele)


%-----------------------------------------------------
%crtanje tonova na vrat gitare, izrada animacije

h=figure;
h=crtaj_vrat(h);


N=5; %tocaka u sekundi
index=round( 1:fs/8/N:length(X) );
for i=1:length(index)
    t_ind(i)=t(index(i));
end

for i=1:length(index)   %pregled po vremenu
    ton_txt=[' '];
    chord_tr=[];
    for j=1:39          %pregled po tonovima
        x_kor=tonovi{j}.polje;
        y_kor=7-tonovi{j}.zica;
        
        [tmp,ind]=sort(x_kor);
        if X_tr(40-j,index(i))>0
            ton_txt=[ton_txt tonovi{j}.ime '   '];
            chord_tr=[chord_tr j];
            for k=1:1%length(x_kor)
                plot(x_kor(ind(k)),y_kor(ind(k)),'o','MarkerEdgeColor','k',...
                                    'MarkerFaceColor','r',...
                                    'MarkerSize',10);
                hold on;
            end
        end
    end
    
    %trazenje akorda 
    dosta=0;
    for k=1:length(akordi)
        if dosta==0
            uvjeti=ones(1,5);
            ton=akordi{k}.tonovi;
            for m=1:length(ton)
                uvjeti(m)=~isempty( find(chord_tr==ton(m)) );
            end
            
            uvjeti_svi=1;
            for m=1:length(ton)
                uvjeti_svi=uvjeti_svi & uvjeti(m);
            end
            if uvjeti_svi
                ton_txt=[ton_txt ' ( ' akordi{k}.ime ' )'];
                dosta=1;
            end
        end
    end
   
    ton_vect{i}=ton_txt;
    %ispis vremena, tonova i akorda
    ispis=sprintf('Vrijeme= %2.2f s',t(index(i)) );
    text(2,-1,ispis,...
     'HorizontalAlignment','left')
    text(2,-2,['Tonovi: ' ton_txt],...
     'HorizontalAlignment','left')
 
    hold off;
    F(i)=getframe;
    h=crtaj_vrat(h);
end

%ton_vect=vektor za ispis tonova u vremenu na X_tr grafu

figure; hold on;
axis([-2 t_ind(end)+2 -0.5 4])
t_v=0:ceil(t_ind(end));
set(gca, 'XTick', t_v)
set(gca,'XTickLabel',{' '})
set(gca,'YTickLabel',{' '})

text(-1,0.25,'t[s]','HorizontalAlignment','left')
text(-1,1.5,'tonovi (akordi)','HorizontalAlignment','left','Rotation',90)
for i=1:length(t_v)
    text(i-1,0.25,num2str(t_v(i)),'HorizontalAlignment','left')
end
for i=1:length(index);
    txt=ton_vect{i};
    if ~isempty(txt)
        text(t_ind(i),0.5,txt,'HorizontalAlignment','left','Rotation',90)
    end
end
plot([-1.5 ceil(t_ind(end))+0.5],[0.5 0.5],'k','LineWidth',3)
plot([-1.5 ceil(t_ind(end))+0.5],[0 0],'k','LineWidth',3)
plot([-0.2 -0.2],[0 3],'k','LineWidth',3)


h=figure;
h=crtaj_vrat(h);
movie(F,1,3)
    

