function [ frame_out] = decode_P_frame( frame_encoded, ref_past, B_size, MB_size, Q, u, v )

[Y_ref, chroma_ref] = RGB_to_YCbCr(ref_past);

enc_luma = frame_encoded.encoded_luma;
enc_chroma = frame_encoded.encoded_chroma;

Nmb = size(enc_luma)/MB_size;

Y_mb = mat2cell(enc_luma, repmat(MB_size,1,Nmb(1)), repmat(MB_size,1,Nmb(2)));
Y_decoded = cell(size(Y_mb));

chroma_mb = mat2cell(enc_chroma, repmat(MB_size/2,1,Nmb(1)), repmat(MB_size/2,1,Nmb(2)),2);
chroma_decoded = cell(size(chroma_mb));

for m = 1 : Nmb(1)
    for n = 1 : Nmb(2)
        Y_inv_q = inverse_quantize( Y_mb{m,n}, MB_size, B_size, Q );
        chroma_inv_q = inverse_quantize( chroma_mb{m,n}, MB_size, B_size, Q );
        Y_decoded{m,n} = motion_compensation( Y_inv_q, Y_ref, u(m,n), v(m,n), m, n  );
        chroma_decoded{m,n} = motion_compensation( chroma_inv_q, chroma_ref, u(m,n), v(m,n), m, n  );  
  

    end
end
Y_decoded = cell2mat(Y_decoded);
chroma_decoded = cell2mat(chroma_decoded);

frame_out = YCbCr_to_RGB( Y_decoded, chroma_decoded );


end

