len = 1.5;
x = [261.6, 349.2, 440, 523.25];
for bits = 1:12
    orig = zeros(1,len*2^13);
    for i=1:length(x)
        orig = orig + (((1:len*2^13)/2^13) > ((i-1)*(len-0.5)/(length(x)+1))) .* (0.3*cos((1:len*2^13)*2*pi*x(i)/2^13));
    end
    orig = 0.3 * orig / max(abs(orig));
    decoded = prob2codec(orig, 32, bits);
    err(bits) = sqrt(sum((decoded - orig).^2)/(len*2^13));
end

scatter(1:12, err);
hold on
plot(1:12, 0.055 * 0.533 .^ (1:12));
hold off
set(gca,'yscale','log');
title({'Quantization bits vs RMSE', 'Trendline: rmse = 0.055 * 0.533^b'});
err