%%%%% cepstrum illustration

load mtlb;
y=mtlb;
NFFT=1024;
lifter=24;
lporder=4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y1=y(1000:1512);  
S_W = (abs(fft(y1,NFFT)).^2);
c_e = ifft(log(S_W));
S_Wplot=10*log10(abs(fft(y1,NFFT)).^2);

tc_e=c_e(1:lifter).*hamming(lifter);
C_W=10*log10(abs(fft(tc_e,NFFT)).^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;
subplot 221;
plot(y1./max(y1));
subplot 222
plot(S_Wplot(1:NFFT/2));
subplot 223
plot(c_e(2:NFFT/2));
%axis tight
subplot 224;
%plot(S_Wplot(1:NFFT/2));
%hold on;
plot((C_W(1:NFFT/2)),'r');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% LP illustration

figure;
subplot 221
ll=lpc(y1,lporder);
llf=log10(abs(fft(ll,NFFT)).^2);
plot(llf(1:NFFT/2)./max(llf));
subplot 222
llfactual=log10(abs(1./fft(ll,NFFT)).^2);
plot(llfactual(1:NFFT/2)./max(llfactual));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lporder = 8;

ll=lpc(y1,lporder);
llf=log10(abs(fft(ll,NFFT)).^2);

subplot 223
llfactual=log10(abs(1./fft(ll,NFFT)).^2);
plot(llfactual(1:NFFT/2)./max(llfactual));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lporder = 12;

ll=lpc(y1,lporder);
llf=log10(abs(fft(ll,NFFT)).^2);

subplot 224
llfactual=log10(abs(1./fft(ll,NFFT)).^2);
plot(llfactual(1:NFFT/2)./max(llfactual));






