clear
%x=cos((1:T*Fs)*2*pi*64*f/Fs);         % test signal
%x=x+cos((1:4096)*2*pi*64*5/Fs);
%T = 0.5, f = 64,

k = 1:10;
f = 64.*k;
n = 32;
t = 1:(2^12 - 2*n);  %time scale
rmse = zeros(1,10); %initialize rmse
for m = 1:10
    rmsenum = 0;
    
    x =cos((1:2^(12))*2*pi*f(m)/2^13); %singal for frequencies of f*m
    x = 0.3*x/max(abs(x));
    
    %sound(x,frequency,n)
    x2 = simplecodec(x,f);
    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(m) = 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*',num2str(m)])
end

rmse

%Odds have almost all the same rmse 0.7375 +/- 0.0003, evens have an rmse pattern of 4, 8 =
%0.5, and 2, 6 = 0.92. 

%So, the reformed singal is close, but doesn't match incredibly well on the evens, but the odds are muhc closer, differing by
%bairly a thousandth.

%0.0021    0.0095    0.0017    0.0091    0.0011    0.0097    0.0016    0.0095    0.0011    0.0089

%Sounds become higher pitched in both cases, though the sin wave is
%slightly... subdued or muffled.