clear all
close all
clc
%% Porovnání LPC a FFT
prompt = 'Pocet nastroju k porovnani? ';
pp = input(prompt);
if pp>6
   error('Max. 6 vzorku')
end
formanty=cell(pp,1);
fmat=cell(pp,1);
dBPmat=cell(pp,1);
NazevVzorku=cell(pp,1);
lpcmat=zeros(24000,pp); %(Pri jine fvz nez 48kHz zmenit 24000 na fvz/2!)
famat=zeros(24000,pp);
%% Výpočty
for i = 1 : pp
[horna,cesta] = uigetfile('*.wav');
NazevVzorku{i,1} = horna;
[x,fvz]=audioread(fullfile(cesta,horna));
x = x(:,1);
%Výpočet LPC
ls=length(x);
koef=lpc(x,40);
[h,fa]=freqz(1,koef,fvz/2,fvz);
h=20*log10(abs(h)/ls);
%FFT
[peaky,pozice,~,dBP]=FFThodnoty(x,fvz);
peaky=peaky(1:5);
norm=h(pozice(1))-peaky(1);
h=h-norm;
f=(0:(length(dBP)-1))*fvz/ls;
lpcmat(:,i)=h;
fmat{i,1}=f;
dBPmat{i,1}=dBP;



%% Vykreslení
figure(1)
if pp == 1
    spa=1;
    spb=1;
elseif pp == 2
    spa=1;
    spb=2;
elseif pp > 2 && pp < 5
    spa=2;
    spb=2;
elseif pp >= 5 
    spa=3;
    spb=2;
end
for k = 1:pp
subplot(spa,spb,k);
plot(fa,(lpcmat(:,k)),'color','r','LineWidth',2.5);
hold on
plot(fmat{k,1},dBPmat{k,1},'color','b')
grid on
xlim([0 6000])
ylim([-100 -30])
xlabel('Kmitočet [Hz]','FontSize',13)
ylabel('Modul [dB]','FontSize',13)
title(NazevVzorku{k,1},'FontSize',13)
legend('LPC','FFT')
set(gca,'FontSize',11)
end
set(gcf,'units','normalized','position',[0.25,0.15,0.5,0.7])

