!! File: ConvolutionForeward !! January 7, 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 Ahead" SUB ThisProgram CALL Convolution 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 ------ ! ----------------------------------------------------------- ! *** Foreward Convolution SUB Convolution 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 ! --- remix colors --- SET COLOR MIX( 9) 0,.8,0 ! green SET COLOR MIX(10) 0,.8,1 ! cyan ! --- Help Screen Array --- DIM info$(1:1) MAT READ info$ DATA "Information on convolution" ! ---------- Utility functions --- DECLARE DEF clamp,roundn,e ! --- Functions and Parameters --- LET a = log(2) LET b = 2 LET c = sqr(a^2 + b^2) LET a2 = a^2 LET b2 = b^2 LET b4 = b2^2 LET c2 = a^2 + b^2 LET c4 = c2^2 LET ra = 1/a LET ra2= 1/a2 LET rb = 1/b LET h = 1/2 DEF f(t) ! signal SELECT CASE signum CASE 0 LET f = 1 CASE 1 LET f = e^(-a*t) CASE 2 LET f = 1 + cos(b*t) END SELECT END DEF DEF w(t) ! weight SELECT CASE wgtnum CASE 0 LET w = 1 CASE 1 LET w = e^(-a*t) CASE 2 LET w = t CASE 3 LET w = ra*(1-e^(-a*t)) CASE 4 LET w = t*e^(-a*t) END SELECT END DEF DEF cnv(t) ! t less than u SELECT CASE signum CASE 0 SELECT CASE wgtnum CASE 0 LET cnv = t CASE 1 LET cnv = ra - ra*e^(-a*t) CASE 2 LET cnv = t^2/2 CASE 3 LET cnv = -ra2 + ra*t + ra2*e^(-a*t) CASE 4 LET cnv = ra2 - (ra2 + ra*t) * e^(-a*t) END SELECT CASE 1 SELECT CASE wgtnum CASE 0 LET cnv = ra - ra*e^(-a*t) CASE 1 LET cnv = t*e^(-a*t) CASE 2 LET cnv = -ra2 + ra*t + ra2*e^(-a*t) CASE 3 LET cnv = ra2 - (ra2 + ra*t) * e^(-a*t) CASE 4 LET cnv = (t^2/2) * e^(-a*t) END SELECT CASE 2 SELECT CASE wgtnum CASE 0 LET cnv = t + (1/b)*sin(b*t) CASE 1 LET cnv = ra - ((2*a + ra*b2)/c2)*e^(-a*t) + (a/c2)*cos(b*t) + (b/c2)*sin(b*t) CASE 2 LET cnv = (1/b2) + h*t^2 - (1/b2)*cos(b*t) CASE 3 LET cnv = -ra2 + ra*t - (1/c2)*cos(b*t) + (a/(b*c2))*sin(b*t) + ((2*a2 + b2)/(c2*a2))*e^(-a*t) CASE 4 LET cnv = ra2 + ((a2-b2)/c4)*cos(b*t) + (2*a*b/c4)*sin(b*t) - ((2*a2 + b2 + (b4/a2))/c4)*e^(-a*t) - ((2*a + (b2/a))/c2)*t*e^(-a*t) END SELECT END SELECT END DEF DEF future(t,u) ! t greater than u LET c0 = cnv(u) SELECT CASE wgtnum CASE 0 LET future = c0 CASE 1 LET future = c0 * e^(-a*(t-u)) CASE 2 SELECT CASE signum CASE 0 LET c1 = u CASE 1 LET c1 = ra - ra*e^(-a*u) CASE 2 ! LET c1 = u + (1/b)*cos(b*u) LET c1 = u + rb*sin(b*u) END SELECT LET future = c0 + c1*(t-u) CASE 3 ! 4th weight function SELECT CASE signum CASE 0 LET c1 = ra - ra*e^(-a*u) CASE 1 LET c1 = u*e^(-a*u) CASE 2 LET c1 = ra + (a/c2)*cos(b*u) + (b/c2)*sin(b*u) - ((2*a2+b2)/(a*c2))*e^(-a*u) END SELECT LET future = c0 + (c1/a)*(1-e^(-a*(t-u))) CASE 4 SELECT CASE signum CASE 0 LET c1 = u*e^(-a*u) CASE 1 LET c1 = (u-a*h*u^2) * e^(-a*u) CASE 2 LET c1 = ((b^3 - a2*b)/c2^2)*sin(b*u) + (2*a*b2/c2^2)*cos(b*u) - (2*a*b2/c4)*e^(-a*u) + ((2*a2 + b2)/c2)*u*e^(-a*u) END SELECT LET future = (c0+(c1+a*c0)*(t-u)) * e^(-a*(t-u)) END SELECT END DEF ! --- Graphing plane parameters and methods LET wwid = 480 ! multiples of 48 (12 / 1/4) LET whgt2= 256 LET whgt1= 120 ! --- plane 1 data --- DECLARE PUBLIC w1Lft,w1Rgt,w1Bas,w1Top,w1Midx,w1Midy DECLARE PUBLIC w1fLft,w1fRgt,w1fBas,w1fTop,w1x0,w1y0 DECLARE PUBLIC w1xFirst, w1xStik, w1xLtik, w1xLabel, w1xGridstep DECLARE PUBLIC w1yFirst, w1yStik, w1yLtik, w1yLabel, w1yGridstep DECLARE PUBLIC w1wWid,w1wHgt,w1fWid,w1fHgt DECLARE PUBLIC w1fxRatio,w1fyRatio,w1wxRatio,w1wyRatio,w1Aspect DECLARE PUBLIC w1xPiFlag, w1xMult, w1yPiFlag, w1yMult LET w1Flag = 1 LET w1xPiFlag= 0 LET w1yPiFlag= 0 LET w1Lft = worklft + 55 ! pixel bounds LET w1Rgt = w1Lft + wwid LET w1Top = workbas - whgt1 - 50 LET w1Bas = w1Top + whgt1 LET w1fLft= 0 ! function bounds LET w1fRgt= 12 LET w1fTop= 2 LET w1fBas= 0 LET w1Xax$= "t" ! axis labels LET w1Yax$= "y" LET w1xGridstep= 0 ! horizontal grid intervals LET w1yGridstep= 0 ! vertical grid intervals LET w1xStik = 0 ! horizontal axis Tik marks LET w1xLtik = 1 LET w1xLabel= 0 LET w1xFirst= w1fLft LET w1xMult = 1 LET w1yStik = 0 ! vertical axis Tik marks LET w1yLtik = 0.5 LET w1yLabel= 0.5 LET w1yFirst= w1fBas LET w1yMult = 1 ! --- Plane 1 methods --- DECLARE DEF w1Fncx,w1Fncy,w1Wndx,w1Wndy ! window/function transforms DECLARE DEF w1wWithin CALL w1Variables SUB w1ClearPlaneGraph CALL BoxArea(w1Lft+1,w1Rgt-1,w1Bas-1,w1Top+1,black) SET COLOR 3 PLOT w1Lft,w1Top; w1Rgt,w1Top; w1Rgt,w1Bas SET COLOR 4 PLOT w1Lft,w1Top; w1Lft,w1Bas; w1Rgt,w1Bas END SUB SUB w1Init CALL w1DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w1Rgt+8,w1y0+3,w1Xax$,axislabelclr) ! axis labels CALL PlotTextLJ(w1lft-28,w1Top-12,"f(u) g(t-u)",cyan) CALL w1DrawBackgroundSignal CALL w1KeepGridLayer END SUB ! ------------------------------------------ ! --- plane 2 data --- DECLARE PUBLIC w2Lft,w2Rgt,w2Bas,w2Top,w2Midx,w2Midy DECLARE PUBLIC w2fLft,w2fRgt,w2fBas,w2fTop,w2x0,w2y0 DECLARE PUBLIC w2xFirst, w2xStik, w2xLtik, w2xLabel, w2xGridstep DECLARE PUBLIC w2yFirst, w2yStik, w2yLtik, w2yLabel, w2yGridstep DECLARE PUBLIC w2wWid,w2wHgt,w2fWid,w2fHgt DECLARE PUBLIC w2fxRatio,w2fyRatio,w2wxRatio,w2wyRatio,w2Aspect DECLARE PUBLIC w2xPiFlag, w2xMult, w2yPiFlag, w2yMult LET w2Flag = 1 LET w2xPiFlag= 0 LET w2yPiFlag= 0 LET w2Lft = w1lft ! pixel bounds LET w2Rgt = w2Lft + wwid LET w2Top = worktop + 34 LET w2Bas = w2Top + whgt2 LET w2fLft= w1fLft ! function bounds * pi LET w2fRgt= w1fRgt LET w2fTop= w1fTop LET w2fBas= w1fBas LET w2xGridstep= 0 ! horizontal grid intervals LET w2yGridstep= 0 ! vertical grid intervals LET w2xAx$= "t" ! axis labels LET w2yAx$= "I" LET w2xStik = 0 ! horizontal axis Tik marks LET w2xLtik = 1 LET w2xLabel= 1 LET w2xFirst= w2fLft LET w2xMult = 1 LET w2yStik = 0 ! vertical axis Tik marks LET w2yLtik = 0.5 LET w2yLabel= 0.5 LET w2yFirst= w2fBas LET w2yMult = 1 SUB w2SetBounds(wgtnum) SELECT CASE signum CASE 0,2 SELECT CASE wgtnum CASE 0 LET w2fTop = 12 LET w2yLtik = 1 LET w2yLabel= 2 CASE 1 LET w2fTop = 2 LET w2yLtik = 0.5 LET w2yLabel= 0.5 CASE 2 LET w2fTop = 72 LET w2yLtik = 6 LET w2yLabel= 12 CASE 3 LET w2fTop = 16 LET w2yLtik = 2 LET w2yLabel= 4 CASE 4 LET w2fTop = 3 LET w2yLtik = 0.5 LET w2yLabel= 1 END SELECT CASE 1 SELECT CASE wgtnum CASE 0 LET w2fTop = 2 LET w2yLtik = 0.5 LET w2yLabel= 0.5 CASE 1 LET w2fTop = 0.6 LET w2yLtik = 0.1 LET w2yLabel= 0.1 CASE 2 LET w2fTop = 16 LET w2yLtik = 2 LET w2yLabel= 4 CASE 3 LET w2fTop = 3 LET w2yLtik = 0.5 LET w2yLabel= 1 CASE 4 LET w2fTop = 0.6 LET w2yLtik = 0.1 LET w2yLabel= 0.1 END SELECT CASE else END SELECT LET w2fBas = 0 LET w2yStik = 0 ! vertical axis Tik marks LET w2yFirst= w2fBas CALL w2Variables END SUB ! --- plane 2 methods --- DECLARE DEF w2Fncx, w2Fncy, w2Wndx, w2Wndy ! window/function transforms DECLARE DEF w2wWithin CALL w2Variables SUB w2Init CALL w2DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w2Rgt+8,w2y0+3,w2xAx$,litgry) LET txt$= "(f*g)(t)" CALL StringWidth(txt$,sw) CALL SwapMultiplication(w2Lft-sw/2+1,w2Top-12,txt$,yellow) CALL w2DrawBackgroundConvolution CALL w2KeepGridLayer END SUB ! --- plane 3 data --- DECLARE PUBLIC w3Lft,w3Rgt,w3Bas,w3Top,w3Midx,w3Midy DECLARE PUBLIC w3fLft,w3fRgt,w3fBas,w3fTop,w3x0,w3y0 DECLARE PUBLIC w3xFirst, w3xStik, w3xLtik, w3xLabel, w3xGridstep DECLARE PUBLIC w3yFirst, w3yStik, w3yLtik, w3yLabel, w3yGridstep DECLARE PUBLIC w3wWid,w3wHgt,w3fWid,w3fHgt DECLARE PUBLIC w3fxRatio,w3fyRatio,w3wxRatio,w3wyRatio,w3Aspect DECLARE PUBLIC w3xPiFlag, w3xMult, w3yPiFlag, w3yMult LET w3Flag = 1 LET w3xPiFlag= 0 LET w3yPiFlag= 0 LET w3Lft = worklft + 55 ! pixel bounds LET w3Rgt = w3Lft + wwid LET w3Top = w1Bas + 72 LET w3Bas = w3Top + whgt1 LET w3fLft= 0 ! function bounds LET w3fRgt= 12 LET w3fTop= 2 LET w3fBas= 0 LET w3Xax$= "t" ! axis labels LET w3Yax$= "y" LET w3xGridstep= 0 ! horizontal grid intervals LET w3yGridstep= 0 ! vertical grid intervals LET w3xStik = 0 ! horizontal axis Tik marks LET w3xLtik = 1 LET w3xLabel= 1 LET w3xFirst= w3fLft LET w3xMult = 1 LET w3yStik = 0 ! vertical axis Tik marks LET w3yLtik = 0.5 LET w3yLabel= 0.5 LET w3yFirst= w3fBas LET w3yMult = 1 ! --- Plane 1 methods --- DECLARE DEF w3Fncx,w3Fncy,w3Wndx,w3Wndy ! window/function transforms DECLARE DEF w3wWithin CALL w3Variables SUB w3Init CALL w3DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w3Rgt+8,w3y0+3,w3Xax$,axislabelclr) ! axis labels CALL PlotTextCJ(w3lft,w3Top-12,"w(t)",litgry) CALL w3KeepGridLayer END SUB ! --- Slider parameters and methods ! --- horizontal slider 1 --- DECLARE PUBLIC h1axis,h1wLft,h1wRgt,h1wBas,h1wTop,h1fLft,h1fRgt DECLARE PUBLIC h1name$,h1form$,h1clr,h1First,h1STik,h1LTik,h1Label DECLARE PUBLIC h1PiAxis,h1Mult,h1fMin,h1fMax LET h1PiAxis= 0 LET h1clr = litgry LET h1name$ = "u" LET h1form$ = "--%.###" LET h1Mult = 1 LET h1Places= 3 LET h1axis = w1Bas + 22 LET h1wLft = w1Lft LET h1wRgt = w1Rgt LET h1fLft = w1fLft LET h1fRgt = w1fRgt LET h1STik = 0.25 ! short tick marks LET h1LTik = 1 ! long tick marks LET h1Label= 1 ! labels LET h1First= h1fLft ! first tick mark LET h1Click= 1 DECLARE DEF h1Within,h1Fncx ! window/function transforms CALL h1SliderVariables SUB h1Iinit CALL h1DrawSlider(h1name$,tau) END SUB ! --- t1 text rectangle - convolution equation --- SUB t1Convolution(lft,ty) LET clr= yellow CALL FLessEqUT(lft,ty,clr) ! f_u CALL SwapMultiplication(tx,ty,"(t)*g(t) = ",clr) CALL StringWidth("(t)*g(t) = ",sw) LET tx= tx + sw + 4 DRAW IntegralSign(clr) with shift(tx,ty) CALL SetTextFont(1,9,"bold") CALL PlotTextLJ(tx+4,ty+7,"0",clr) CALL PlotTextLJ(tx+5,ty-9,"t",clr) LET tx= tx + 35 CALL SetTextFont(1,12,"bold") CALL FLessEqUT(tx,ty,clr) ! f_u LET tx= tx + 3 CALL PlotTextLJ(tx,ty,"(u) g(t-u) dt",clr) END SUB SUB FLessEqUT(mid,ty,clr) CALL StringWidth("f=u(t)",sw) LET tx = mid - sw/2 CALL PlotTextLJ(tx,ty,"f",clr) CALL StringWidth("f",sw) LET tx = tx+sw+1 LET ysub= ty+3 DRAW LessEql9(clr) with shift(tx,ysub) CALL PlotTextLJ(tx+7,ysub,"u",clr) LET tx = tx + 15 END SUB ! ----- menu 1: signal ----- DECLARE PUBLIC m1Lft, m1Rgt, m1Bas, m1Top, m1Equation, m1Prefix$, m1Menu1$() DECLARE PUBLIC m1tClr, m1Name$ MAT redim m1Menu1$(1:3) MAT READ m1Menu1$ DATA "1" DATA "e^[-at]" DATA "1 + cos(bt)" LET m1Prefix$ = "f(t) = " LET m1Lft = w1Rgt + 40 LET m1Top = w2Bas - 90 LET m1tClr = green LET m1Equation= 1 LET m1Name$ = "Signal" SUB m1Init CALL m1ResetMenu(m1State) END SUB ! ----- menu 2: weight ----- DECLARE PUBLIC m2Lft, m2Rgt, m2Bas, m2Top, m2Equation, m2Prefix$, m2Menu1$() DECLARE PUBLIC m2tClr, m2Name$ MAT redim m2Menu1$(1:5) MAT READ m2Menu1$ DATA "1" DATA "e^[-at]" DATA "t" DATA "(1/a)(1-e^[-at])" DATA "t e^[-at]" LET m2Prefix$ = "g(t) = " LET m2Lft = m1Lft LET m2Top = w1Top ! m1Top + 115 LET m2tClr = white LET m2Equation= 1 LET m2Name$ = "Weight" SUB m2Init CALL m2ResetMenu(m2State) END SUB ! --- Radio Buttons --- DECLARE PUBLIC r1cnt,r1stp,r1siz DECLARE PUBLIC r1lft,r1rgt,r1bas,r1top,r1Name$,r1NameClr DECLARE PUBLIC r1NameList$(),r1ColorList() MAT redim r1NameList$(1:3) MAT READ r1NameList$ DATA "1/2","1/4","1/8" MAT redim r1ColorList(1:3) MAT READ r1ColorList DATA 5,5,5 LET r1cnt = 3 LET r1Lft = w1Rgt + 40 LET r1Top = w2Top + 50 LET r1Name$ = "step size" LET r1NameClr= 5 LET r1TxtClr = 5 DECLARE DEF r1Within CALL r1SetVars ! --- Set Default Parameters and Draw screen --- LET tau,oldtau= 0 LET maxtau = 0 LET signum = m1Equation-1 LET wgtnum = m2Equation-1 LET r1num = 1 LET skip = 1/2 LET m1State = 0 LET m2State = 0 ! ------ Initialize the screen ------ CALL InitScreen CALL m1InitMenu1 CALL m2InitMenu1 CALL SetTimer SUB InitScreen BOX CLEAR workLft,workRgt,workBas,workTop CALL w2SetBounds(wgtnum) CALL w1Init CALL w2Init ! CALL w3Init CALL m1Init CALL m2Init CALL r1DrawCheckBoxes CALL r1SetCheckBox(r1num) CALL h1Iinit CALL w2DrawFuture(tau,cyan) CALL w2DrawConvolution(tau) CALL w1DrawGraphs(tau,cyan) CALL w1DrawWeight ! CALL t1Convolution(w2Midx-80,w2Top-16) ! show equation CALL w1KeepGraphLayer CALL w2KeepGraphLayer END SUB ! ---------- Event manager ------------- DO LET clearflag= 0 SET COLOR litgry LET oldmx= -999 DO GET MOUSE: mx,my,ms IF w1wWithin(mx,my)=1 or w2wWithin(mx,my)=1 then LET x = w1Fncx(mx) LET x = roundn(x,skip) LET mx= w1Wndx(x) IF mx<>oldmx then CALL RollOver LET oldmx= mx END IF ELSE IF clearflag=1 then CALL w1ShowGraphLayer CALL w2ShowGraphLayer LET clearflag= 0 END IF LOOP until ms=2 IF w1wWithin(mx,my)=1 or w2wWithin(mx,my)=1 then ! temp areas while mouse button is down LET temptau= w1Fncx(mx) LET temptau= roundn(temptau,skip) LET wtau = w1Wndx(temptau) CALL w1ShowGridLayer CALL PlotLine( wtau,w1Bas-1, wtau,w1Top+1, litmid) CALL w1FillGraph(temptau,cyan) SET COLOR yellow FOR wx= w2Lft to wtau ! convolution graph LET t= w2Fncx(wx) LET y= cnv(t) PLOT wx,w2Wndy(y); NEXT wx PLOT CALL w2FillGraph(temptau,cyan) CALL MouseUp(mx,my,ms) ! wait for mouse up CALL w1ShowGraphLayer CALL w2ShowGraphLayer ELSE IF h1Within(mx,my)=1 then IF mym1Lft and mxm1Top and mym2Lft and mxm2Top and myoldx then CALL h1Mark(x) LET oldx= x END IF LOOP until ms=3 LET tau= x CALL h1action CALL w1KeepGraphLayer CALL w2KeepGraphLayer END SUB SUB h1action IF tau<>oldtau then IF tau=0 then CALL w1DrawWeight CALL w2ShowGridLayer ELSE LET maxtau= roundn(maxtau,skip) LET oldtau= tau CALL h1Mark(tau) IF tau>maxtau then ! new drawing to right IF tau-maxtau>=skip then FOR i= maxtau+skip to tau+.1 step skip ! for each step SET COLOR yellow IF maxtau>skip then LET start= maxtau-skip ELSE LET start= 0 END IF FOR wx= w2Wndx(start) to w2Wndx(i) ! draw the curve LET t= w2Fncx(wx) LET y= cnv(t) PLOT wx,w2Wndy(y); NEXT wx PLOT CALL Delay(1/100) CALL w1DrawGraphs(i,cyan) CALL w2DrawFuture(i,cyan) NEXT i END IF ELSE IF tau=skip then FOR i= maxtau to tau-.1 step -skip LET i1,i2= roundn(i,skip) IF i0 or wgtnum=2 then CALL w2DrawFuture(tau,cyan) ! touch up END IF END IF LET maxtau= tau END IF END IF END SUB ! --- Tool specific drawing and typesetting routines --- ! --------- w1 plane - show weight function --------- SUB w1DrawWeight ! display weight function in the bottom plane CALL w1ShowGridLayer SET COLOR litgry FOR wx= w1Lft to w1Rgt LET t = w1Fncx(wx) LET y = w(t) LET wy= w1Wndy(y) IF wy>w1Top and wyw1Top and wy0 then ! draw signal from left to tau in plane 1 SET COLOR green FOR wx= w1Lft to wlft LET u = w1Fncx(wx) LET y= f(u) LET wy= round(w1Wndy(y)) IF wy>w1Top and wy1 then CALL PlotLine( wlft,w1y0-1, wlft,wy, green) ELSE CALL PlotLine( wlft,w1y0-1, wlft,wy, cyan) END IF ! draw product curve from tau to right in plane 1 SET COLOR clr FOR wx= wlft to w1Rgt-1 LET t = w1Fncx(wx) LET y = w(t-w1tau)*f(w1tau) LET wy= round(w1Wndy(y)) IF wy>w1Top and wy0 then SET COLOR clr FOR wx= wLft+1 to w1Rgt-1 ! graph in plane 1 LET t = w1Fncx(wx) LET y = w(t-tau)*f(tau) LET wy= max(w1Wndy(y),w1Top) PLOT wx,wy; wx,w1y0-1 NEXT wx PLOT END IF END SUB ! --- w2 plane - upper convolution --- SUB w2DrawBackgroundConvolution ! fixed integral curve ! draws gray convolution curve on background SET COLOR 3 ! gray convolution ghost FOR wx= w2Lft to w2Rgt LET t = w2Fncx(wx) LET y = cnv(t) LET wy= w2Wndy(y) PLOT wx,wy; NEXT wx PLOT CALL w2KeepGridLayer END SUB SUB w2DrawConvolution(tau) ! draws yellow convolution curve in upper plane SET COLOR yellow FOR wx= w2Lft to w2Wndx(tau) LET t = w2Fncx(wx) LET y = cnv(t) LET wy= w2Wndy(y) PLOT wx,wy; NEXT wx PLOT END SUB SUB w2DrawFuture(tau2,clr) ! graph in upper plane 2 ! removes yellow convolution curve back to tau IF clr=black then ! restore convolution ghost SET COLOR drkmid LET wtaux= max(int(w2Wndx(tau2)),w2Lft) FOR wx= wtaux to w2Rgt-1 LET t = w2Fncx(wx) LET y = cnv(t) LET wy= w2Wndy(y) PLOT wx,wy; NEXT wx PLOT END IF IF clr=cyan or tau2>tau then ! draws if cyan, erases if black LET wtaux= int(w2Wndx(tau2)) SET COLOR clr FOR wx= wtaux to w2Rgt-1 ! y is decay from convolve LET t = w2Fncx(wx) LET y = future(t,tau2) LET wy= round(w2Wndy(y)) IF wy0 then LET tau0 = tau - skip LET wtaux= int(w2Wndx(tau)) + 1 LET wbasx= w2y0 - 1 SET COLOR clr FOR wx= wtaux to w2Rgt-1 ! y is decay from convolve LET t = w2Fncx(wx) LET y = future(t,tau) LET wy = min(w2Wndy(y),wbasx) LET y0 = future(t,tau0) LET wy0= min(w2Wndy(y0),wbasx) PLOT wx,wy; wx,wy0 NEXT wx PLOT END IF END SUB END SUB ! ----- end of convolution code ------