function Txt = message(L, Charspace, Bitspace)

  Nzero = 0;
  Nflips = 0;
  Bits = "";
  Txt = ">";
  
#  for i = 2 : 700
  for i = 2 : length(L)
    
    # Count +1/-1 sign changes
    if (L(i-1) * L(i) < 0)
      Nflips = Nflips + 1;
    endif
    
    if (L(i) != 0)
      Nzero = 0;
    else
      # Count zeros
      Nzero = Nzero + 1;

      # Detect the start of a new character
      if (Nzero > Charspace)
        if (length(Bits))
          Txt = [Txt char(bin2dec(Bits))];
          disp(Txt);
        endif
        Nzero = 0;
        Nflips = 0;
        Bits = "";
      endif

      # Detect the end of a single bit
      if (Nflips != 0 && Nzero > Bitspace)
        if (Nflips < 3)
          disp ('1');
          Bits = [Bits "1"];
        elseif (Nflips >= 3)
          disp ('0');
          Bits = [Bits "0"];
        else
          disp ('Error at')
          disp (i)
          disp (Nflips)
        endif
        Nflips = 0;
      endif
      
    endif      
    
  endfor

endfunction
