
clear

k = 1:10;
n = 32;
t = 1:(2^12 - 2*n);  %time scale
b = 4;
rmse = zeros(1,10); %initialize rmse

rmsenum = 0;

x =cos((1:2^(12))*2*pi*64/2^13); %singal for frequencies of f*m
x = 0.3*x/max(abs(x));

%sound(x,frequency,n)
x2 = simplecodec6(x,b);
x1 = x(33:length(x2)+32)'; %trimmed down signal

error = (x1 - x2).^2; %difference squred

for i = 1:length(x2)
    rmsenum = rmsenum+error(i); %numeric rmse
end
rmse = sqrt(rmsenum/length(x2)); %rmse for each frequency


figure
plot(t(1:100),x1(1:100),'-r',t(1:100),x2(1:100),'-b') %plots a small section of the signal
legend('starting wave','new wave')
title(['f = 64'])


rmse

%So, my system runs for a maximum of 4 bits. It assigns the full 4 bits to
%values near the maximum of the wave, and assigns one bits to the values
%closest to 0. This allocates more data to larger values, and less data to
%the more uninteresting sections.