! this uses u for time and t for the moving "current" time ! a simple discrete convolution ! Invest 1 dollar a day in internet stock, and each day a dollar loses half its value. ! There are two discrete functions: ! f(u) = 1 ! (signal) invest one dollar per day ! g(u) = (1/2)^u ! (weight) reduce value by half each day ! The discrete convolution, f*g, is the sum of the products, f(u) g(t-u) ! for current day, t, and time from u=0 to u=t. ! g(u) has values 1, 1/2, 1/4, 1/8, etc. ! On any given day, we have a sum of products. Suppose the day, t, is 2, ! and we look at each day from u=t or u=2, back to u=0. ! day 0: 1 = 1 ! day 1: 1/2 1 = 1.5 ! day 2: 1/4 1/2 1 = 1.75 ! day 3: 1/8 1/4 1/2 1 = 1.875 ! or more graphically ! 1 ! 1 1/2 ! 1 1/2 1/4 ! 1 1/2 1/4 1/8 ! -------------------> u ! 0 1 2 3 ! t ! If the current day, t, is 2: ! On day u=2, the new dollar is multiplied by 1, which is g(t-u) or g(0), so its value is 1. ! The day u=1 dollar is multiplied by 1/2, which is g(t-u) or g(1), so its value is now 1/2. ! The day u=0 dollar is multiplied by 1/4, which is g(t-u) or g(2), so its value is now 1/4. ! g(0) or 1, is the weight for day 2, and g(2), or 1/4 is the weight for day 0. ! So the weighting function, g, is reversed in time to find the daily products. ! The products on day 2 are f(2)*g(2-2) = 1*1, f(2)*g(2-1) = 1*1/2, f(2)*g(2-0) = 1*1/4 ! The sum of products on day 2 is 1 + 1/2 + 1/4 = 1.75. ! The points on the convolution curve are the sums of the products to each day: ! (0,1), (1,1.5), (2,1.75), (3,1.875) ! The discrete convolution curve records the history of the sums of the products. ! Using continuous functions, the products form a continuous curve, and ! the convolution curve records the history of the area under the product curve. !! File: ConvolutionBack !! January 13, 2003 Hubert Hohn PUBLIC PCFlag,Mac5Flag,M68KFlag,UnixFlag,xmax,ymax PUBLIC toolLft,toolRgt,toolBas,toolTop,toolhdr,toolHgt,toolWid ! tool boundaries PUBLIC winLft,winRgt,winBas,winTop,winHgt,winWid ! window PUBLIC workLft,workRgt,workBas,workTop,workMidx ! work area PUBLIC black,drkgry,drkmid,midgry,litmid,litgry,white PUBLIC red,yellow,green,cyan,blue,magenta,pink,colorscheme PUBLIC planeclr,gridclr,rimclr,axisclr,axislabelclr,titleclr,rightsclr PUBLIC numberlineclr,slotdrkclr,slotlgtclr,slideclr PUBLIC largefonts, title$, SLUmode ! DECLARE DEF quitWithin,infoWithin LET toolHgt= 560 LET toolWid= 780 LET window$= "d'Arbeloff Interactive Math Project" LET colorscheme= 0 LET title$ = "Convolution: Looking Back" SUB ThisProgram CALL ConvolutionBack CLEAR END SUB !! --------------------------------------------------------- !! ------ Start TB4 Mac Header and Subs ------ !LET M68KFlag = 1 !LIBRARY "MacTools*", "HHLib.trc" !ASK PIXELS winWid,winHgt !LET winLft= 0 !LET winTop= 0 !LET winRgt= winWid-1 !LET winBas= winHgt-1 !SET WINDOW 0,winRgt,winBas,0 !CALL Palette !CLEAR ! !CALL ToolPanel !CALL ThisProgram ! !END !EXTERNAL ! !MODULE Mac4Parts ! SUB SetTextFont(font,size,style$) ! CALL MacTextFont(font) ! CALL MacTextSize(size) ! CALL MacTextFace(style$) ! END SUB ! ! SUB StringWidth(sw$,sl) ! DECLARE DEF MacStringWidth ! LET sl= MacStringWidth(sw$) ! END SUB ! ! SUB SetLineWeight(wgt) ! CALL MacPenSize(wgt,wgt) ! END SUB ! ! SUB BoxDisk(Lft,Rgt,Bas,Top) ! CALL MacPaintOval(Lft,Rgt,Bas,Top) ! END SUB !END MODULE !! --- End TB4 Mac Header and Subs --- !!--------------------------------------------------------- !!--- Start TB5 Cross-Platform header and subs --- LIBRARY "c:\TB Gold 51a\TBLibs\TrueCtrl.trc" ! windows LIBRARY "c:\TB Gold 51a\TBLibs\HHLib.trc" !LIBRARY ":TBLibs:TrueCtrl.trc" ! macintosh !LIBRARY "HHLib.trc" ! PUBLIC WinID DECLARE PUBLIC OBJM_SET,OBJM_SYSINFO LET winHgt= toolHgt LET winWid= toolWid DIM values(1) CALL TC_Init CALL Object(OBJM_SYSINFO,WinID,"MACHINE",system$,values()) IF system$="MAC" then LET Mac5Flag= 1 ELSE IF system$="WIN32" then LET PCFlag = 1 END IF CALL TC_SetUnitsToPixels ! 5.1 and up needs this CALL TC_GetScreenSize(scrnLft,scrnRgt,scrnBas,scrnTop) LET winLft= int((scrnRgt-scrnLft-winWid)/2) LET winRgt= winLft+winWid-1 LET winTop= int((scrnBas-scrnTop-winHgt)/2) + 10 LET winBas= winTop+winHgt-1 CALL TC_Win_Create (WinID,"TITLE",winLft,winRgt,winBas,winTop) LET values(1)= 2 CALL Object(OBJM_SET, WinID, "TYPE", "", values()) IF PCFlag=1 then ! kill dithering LET values(1)= 1 CALL Object(OBJM_SET, WinID, "SOLID MIX", "", values()) END IF LET values(1)= 0 CALL TC_SetRect(WinID,winLft,winRgt,winBas,winTop) CALL TC_Win_SetTitle(WinID,window$) CALL TC_Show(WinID) SET MODE "COLORSTANDARD" ASK PIXELS winWid,winHgt ! must follow set mode LET winLft= 0 LET winTop= 0 LET winRgt= winWid-1 LET winBas= winHgt-1 SET WINDOW 0,winRgt,winBas,0 CALL Palette IF PCFlag=1 then LET values(1)= 0 ! now force solid colors CALL Object(OBJM_SET, WinID, "SOLID MIX", "", values()) CALL TC_Win_RealizePalette(WinID) ! some PCs need this CALL TC_Win_SetFont(WinID,"arial",9,"plain") CALL StringWidth("0",sw) IF sw>7 then LET largefonts=1 else LET largefonts=0 END IF CALL TC_Win_Switch(WinID) CALL ToolPanel CALL ThisProgram CALL SetTextFont(1,12,"bold") ! now shut down and clean up LET quit$= "click the mouse or press a key to close..." CALL PlotTextCJ(workmidx,(workbas+worktop)/2,quit$,yellow) CALL TC_CleanUp END EXTERNAL MODULE TB5Parts SUB StringWidth(sw$,sl) DECLARE PUBLIC WinID LET sl= StrWidth(WinID,sw$) END SUB SUB SetLineWeight(wgt) DECLARE PUBLIC OBJM_SET DECLARE PUBLIC WinID DIM values(1) LET values(1)= wgt CALL Object(OBJM_SET,WinID, "WIDTH", "", values()) END SUB SUB SetTextFont(font,size,style$) DECLARE PUBLIC WinID,Mac5Flag,PCFlag,largefonts IF Mac5Flag=1 then SELECT CASE font CASE 4 LET font$= "Courier" CASE 16 LET font$= "Times" CASE else LET font$= "Geneva" END SELECT ELSE IF PCFlag=1 then IF largefonts=1 then IF size<12 then LET size= 6 ELSE IF size=14 then LET size= 10 ELSE IF size=18 then LET size= 12 ELSE IF size=24 then LET size= 14 ELSE IF size=12 then LET size= 8 ELSE LET size= round(72/96 * size * .8) END IF ELSE IF size<12 then LET size= 7 ELSE IF size=14 then LET size= 12 ELSE IF size=12 then LET size= 9 ELSE IF size=18 then LET size= 14 ELSE IF size=24 then LET size= 18 ELSE LET size= round(72/96 * size) END IF END IF SELECT CASE font CASE 4 LET font$= "Courier New" CASE 16 LET font$= "Times New Roman" CASE else LET font$= "Verdana" END SELECT END IF IF style$= "normal" then LET style$= "plain" CALL TC_Win_SetFont(WinID,font$,size,style$) END SUB SUB BoxDisk(Lft,Rgt,Bas,Top) BOX DISK Lft,Rgt,Bas,Top END SUB END MODULE ! --- End TB5 Cross-platform header and subs --- !! --------------------------------------------------------- !! --- Start Unix Header and Subs --- !Library "HHLib.unix" !LET UnixFlag= 1 !ASK PIXELS winWid,winHgt !LET winLft= 0 !LET winTop= 0 !LET winRgt= winWid-1 !LET winBas= winHgt-1 !SET WINDOW 0,winRgt,winBas,0 !CALL Palette ! !CALL ToolPanel !CALL ThisProgram ! !END !EXTERNAL ! !MODULE UnixParts ! SHARE CharWidth ! ! SUB SetTextFont(font,size,style$) ! LET font$= "-adobe-courier-" ! IF style$= "normal" then ! LET style$= "medium-r-normal--" ! ELSE ! LET style$= "bold-r-normal--" ! END IF ! IF size=9 then ! LET size$= str$(10) ! ELSE ! LET size$= str$(size) ! END IF ! LET test= SetFont(font$&style$&size$&"*") ! ! IF size=9 then ! LET CharWidth= 6 ! ELSE IF size=12 then ! numeric output - axis labels ! LET CharWidth= 7 ! ELSE IF size=14 then ! rare ! LET CharWidth= 8 ! ELSE IF size=18 then ! rare ! LET CharWidth= 10 ! END IF ! END SUB ! ! SUB StringWidth(sw$,sl) ! string width in pixels ! ! LET sl= StrWidth(sw$) ! LET chars= len(sw$) ! LET sl = chars*CharWidth ! END SUB ! ! SUB SetLineWeight(wgt) ! ! CALL PenSize(wgt,wgt) ! END SUB ! ! SUB BoxDisk(Lft,Rgt,Bas,Top) ! CALL Fill_Circle(Lft,Rgt,Bas,Top) ! END SUB !END MODULE !! ------ End of TB Unix Header and Subs ------ ! ----------------------------------------------------------- ! *** SUB ConvolutionBack DECLARE PUBLIC worklft,workrgt,workbas,worktop,workmid ! work area DECLARE PUBLIC black,drkgry,drkmid,midgry,litmid,litgry,white DECLARE PUBLIC red,yellow,green,cyan,blue,magenta,colorscheme DECLARE PUBLIC slideclr,axislabelclr,true,false DECLARE DEF InfoWithin, QuitWithin ! ------- help screen array ------- DIM info$(1:1) MAT READ info$ DATA "Information on convolution" ! ------- color ------- LET sigClr = red LET wgtClr = green LET cnvClr = cyan LET prdClr = yellow LET areaClr= blue SET COLOR MIX(areaClr) 0,.5,.4 ! remix blue fill ! ---------- Utility functions ----------- DECLARE DEF clamp,roundn,e ! --- functions and parameters ----------- ! SUB SetConstants(signum,wgtnum, a,b,k) ! SELECT CASE signum ! CASE 1 ! SELECT CASE wgtnum ! CASE 1 ! CASE 2 ! CASE 3 ! CASE 4 ! END SELECT ! CASE 2 ! SELECT CASE wgtnum ! CASE 1 ! CASE 2 ! CASE 3 ! CASE 4 ! END SELECT ! CASE 3 ! SELECT CASE wgtnum ! CASE 1 ! CASE 2 ! CASE 3 ! CASE 4 ! END SELECT ! CASE 4 ! SELECT CASE wgtnum ! CASE 1 ! CASE 2 ! CASE 3 ! CASE 4 ! END SELECT ! END SELECT ! END SUB ! ---------------------------------------- !For reference: the LTI differential operators with these weight functions are: !w1: Lx = x' + ax !w2: Lx = x' !w3: Lx = x" + b^2 x !w4: Lx = x" + 2a x' + a^2 x !The convolution equals the solution to Lx = f(t) with rest initial cond's: !x(0) = 0 in the first order cases !x(0) = 0, x'(0) = 0 in the second order cases. !Here are the convolutions: (notation: c^2 = a^2 + b^2) !f1*w1(t) = (1/c^2)(a sin(bt) - b cos(bt) + b e^{-at}). !f1*w2(t) = (1/b)(1 - cos(bt)) !f1*w3(t) = (-1/2b) t cos(bt) + (1/2b^2) sin(bt). !f1*w4(t) = ((a^2-b^2)/c^4) sin(bt) - (2ab/c^4) cos(bt) + ((b/c^2)t + 2ab/c^4) e^{-at} !f2*w1(t) = (1/a)(1 - e^{-at}). !f2*w2(t) = t !f2*w3(t) = (1/b)(1 - cos(bt)). !f2*w4(t) = (1/a^2) - (t/a + 1/a^2) e^{-at} !f3*w1(t) = (1/a)(1 - e^{-at}) for t < t0 ! (1/a)(1 - e^{-a(t0)}) e^{-a(t-t0)) for t > t0 !f3*w2(t) = t for t < t0 ! t0 for t > t0 !f3*w3(t) = (1/b)(1 - cos(bt)) for t < t0 ! (1/b)(1 - cos(b t0)) cos(b(t-t0)) + (1/b) sin(b t0) sin(b(t-t0)) for t > t0 !f3*w4(t) = (1/a^2) - (t/a + 1/a^2) e^{-at} for t < t0 ! (c1(t-t0) + c0) e^{-a(t-t0)} for t > t0 ! where c1 = (1/a)(1 - e^{-a t0}) ! c0 = (1/a^2) - (t0/a + 1/a^2) e^{-a t0). !f4*w1(t) = (1/h^2) (a sin(wt) - w cos(wt) + w e^{-at}). !f4*w2(t) = (1/w) (1 - cos(wt)) !f4*w3(t) = (1/(w^2-b^2)) (sin(wt) - (w/b) sin(bt)) !f4*w4(t) = ((a^2-w^2)/h^4) sin(wt) - (2aw/h^4) cos(wt) + ((w/h^2)t + 2aw/h^4) e^{-at} ! where h^2 = a^2 + w^2. DIM CnvVals(1:1) !f4(t) = sin(wt) where w differs from b. !The "b"s here are intentionally the same. You took b = 2, and w = 1, and !this looks good. SUB SetConstants(signum,wgtnum, a,b,k) IF signum=4 then LET a= 1 LET b= 1 LET k= 2 ! haynes used w ! ELSE IF signum=3 and wgtnum=5 then ! LET a= 0.2 ! LET b= 2 ! LET k= 1 ! haynes used w ELSE LET a= 1 LET b= 1 LET k= 1 END IF END SUB ! ----- weights ----- !w1(t) = e^{-at} (t > 0) !w2(t) = 1 (t > 0) !w3(t) = (1/b) sin(bt) (t > 0) !w4(t) = t e^{-at} (t > 0) DEF w(wgtnum,t) IF t>=0 then SELECT CASE wgtnum CASE 1 LET w= e^(-a*t) CASE 2 LET w= 1 CASE 3 LET w= 1/b * sin(b*t) CASE 4 LET w= t * e^(-a*t) CASE 5 LET w= 1/b * sin(b*t) * e^(-a*t) END SELECT ELSE LET w= 0 END IF END DEF !w5(t) = (1/b) e^{-at} sin(bt) ! !(a and b will have the same values as they did for the other weights.) ! ----- signals ----- !f1(t) = sin(bt) !f2(t) = 1 !f3(t) = 1 for 0 < t < 3 !f4(t) = sin(kt) where k differs from b. LET f3Step= 3 DEF f(signum,t) IF signum<>3 then IF t<0 then LET f= 0 ELSE SELECT CASE signum CASE 1 LET f= sin(b*t) CASE 2 LET f= 1 CASE 4 LET f= sin(k*t) END SELECT END IF ELSE IF signum=3 then IF t>=0 and t t0 ! ! Let d = (a^2+b^2-w^2)^2 + 4a^2w^2 . !f4*w5(t) = (1/d) ((a^2+b^2-w^2) sin(wt) - 2aw cos(wt) + e^{-at} (2aw cos(bt) + (a^2-b^2+w^2)(w/b) sin(bt))) DEF cnv(signum,wgtnum,t) LET c2 = a^2 + b^2 LET c4 = c2^2 LET h2 = a^2 + k^2 LET h4 = h2^2 IF t<0 then LET cnv= 0 ELSE SELECT CASE signum CASE 1 !f1*w1(t) = (1/c^2)(a sin(bt) - b cos(bt) + b e^{-at}) !f1*w2(t) = (1/b)(1 - cos(bt)) !f1*w3(t) = (-1/2b) t cos(bt) + (1/2b^2) sin(bt) !f1*w4(t) = ((a^2-b^2)/c^4) sin(bt) - (2ab/c^4) cos(bt) + ((b/c^2)t + 2ab/c^4) e^{-at} !f1*w5(t) = (1/(a^4 + 4a^2b^2)) ((a^2) sin(bt) - 2ab cos(bt) + e^{-at} (2ab cos(bt) + (a^2) sin(bt))) SELECT CASE wgtnum CASE 1 LET cnv = (1/c2) * (a*sin(b*t) - b*cos(b*t) + b*e^(-a*t)) CASE 2 LET cnv = (1/b)*(1-cos(b*t)) CASE 3 LET cnv = (-1/(2*b))*t*cos(b*t) + 1/(2*b^2)*sin(b*t) CASE 4 LET cnv = ((a^2-b^2)/c4)*sin(b*t) - (2*a*b/c4)*cos(b*t) + ((b/c2)*t + 2*a*b/c4)*e^(-a*t) CASE 5 LET cnv = (1/(a^4 + 4*a^2*b^2)) * ((a^2)*sin(b*t) - 2*a*b*cos(b*t) + e^(-a*t) * (2*a*b*cos(b*t)+(a^2)*sin(b*t))) END SELECT CASE 2 !f2*w1(t) = (1/a)(1 - e^{-at}). !f2*w2(t) = t !f2*w3(t) = (1/b)(1 - cos(bt)). !f2*w4(t) = (1/a^2) - (t/a + 1/a^2) e^{-at} SELECT CASE wgtnum CASE 1 LET cnv = (1/a) * (1-e^(-a*t)) CASE 2 LET cnv = t CASE 3 LET cnv = (1/b) * (1-cos(b*t)) CASE 4 LET cnv = (1/a^2) - (t/a + 1/a^2)*e^(-a*t) CASE 5 LET cnv = (1/(a^2+b^2)) * (1 - e^(-a*t) * (cos(b*t) + (a/b)*sin(b*t))) END SELECT CASE 3 !f3*w1(t) = (1/a)(1 - e^{-at}) for t < t0 ! (1/a)(1 - e^{-a(t0)}) e^{-a(t-t0)) for t > t0 !f3*w2(t) = t for t < t0 ! t0 for t > t0 !f3*w3(t) = (1/b)(1 - cos(bt)) for t < t0 ! (1/b)(1 - cos(b t0)) cos(b(t-t0)) + (1/b) sin(b t0) sin(b(t-t0)) for t > t0 !f3*w4(t) = (1/a^2) - (t/a + 1/a^2) e^{-at} for t < t0 ! (c1(t-t0) + c0) e^{-a(t-t0)} for t > t0 ! where c1 = (1/a)(1 - e^{-a t0}) ! c0 = (1/a^2) - (t0/a + 1/a^2) e^{-a t0). !f3*w5(t) = (1/(a^2+b^2)) (1 - e^{-at} (cos(bt) + (a/b) sin(bt))) for t < t0 ! = e^{a(t-t0)} (c0 cos(b(t-t0)) + ((a(c0) + c1)/b) sin(b(t-t0))) for t > t0 ! where c0 = (1/(a^2+b^2)) (1 - e^{-a(t0)} (cos(b(t0)) + (a/b) sin(b(t0)))) ! c1 = (1/b) e^{-a(t0)} sin(b(t0)) SELECT CASE wgtnum CASE 1 IF t0" DATA "1 0 0) !w2(t) = 1 (t > 0) !w3(t) = (1/b) sin(bt) (t > 0) !w4(t) = t e^{-at} (t > 0) !w4(t) = (1/b) sin(bt) e^{-at} (t > 0) DECLARE PUBLIC m2Lft, m2Rgt, m2Bas, m2Top, m2Equation, m2Prefix$, m2Menu1$() DECLARE PUBLIC m2Name$, m2tClr DECLARE DEF m2Within MAT redim m2Menu1$(1:4) MAT READ m2Menu1$ DATA "e^[-u]" DATA "1" DATA "sin(u)" DATA "u e^[-u]" ! DATA "sin(u) e^[-u]" LET m2Prefix$ = "g(u) = " LET m2Lft = m1Lft LET m2Top = m1Top + 115 LET m2Name$ = "Weight" LET m2tClr = wgtClr LET m2Equation= 1 SUB m2Init CALL m2ResetMenu(m2State) END SUB ! -------- end of design and layout --------- ! --- set default parameters --- LET m1State = 0 LET m2State = 0 LET m1Equation= 1 ! signals LET m2Equation= 1 ! weights LET signum = m1Equation LET wgtnum = m2Equation LET tm = 0 ! --- initialize screen --- CALL InitScreen CALL m1InitMenu1 CALL m2InitMenu1 CALL SetTimer SUB InitScreen BOX CLEAR workLft,workRgt,workBas,workTop CALL SetConstants(signum,wgtnum, a,b,k) CALL w1SetBounds(signum,wgtnum) CALL w1Init CALL w2Init CALL w3Init CALL w4Init CALL t1Init CALL t1SetValue(a,b,tm) CALL h1Init CALL m1Init CALL m2Init CALL BackGroundGraphs CALL DrawGraphs(tm) END SUB ! ------------------ Event manager ---------------- DO CALL MouseDown(mx,my,ms) IF w1wWithin(mx,my)=true or w2wWithin(mx,my)=true or w3wWithin(mx,my)=true then DO ! drag t within a plane GET MOUSE: mx,my,ms LET mx = clamp(mx,w3Lft,w3Rgt) LET tm = w3Fncx(mx) CALL h1Action LOOP until ms=3 ELSE IF h1Within(mx,my)=true then ! h1 - t slider IF myoldtm then CALL h1Mark(tm) CALL t1SetValue(a,b,tm) CALL DrawGraphs(tm) LET oldtm= tm END IF END SUB SUB h1Animate LET start= tm FOR tm= start to h1fRgt step 2*pixstep CALL h1Action GET MOUSE: mx,my,ms ! check for mouse event IF ms=2 then ! stop on mousedown CALL h1AnimStopButtonUp(ms) ! get mouse up EXIT FOR END IF CALL Delay(1/30) NEXT tm CALL h1StopButtonClear END SUB ! --- menu event --- SUB ChangeEquation CALL h1SetZero CALL w1SetBounds(signum,wgtnum) CALL w1Init CALL SetConstants(signum,wgtnum, a,b,k) CALL BackGroundGraphs CALL DrawGraphs(tm) END SUB ! --- Tool specific drawing and typesetting routines --- ! ------------------------------------------------------ ! --- response to real-time change --- SUB DrawT(wx,wBas,wTop) ! moving vertical rule at t CALL PlotLine(wx,wTop+1, wx,wBas-1, litgry) END SUB SUB DrawGraphs(tm) ! --- plane 3 - overlay weight from tm back to zero CALL w3ShowGraphLayer LET wxTm= w3Wndx(tm) CALL DrawT(wxTm,w3Bas,w3Top) ! vertical rule SET COLOR wgtClr ! now the weight FOR wx= w3Lft to wxTm LET u = w3Fncx(wx) LET wgt= w(wgtnum,tm-u) LET wy = w3Wndy(wgt) PLOT wx,wy NEXT wx ! --- plane 2 - product curve and area CALL w2ShowGridLayer FOR u= tm to 0 step -pixstep LET u = round(u,3) ! time LET y1 = f(signum,u) ! signal LET y2 = w(wgtnum,tm-u) ! weight LET y = y1*y2 ! product CALL w2MathToPixels(u,y, wx,wy) CALL PlotPoint(wx,wy,prdclr) ! product curve value ! now area within product curve if there is space IF wyw2y0+2 then CALL PlotLine( wx,w2y0+1, wx,wy-2, areaClr) END IF END IF NEXT u CALL DrawT(wxTm,w2Bas,w2Top) ! vertical rule ! --- plane 1 - top plane - convolution curve line and point CALL w1ShowGraphLayer LET yi= cnv(signum,wgtnum,tm) ! find convolution y ! CALL w1NumericalIntegral(tm,yi) ! for debugging LET wy= w1Wndy(yi) IF wy0 LET wy= w3Wndy(1) PLOT w3Lft,w3y0; w3x0,w3y0; w3x0,wy; w3Rgt,wy ELSE IF signum=3 then ! step to one for 0<=t<=3 CALL w2MathToPixels(f3step,1,wRgt,wy) LET wRgt= w3Wndx(f3step) LET wy = w3Wndy(1) PLOT w3Lft,w3y0; w3x0,w3y0; w3x0,wy; wRgt,wy; wRgt,w3y0; w3Rgt,w3y0 ELSE FOR wx= w3Lft to w3Rgt LET u = w3Fncx(wx) LET wy= w3Wndy(f(signum,u)) PLOT wx,wy; NEXT wx PLOT END IF END SUB ! --- plane 4 - weight function --- SUB Plane4Graph ! lower left plane - weight function SET COLOR wgtClr FOR wx= w4x0+1 to w4Rgt LET u = w4Fncx(wx) LET wy= w4Wndy(w(wgtnum,u)) PLOT wx,wy; NEXT wx PLOT END SUB ! ------------------------------------ ! --- numerical routines for debugging and absence of closed form solutions --- SUB DrawNumericalIntegral CALL w1ShowGridLayer SET COLOR cnvClr CALL NumericalIntegral CALL w1KeepGraphLayer END SUB SUB w1NumericalIntegral(t,sum) ! returns one convolution value at t LET sum= 0 FOR u= w1fLft to t step pixstep LET y1 = f(signum,u) LET y2 = w(wgtnum,t-u) LET y = y1*y2 LET area= y*pixstep LET sum = sum+area NEXT u ! LET sum= sum*pixstep END SUB SUB NumericalIntegral ! draws a graph of the convolution SET COLOR litgry ! FOR wx= w1Lft to w1Rgt ! use stored values ! LET wy= CnvVals(wx) ! PLOT wx,wy ! NEXT wx FOR wx= w1Lft to w1Rgt LET x = w1Fncx(wx) CALL w1NumericalIntegral(x,sum) LET wy= w1Wndy(sum) PLOT wx,wy; NEXT wx PLOT END SUB SUB IntegralValues ! stores numerical integration for quik access MAT redim CnvVals(w1Lft:w1Rgt) FOR wx= w1Lft to w1Rgt LET x = w1Fncx(wx) CALL w1NumericalIntegral(x,sum) LET wy= w1Wndy(sum) LET CnvVals(wx)= wy NEXT wx END SUB END SUB ! ---- end of backward convolution code --------------------------------