
function [v_dem] = demapeador(ms,n_mod_tipo)

v_dem=[];
load ENC2.mat
load ENC4.mat
load ENC16.mat
load ENC64.mat

switch n_mod_tipo
    case 1
        %CODIFICADOR BPSK
        for i=1:1:length(ms)
             pc=ms(i);
             a(1)=abs(pc-s2(1));
             a(2)=abs(pc-s2(2));
             ma=min(a);
             switch ma
                 case a(1)
                     v_dem=[v_dem 0];
                 case a(2)
                     v_dem=[v_dem 1];
             end
        end
        
    case 2
        %CODIFICADOR QPSK
         for i=1:1:length(ms)
             pc=ms(i);
             a(1)=abs(pc-s4(1));
             a(2)=abs(pc-s4(2));
             a(3)=abs(pc-s4(3));
             a(4)=abs(pc-s4(4));
             ma=min(a);
             switch ma
                 case a(1)
                     v_dem=[v_dem c4(1,1:2)];
                 case a(2)
                     v_dem=[v_dem c4(2,1:2)];
                 case a(3)
                     v_dem=[v_dem c4(3,1:2)];
                 case a(4)
                     v_dem=[v_dem c4(4,1:2)];
             end
         end
        
    case 4
        %CODIFICADOR 16-QAM
        for i=1:1:length(ms)
            pc=ms(i);
             a(1)=abs(pc-s16(1));
             a(2)=abs(pc-s16(2));
             a(3)=abs(pc-s16(3));
             a(4)=abs(pc-s16(4));
             a(5)=abs(pc-s16(5));
             a(6)=abs(pc-s16(6));
             a(7)=abs(pc-s16(7));
             a(8)=abs(pc-s16(8));
             a(9)=abs(pc-s16(9));
             a(10)=abs(pc-s16(10));
             a(11)=abs(pc-s16(11));
             a(12)=abs(pc-s16(12));
             a(13)=abs(pc-s16(13));
             a(14)=abs(pc-s16(14));
             a(15)=abs(pc-s16(15));
             a(16)=abs(pc-s16(16));
             ma=min(a);
             switch ma
                 case a(1)
                     v_dem=[v_dem c16(1,1:4)];
                 case a(2)
                     v_dem=[v_dem c16(2,1:4)];
                 case a(3)
                     v_dem=[v_dem c16(3,1:4)];
                 case a(4)
                     v_dem=[v_dem c16(4,1:4)];
                 case a(5)
                     v_dem=[v_dem c16(5,1:4)];
                 case a(6)
                     v_dem=[v_dem c16(6,1:4)];
                 case a(7)
                     v_dem=[v_dem c16(7,1:4)];
                 case a(8)
                     v_dem=[v_dem c16(8,1:4)];
                 case a(9)
                     v_dem=[v_dem c16(9,1:4)];
                 case a(10)
                     v_dem=[v_dem c16(10,1:4)];
                 case a(11)
                     v_dem=[v_dem c16(11,1:4)];
                 case a(12)
                     v_dem=[v_dem c16(12,1:4)];
                 case a(13)
                     v_dem=[v_dem c16(13,1:4)];
                 case a(14)
                     v_dem=[v_dem c16(14,1:4)];
                 case a(15)
                     v_dem=[v_dem c16(15,1:4)];
                 case a(16)
                     v_dem=[v_dem c16(16,1:4)];
             end %end del switch ma
        end  %end del for 16 qam
        
        
    case 6
    %CODIFICADOR 64-QAM
    for i=1:1:length(ms)
            pc=ms(i);
             a(1)=abs(pc-s64(1));
             a(2)=abs(pc-s64(2));
             a(3)=abs(pc-s64(3));
             a(4)=abs(pc-s64(4));
             a(5)=abs(pc-s64(5));
             a(6)=abs(pc-s64(6));
             a(7)=abs(pc-s64(7));
             a(8)=abs(pc-s64(8));
             a(9)=abs(pc-s64(9));
             a(10)=abs(pc-s64(10));
             a(11)=abs(pc-s64(11));
             a(12)=abs(pc-s64(12));
             a(13)=abs(pc-s64(13));
             a(14)=abs(pc-s64(14));
             a(15)=abs(pc-s64(15));
             a(16)=abs(pc-s64(16));
             a(17)=abs(pc-s64(17));
             a(18)=abs(pc-s64(18));
             a(19)=abs(pc-s64(19));
             a(20)=abs(pc-s64(20));
             a(21)=abs(pc-s64(21));
             a(22)=abs(pc-s64(22));
             a(23)=abs(pc-s64(23));
             a(24)=abs(pc-s64(24));
             a(25)=abs(pc-s64(25));
             a(26)=abs(pc-s64(26));
             a(27)=abs(pc-s64(27));
             a(28)=abs(pc-s64(28));
             a(29)=abs(pc-s64(29));
             a(30)=abs(pc-s64(30));
             a(31)=abs(pc-s64(31));
             a(32)=abs(pc-s64(32));
             a(33)=abs(pc-s64(33));
             a(34)=abs(pc-s64(34));
             a(35)=abs(pc-s64(35));
             a(36)=abs(pc-s64(36));
             a(37)=abs(pc-s64(37));
             a(38)=abs(pc-s64(38));
             a(39)=abs(pc-s64(39));
             a(40)=abs(pc-s64(40));
             a(41)=abs(pc-s64(41));
             a(42)=abs(pc-s64(42));
             a(43)=abs(pc-s64(43));
             a(44)=abs(pc-s64(44));
             a(45)=abs(pc-s64(45));
             a(46)=abs(pc-s64(46));
             a(47)=abs(pc-s64(47));
             a(48)=abs(pc-s64(48));
             a(49)=abs(pc-s64(49));
             a(50)=abs(pc-s64(50));
             a(51)=abs(pc-s64(51));
             a(52)=abs(pc-s64(52));
             a(53)=abs(pc-s64(53));
             a(54)=abs(pc-s64(54));
             a(55)=abs(pc-s64(55));
             a(56)=abs(pc-s64(56));
             a(57)=abs(pc-s64(57));
             a(58)=abs(pc-s64(58));
             a(59)=abs(pc-s64(59));
             a(60)=abs(pc-s64(60));
             a(61)=abs(pc-s64(61));
             a(62)=abs(pc-s64(62));
             a(63)=abs(pc-s64(63));
             a(64)=abs(pc-s64(64));
             ma=min(a);
             switch ma
                 case a(1)
                     v_dem=[v_dem c64(1,1:6)];
                 case a(2)
                     v_dem=[v_dem c64(2,1:6)];
                 case a(3)
                     v_dem=[v_dem c64(3,1:6)];
                 case a(4)
                     v_dem=[v_dem c64(4,1:6)];
                 case a(5)
                     v_dem=[v_dem c64(5,1:6)];
                 case a(6)
                     v_dem=[v_dem c64(6,1:6)];
                 case a(7)
                     v_dem=[v_dem c64(7,1:6)];
                 case a(8)
                     v_dem=[v_dem c64(8,1:6)];
                 case a(9)
                     v_dem=[v_dem c64(9,1:6)];
                 case a(10)
                     v_dem=[v_dem c64(10,1:6)];
                 case a(11)
                     v_dem=[v_dem c64(11,1:6)];
                 case a(12)
                     v_dem=[v_dem c64(12,1:6)];
                 case a(13)
                     v_dem=[v_dem c64(13,1:6)];
                 case a(14)
                     v_dem=[v_dem c64(14,1:6)];
                 case a(15)
                     v_dem=[v_dem c64(15,1:6)];
                 case a(16)
                     v_dem=[v_dem c64(16,1:6)];
                 case a(17)
                     v_dem=[v_dem c64(17,1:6)];
                 case a(18)
                     v_dem=[v_dem c64(18,1:6)];
                 case a(19)
                     v_dem=[v_dem c64(19,1:6)];
                 case a(20)
                     v_dem=[v_dem c64(20,1:6)];
                 case a(21)
                     v_dem=[v_dem c64(21,1:6)];
                 case a(22)
                     v_dem=[v_dem c64(22,1:6)];
                 case a(23)
                     v_dem=[v_dem c64(23,1:6)];
                 case a(24)
                     v_dem=[v_dem c64(24,1:6)];
                 case a(25)
                     v_dem=[v_dem c64(25,1:6)];
                 case a(26)
                     v_dem=[v_dem c64(26,1:6)];
                 case a(27)
                     v_dem=[v_dem c64(27,1:6)];
                 case a(28)
                     v_dem=[v_dem c64(28,1:6)];
                 case a(29)
                     v_dem=[v_dem c64(29,1:6)];
                 case a(30)
                     v_dem=[v_dem c64(30,1:6)];
                 case a(31)
                     v_dem=[v_dem c64(31,1:6)];
                 case a(32)
                     v_dem=[v_dem c64(32,1:6)];
                 case a(33)
                     v_dem=[v_dem c64(33,1:6)];
                 case a(34)
                     v_dem=[v_dem c64(34,1:6)];
                 case a(35)
                     v_dem=[v_dem c64(35,1:6)];
                 case a(36)
                     v_dem=[v_dem c64(36,1:6)];
                 case a(37)
                     v_dem=[v_dem c64(37,1:6)];
                 case a(38)
                     v_dem=[v_dem c64(38,1:6)];
                 case a(39)
                     v_dem=[v_dem c64(39,1:6)];
                 case a(40)
                     v_dem=[v_dem c64(40,1:6)];
                 case a(41)
                     v_dem=[v_dem c64(41,1:6)];
                 case a(42)
                     v_dem=[v_dem c64(42,1:6)];
                 case a(43)
                     v_dem=[v_dem c64(43,1:6)];
                 case a(44)
                     v_dem=[v_dem c64(44,1:6)];
                 case a(45)
                     v_dem=[v_dem c64(45,1:6)];
                 case a(46)
                     v_dem=[v_dem c64(46,1:6)];
                 case a(47)
                     v_dem=[v_dem c64(47,1:6)];
                 case a(48)
                     v_dem=[v_dem c64(48,1:6)];
                 case a(49)
                     v_dem=[v_dem c64(49,1:6)];
                 case a(50)
                     v_dem=[v_dem c64(50,1:6)];
                 case a(51)
                     v_dem=[v_dem c64(51,1:6)];
                 case a(52)
                     v_dem=[v_dem c64(52,1:6)];
                 case a(53)
                     v_dem=[v_dem c64(53,1:6)];
                 case a(54)
                     v_dem=[v_dem c64(54,1:6)];
                 case a(55)
                     v_dem=[v_dem c64(55,1:6)];
                 case a(56)
                     v_dem=[v_dem c64(56,1:6)];
                 case a(57)
                     v_dem=[v_dem c64(57,1:6)];
                 case a(58)
                     v_dem=[v_dem c64(58,1:6)];
                 case a(59)
                     v_dem=[v_dem c64(59,1:6)];
                 case a(60)
                     v_dem=[v_dem c64(60,1:6)];
                 case a(61)
                     v_dem=[v_dem c64(61,1:6)];
                 case a(62)
                     v_dem=[v_dem c64(62,1:6)];
                 case a(63)
                     v_dem=[v_dem c64(63,1:6)];
                 case a(64)
                     v_dem=[v_dem c64(64,1:6)];
             end %end del switch ma
    end %fin del for de 64 qam
end %end de switch mod
    
        

