%% ECE 146B-Lab2-QPSK DECODE

function [estimated_bits] = qpskDecode(received_const)
    
    %assign all zeros to entire column first (corresponsds to +1+j)
    QPSK1j = zeros(length(received_const),2);  
    %convert 1-j to [0 1]
    mapQuad2 = (real(received_const)) > 0 & (imag(received_const)) < 0;
    QPSK1j(:,2) = mapQuad2 + QPSK1j(:,2);
    %convert -1-j to [1 1]
    mapQuad3 = (real(received_const)) < 0 & (imag(received_const)) < 0;    
    QPSK1j(:,1) = mapQuad3 + QPSK1j(:,1);
    QPSK1j(:,2) = mapQuad3 + QPSK1j(:,2);
    %convert -1+j to [1 0]
    mapQuad4 = (real(received_const)) < 0 & (imag(received_const)) > 0;   
    QPSK1j(:,1) = mapQuad4 + QPSK1j(:,1);
    %interleave the two column vectors of QPSK1j
    estimated_bits = reshape(QPSK1j',length(received_const)*2,1);

end