ldpc decode and sync working with no errors
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 30 Dec 2013 05:17:10 +0000 (05:17 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 30 Dec 2013 05:17:10 +0000 (05:17 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1349 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/ldpc.m
codec2-dev/octave/ldpcenc.m

index dfed5d45f8535f8a4b74ea4e5f07bf00ca3c59bc..917b7efa24ac90976c2702985ad8c05fd1b7e4cb 100644 (file)
@@ -23,12 +23,12 @@ endfunction
 % Gray coded QPSK modulation function\r
 \r
 function symbol = qpsk_mod(two_bits)\r
-    two_bits_decimal = sum(two_bits .* [1 2]); \r
+    two_bits_decimal = sum(two_bits .* [2 1]); \r
     switch(two_bits_decimal)\r
-        case (0) symbol =  1+j;\r
-        case (1) symbol = -1+j;\r
-        case (2) symbol =  1-j;\r
-        case (3) symbol = -1-j;\r
+        case (0) symbol =  1;\r
+        case (1) symbol =  j;\r
+        case (2) symbol = -j;\r
+        case (3) symbol = -1;\r
     endswitch\r
 endfunction\r
 \r
@@ -56,9 +56,30 @@ function frameout = insert_uw(framein, uw)
         pout += 2;\r
         luw -= 2;\r
     end\r
+endfunction\r
+\r
+% removes a unique word from a frame of bits.  The UW bits are spread\r
+% throughout the input frame 2 bits at a time.\r
+\r
+function frameout = remove_uw(framein, lvd, luw)\r
+\r
+    spacing = 2*lvd/luw;\r
+\r
+    frameout = [];\r
+\r
+    pin = 1; pout = 1;\r
+    while (luw)\r
+        %printf("pin %d pout %d luw %d  ", pin, pout, luw);\r
+        %printf("pin+spacing-1 %d lvd %d lframein: %d\n", pin+spacing-1, lvd, length(framein));\r
+        frameout(pout:pout+spacing-1) = framein(pin:pin+spacing-1);\r
+        pin  += spacing + 2; \r
+        pout += spacing;\r
+        luw  -= 2;\r
+    end\r
 \r
 endfunction\r
 \r
+\r
 % builds up a sparse QPSK modulated version version of the UW for use\r
 % in UW sync at the rx\r
 \r
index 9773e79f476d80b4c635fad8876c85c6ba5d4fa2..9d7dde0bd3af871dbc22068a5b4b227f3118bb3d 100644 (file)
@@ -27,6 +27,7 @@ mapping = 'gray';
 demod_type = 0;\r
 decoder_type = 0;\r
 max_iterations = 100;\r
+EsNo = 10;\r
 \r
 vocoderframesize = 52;\r
 nvocoderframes = 8;\r
@@ -58,8 +59,8 @@ for nn = 1: Nframes
 end\r
 fclose(fc);\r
 \r
-printf("framesize: %d data_bits_per_frame: %d code_bits_per_frame: %d\n", ...\r
-        framesize, code_param.data_bits_per_frame,  code_param.code_bits_per_frame);\r
+%printf("framesize: %d data_bits_per_frame: %d code_bits_per_frame: %d\n", ...\r
+%        framesize, code_param.data_bits_per_frame,  code_param.code_bits_per_frame);\r
 \r
 % rx simulation (separate later)\r
 \r
@@ -71,7 +72,7 @@ lpackedmodem = 72/8;
 mod_codeword = zeros(1, code_param.code_bits_per_frame/2);\r
 lmod_codeword = code_param.code_bits_per_frame/2;\r
 \r
-for m=1:16\r
+for m=1:8\r
 \r
     % read in one modem frame at a time\r
 \r
@@ -89,8 +90,28 @@ for m=1:16
     mod_codeword(1:lmod_codeword-length(mod_unpackedmodem)) = mod_codeword(length(mod_unpackedmodem)+1:lmod_codeword);\r
     mod_codeword(lmod_codeword-length(mod_unpackedmodem)+1:lmod_codeword) = mod_unpackedmodem;\r
 \r
-    look_for_uw(10*mod_codeword(1:length(mod_uw)), mod_uw)\r
+    uw_sync = look_for_uw(mod_codeword(1:length(mod_uw)), mod_uw);\r
+    if (uw_sync)\r
+        % force UW symbols as they are known (is this needed?)\r
+\r
+        % LDPC decode\r
+\r
+        detected_data = ldpc_dec(code_param, max_iterations, demod_type, decoder_type, mod_codeword, EsNo);\r
+\r
+        % unpack payload data, removing UW\r
+\r
+        vd_rx = remove_uw(detected_data(1:code_param.data_bits_per_frame), length(vd), length(uw));\r
+\r
+        % measure BER\r
+\r
+        error_positions = xor(vd, vd_rx);\r
+        Nerrs = sum(error_positions);\r
+        if Nerrs>0, fprintf(1,'x'),  else fprintf(1,'.'),  end\r
+\r
+        % save packed payload data to disk\r
+    end\r
 end\r
 \r
+fprintf(1,'\n')\r
 fclose(fc);\r
 \r