#vectorMathLibrary_2023FJun30_py.py #by David at ColeCanada.com #date: 2021FJun30 # #purpose: Library of functions to process a wave stored as a vector of # positive samples with or without timestamps # # import math def makeVectorVIX(nRange,type = "square"): # Purpose: generates VIX waveforms in a complex list vector # By: David@ColeCanada.com # Date: 2023FJun29 # Tested: 2023FJun29 # NOTE: If the number of samples is N, # the list of samples will not include a sample at time 0. # eg. a sample #1 of a sawtooth (max value of 1) will NOT be 0, # it will be 1/N # # used to generate a list of samples for 1 cycle of a Wave in a Vector # valid types are "toSin90", "toSin360","complex-toSin90", "complex-toSin360", # "square", "unary", "complex-square" and "complex-unary" # "sawtooth" and "complex-sawtooth". # Version 1 added "sawtooth" waveform # # eg VIXdegListA=makeVectorVIX(360,) # produces [0,1,2,3,4,5, . . . . 359] #print("waveformIn:",type) #if type=="toSin90":print ("type is:",type) typeList=[ \ "sawtooth","complex-sawtooth", \ "square","complex-square", \ "toSin360","complex-toSin360", \ "toSin90","complex-toSin90", \ "unary","complex-unary"] if typeList.count(type)==0: print("Err001 wave type not in:",typeList) print("... set to unary waveform") #rType = type(nRange) #print("rType:",rType) #if type(nRange) == 'int' : # print("Err003 range must be integer") # print(" used 8") # nRange = 8 isRangeOK=True if nRange == 0 or nRange > 10000 : isRangeOK=False dohrange=1.0 * nRange if dohrange < 1.0 : isRangeOK=False intRange=1 # intRange will be assigned next if isRangeOK==False: print ("Err002 nr line 51, range is invalid or exceeds 10000") print(" using nRange:8") #nRange = int(8) intRange= int(8) else: #print("at 56 nRange:",nRange) intRange=nRange #print("intRange:",intRange) thisList=[] #empty list dX=1./(intRange) #print("in:",thisList) for iterN in range(intRange): iterN=iterN+1 #print("degN:",degN) if type=="toSin90" or type=="complex-toSin90": maxDegree=90 #print("set_maxDegree:",maxDegree) degrees=iterN*maxDegree/intRange rads=(degrees)*2*math.pi/360 #print ("after for, type is:",type, "rads is",rads) #end if if type=="toSin360" or type=="complex-toSin360": maxDegree=360 #print("set_maxDegree:",maxDegree) degrees=iterN*maxDegree/intRange rads=(degrees)*2*math.pi/360 #end if #thisList.append(sin(rad) value=1.0 if type=="toSin90" or type=="complex-toSin90": value=math.sin(rads) if type=="toSin360" or type=="complex-toSin360": value=math.sin(rads) if type=="unary" or type=="complex-unary": value=1.0 if type=="sawtooth" or type=="complex-sawtooth": value=iterN*dX #end if if type=="square" or type=="complex-square": if iterN