%% ECE 146B-Lab2-4PAM DECODE

function [estimated_bits] = fourPAMDecode(received_const)
    %account for gain contributed by receive filter
    received_const = received_const/4;
    %assign all zeros to entire column first (corresponsds to +3)
    fourPam13 = zeros(length(received_const),2);  
    %convert 1 to [0 1]
    map2 = (real(received_const) < 2 & real(received_const) > 0);
    fourPam13(:,2) = map2 + fourPam13(:,2);
    %convert -1 to [1 1]
    map3 = (real(received_const)) > -2 & (real(received_const)) < 0;    
    fourPam13(:,1) = map3 + fourPam13(:,1);
    fourPam13(:,2) = map3 + fourPam13(:,2);
    %convert -3 to [1 0]
    map4 = real(received_const) < -2; 
    fourPam13(:,1) = map4 + fourPam13(:,1);
    %interleave the two column vectors of fourPam13
    estimated_bits = reshape(fourPam13',length(received_const)*2,1);

end