t = 0:1/fs:5-1/fs;
xToModel = 0.5*sin(2*pi*440*t); % definition of signal to be processed
% xToModel = x;
xpower = ones(1,length(xToModel));
ymodel = zeros(1,length(xToModel));

for n = 1:N
    xpower = xToModel.^n;
    ypower = filter(gs(n,:),1,xpower);
    ymodel = ymodel + ypower;
end
%% vykresleni grafu 

real = audioread('440HzSS13polovicni.wav');
real = real(20001:20000+length(t));
figure(1); % casovy prubeh modelu
plot(t, ymodel,'black');
title('sweptsine');
xlabel('èas [s]');
axis([0.4 0.41 -0.5 0.5])
figure(2); % casovy prubeh realu
plot(t,real,'black');
title('real');
xlabel('èas [s]');
axis([0.4 0.41 -0.5 0.5])
figure(3); % spektrum modelu
frqAxeSS = 0:fs/length(ymodel):fs-1/length(ymodel);
outputSpektrum = 10*log10(abs(fft(ymodel)./(length(ymodel))));
plot(frqAxeSS, outputSpektrum,'black');
title('sweptsine');
axis([0 48000 -80 0]);
xlabel('frekvence [Hz]');
ylabel('amplituda [dB]');
figure(4); % spektrum realu
frqAxeReal = 0:fs/length(real):fs-1/length(real);
realSpektrum = log10(abs(fft(real)./(length(real))));
ofset = 0; 
frqAxeReal = frqAxeReal + ofset*ones(1,length(frqAxeReal));
plot(frqAxeReal, 10*realSpektrum,'k');
title('real');
axis([0 48000 -80 0]);
xlabel('frekvence [Hz]');
ylabel('amplituda [dB]');
% audiowrite('pi440modelHalf.wav', ymodel, fs);