clear;
for i = 1:50
f1 = 10;
f2 = 12;
f3 = 15;
Fs = 8192;
a = cos(2*pi*44*f1*(1:Fs*3)/Fs)+cos(2*pi*44*f2*(1:Fs*3)/Fs)...
+cos(2*pi*44*f3*(1:Fs*3)/Fs);
a=0.3*a/max(abs(a));
bit=i;
b = simplecodec(a,bit,Fs);
c = windowcodec(a,bit,Fs);
a = a(33:length(a)-32);
if i ==2
audiowrite('aminor_n_windowing.wav',b,Fs)
audiowrite('aminor_wndowing.wav',c,Fs)
figure(1)
plot(a,'k-','LineWidth',2)
hold on;
plot(b,'r-','LineWidth',2)
plot(c,'b-','LineWidth',2)
title(sprintf('Pre- and post-compressed signal: bit rate = %i, A-minor chord',i),...
'FontSize',14)
grid on
xlabel('Time(samples)')
ylabel('Amplitude (unitless)')
legend('Original signal','Compressed (no windowing)','Compressed (windowing)','Location','northeastoutside')
axis([0 100 -.3 .3])
hold off;
end
%Root-mean-square
RMSE1(i) = sqrt( sum( (a(:)-b(:)).^2) / numel(b) );
RMSE2(i) = sqrt( sum( (a(:)-c(:)).^2) / numel(c) );
end
figure(2)
semilogy(RMSE1,'b-.','LineWidth',2)
hold on
grid on
semilogy(RMSE2,'r-.','LineWidth',2)
title(sprintf('RMS error, A-minor chord',bit),'FontSize',14)
xlabel('Bit rate')
ylabel('RMSE error')
legend('Without windowing','With windowing')
hold off;