better comments in mrd4 encoder
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 23 Oct 2015 17:06:26 +0000 (17:06 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 23 Oct 2015 17:06:26 +0000 (17:06 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2469 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/fsk4.m

index 2b832b4c3ba57f62642ade77f33aeb912d2ee758..78f35cffad428d94a7ccf223ca560088fc9a1215 100644 (file)
@@ -154,19 +154,22 @@ function dat = bitreps(in,M)
   end
 endfunction
 
+% Minimal Running Disparity, 4 symbol encoder
+% This is a simple 1 bit to 1 symbol encoding for 4fsk modems built
+% on old fashoned FM radios.
 function syms = mrd4(bits)
   syms = zeros(1,length(bits));
   rd=0;
   lastsym=0;
   for n = (1:length(bits))
     bit = bits(n);
-    sp = 1+(bit*2.0);
-    [x,v] = min(abs([rd+sp rd-sp]));
+    sp = [1 3](bit); %Map a bit to a +1 or +3
+    [x,v] = min(abs([rd+sp rd-sp])); %Select +n or -n, whichever minimizes disparity
     ssel = [sp -sp](v);
-    if(ssel == lastsym)ssel = -ssel;endif
-    syms(n) = ssel;
-    rd = rd + ssel;
-    lastsym = ssel;
+    if(ssel == lastsym)ssel = -ssel;endif %never run 2 of the same syms in a row
+    syms(n) = ssel; %emit the symbol
+    rd = rd + ssel; %update running disparity
+    lastsym = ssel; %remember this symbol for next time
   end
 endfunction