from myhdl import block, Signal, delay, always, now import math # subsetsum analogon using "reversible computing" # OH 2018 cumultune = 0 TIMESCALE = 1e-3 SIMULATIONDURATION = 1e6 ALPHA = 1e-2 @block def SubsetsumAnalogon(tones_,harmonicdistortion_, targetsum_): tones = tones_ harmonicdistortion = harmonicdistortion_ # [a,b,c,..] = a*X + b*X^2 + c* X^3 + .... targetsum = targetsum_ clk = Signal(0) def setTones( tones_): tones = tones_ @always(delay(10)) def drive_clk(): clk.next = not clk @always(clk.posedge) def timedomain(): global cumultune t = now()*TIMESCALE x = 0 for tone in tones: x = x + math.sin(tone*t) y = 0 n = len(harmonicdistortion) for order in range(0,n): y = y + (harmonicdistortion[order])*math.pow(x,order+1) tuning = math.sin( targetsum * t ) * y + math.cos( targetsum * t ) * y #cumultune = (ALPHA)* tuning + (1.-ALPHA)*cumultune cumultune = cumultune + tuning # (1)timebase (2)unmixed # (3)distorted signal (4) power of tuning frequency (target detection) print("%g %g %g %g" % (t,x,y,cumultune)) return drive_clk, timedomain inst = SubsetsumAnalogon([ 31,11, 7],[1,1] , 17) inst.run_sim(SIMULATIONDURATION)