Jul-18-2018, 02:48 AM
here is the recursive code working:
back when i first made this program in assembler (for both IBM 360/370 mainframes and 6502 in an Apple II) i realized by watching the data (codes) fly by real fast, that they was a better way to generate all the codes for a given scheme. i did implement that and generated a lot of schemes. from that i found an even more optimal way to select good schemes without generating codes that was based on Pascal's Triangle and some variations of that (adding more than just 2 numbers from the line above). but really the 28 4 7 1 scheme is all we need (the 15 3 5 1 scheme for 4-bit streams).
the above embedded source code is also available at http://ipal.net/free/signalcoding.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import division, generators, print_function, with_statement r"""Generate signal codings for the multiple interval signal system. file signalcoding.py purpose generate signal codings for the multiple interval signal system email 10054452614123394844460370234029112340408691 """ #-------#-------#-------#-------#-------#-------#-------#-------#-------#-------# __license__ = r""" Copyright © 2018, by Phil D. Howard - all other rights reserved Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. The author may be contacted by decoding the number 10054452614123394844460370234029112340408691 (provu igi la numeron al duuma) """ #-------#-------#-------#-------#-------#-------#-------#-------#-------#-------# try: from d import sl, pr, pv except: def sl(*a,**o): return def pr(*a,**o): return def pv(*a,**o): return try: from printobject import print_object except: def print_object(*a,**o): return 0 try: from intx import intx except: intx = int #-------#-------#-------#-------#-------#-------#-------#-------#-------#-------# def depth(): from inspect import currentframe d = -2 f = currentframe() while 'f_back' in dir(f): d += 1 f = f.f_back return d def eprint(*a,**o): if 'file' not in o: o['file']=stderr f=o['file'] r=print(*a,**o) if o else print(*a) f.flush() return r # sum is the accumulated sum of all previous loops, starts with 0 # xlist is the indexed list keeping each loop value, starts with [] # limit is the limit of sum of loop indexes, length of the code sum # sss is a 3-tuple (start,stop,step) passed as args to range() to # control each loop at each recursive depth def nestloop(sum,xlist,limit,sss): deep = depth()-1 xlist.append(0) for num in range(*sss): xlist[-1] = num sn = sum+num if sn==limit: print('{:>4d}:'.format(deep),' '.join([repr(x) for x in xlist])) stdout.flush() break if sn>limit: break nestloop(sn,xlist,limit,sss) xlist.pop(-1) return #-------#-------#-------#-------#-------#-------#-------#-------#-------#-------# def main(args): errors = 0 cname = args.pop(0) if len(args) > 4: return 'too many arguments - max 4 - '\ 'need: [ limit (8) [ start (1) [ last (start+1) [ step (1) ] ] ] ]' names = ('limit','start','last','step') nums = [] for x,arg in enumerate(args): if x > 3: eprint('argument',repr(1+x),'['+names[x]+']','is an extra argument') errors += 1 continue try: n = intx(arg) except: eprint('argument',repr(1+x),'['+names[x]+']','is','('+repr(arg)+')', 'not a valid number') errors += 1 nums.append(n) if len(nums) == 0: nums += [15,3,5,1] if len(nums) == 1: nums += [3,5,1] if len(nums) == 2: nums += [nums[1]+1,1] if len(nums) == 3: nums += [1] limit, start, last, step = nums print('limit =',repr(limit)) print('start =',repr(start)) print(' last =',repr(last)) print(' step =',repr(step)) stdout.flush() if errors: return 'aborting due to '+repr(errors)+' errors' nestloop(0,[],limit,(start,last+1,step)) return 0 #-------#-------#-------#-------#-------#-------#-------#-------#-------#-------# if __name__ == '__main__': from sys import argv, stderr, stdout if bytes == str: BrokenPipeError, FileNotFoundError = IOError, OSError try: result=main(argv) except BrokenPipeError: result = 99 except KeyboardInterrupt: stderr.flush() print() result = 98 stderr.flush() stdout.flush() if result is 0 or result is None or result is True: exit(0) if result is 1 or result is False: exit(1) if isinstance(result, str): print(result, file=stderr) exit(2) try: exit(int(result)) except ValueError: print(str(result), file=stderr) exit(3) except TypeError: exit(4) # EOFthe 4 command arguments default to 15 3 5 1 if none are given. this means to generate all the groups of numbers in the range(3,6,1) that add up to a fixed total of 15. this represents a single coding scheme to modulate data over an analog medium such as as a keyed radio carrier. this design works by having varying lengths of time between on/off transitions. there are 18 such codes as the output of this program shows. 2 of them would be used for idling (3 3 3 3 3) and (5 5 5) and the other 16 used to encode 4 bits of data. the coding scheme with lengths 4 through 7 for a total of 28 has 277 possible combinations which has plenty of code combinations to use 2 for idling (4 4 4 4 4 4 4) and (7 7 7 7) and 256 of the remaining 275 for 8 bits of data. many more schemes can be made, all with a fixed total over all of the codes for each scheme. by limiting the inter-transition length to numbers where the longest is no longer than twice the shortest, it is possible to reconstruct the original data level waveform from a smoothed level analog waveform that can be had through a narrow bandwidth frequency filter. the information part of the waveform is maintained in that narrow range as defined by the shortest and longest intervals. the up/down positive/negative state of the signal does not matter. all the information is in the timing between transitions, eliminating concern for the DC bias of the signal, which will average out to zero with scrambled or encrypted data.
back when i first made this program in assembler (for both IBM 360/370 mainframes and 6502 in an Apple II) i realized by watching the data (codes) fly by real fast, that they was a better way to generate all the codes for a given scheme. i did implement that and generated a lot of schemes. from that i found an even more optimal way to select good schemes without generating codes that was based on Pascal's Triangle and some variations of that (adding more than just 2 numbers from the line above). but really the 28 4 7 1 scheme is all we need (the 15 3 5 1 scheme for 4-bit streams).
the above embedded source code is also available at http://ipal.net/free/signalcoding.py
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.