%! % A Fourier Series analyzer for the triangle series % ===================================== % Don Lancaster and Synergetics www.tinaja.com % This file is http://www.tinaja.com/psutils/fourier1.psl It is normally % run by sending the file to Distiller by way of command line //acrodist /F. % It should also be GhostScript or Google Drive compatible. % The companion demo is http://www.tinaja.com/psutils/fourier1.log % Development services available via don@tinaja.com. % ///////// (A) WEB FRIENDLY COLOR UTILITIES ///////////// % tintmat is a self-generating list of 216 triple color values /webtintmat [ 0 1 5 { /a exch store 0 1 5 { /b exch store 0 1 5 { 5 div b 5 div a 5 div }for } for } for ] def % setwebtint accepts a color number 0 to 215 and then % sets the PostScript color generator for later use... /setwebtint { abs cvi 216 cvi mod % restrict range webtintmat exch 3 mul 3 getinterval % get values from table aload pop setrgbcolor} def % and set them % The blocks are arranged as red to the right, green % up in order of increasing blue. % Some "pure color" sequences are % red: 0 1 2 3 4 5 % orange: 0 7 8 15 16 23 (sort of) % yellow: 0 7 14 21 28 35 % green: 0 6 12 18 24 30 % aqua: 0 42 84 126 168 210 % blue: 0 36 72 108 144 180 % magenta: 0 37 74 111 148 185 % purple 0 73 73 110 147 183 (sort of) % gray 0 43 86 129 172 215 % ////////////// GONZO EXCERPTS ////////////////// /setgrid { /blocksize exch def translate % simplified blocksize dup scale} def % repeats [ proc distance trips] xrpt /xrpt{gsave aload pop /trips exch def /dist exch def /rproc exch def trips { gsave rproc grestore dist 0 translate } repeat grestore} def /yrpt{gsave aload pop /trips exch def /dist exch def /rproc exch def trips { gsave rproc grestore 0 dist translate } repeat grestore} def % mergestr merges the two top stack strings into one top stack string /mergestr {2 copy length exch length add string dup dup 4 3 roll 4 index length exch putinterval 3 1 roll exch 0 exch putinterval} def /showgrid {gsave /vblocks exch def /hblocks exch def thingridlines setlinewidth [{0 0 moveto 0 vblocks rlineto stroke} 1 hblocks 1 add] xrpt [{0 0 moveto hblocks 0 rlineto stroke} 1 vblocks 1 add] yrpt fatterborder { gsave newpath 0 0.96 blocksize div dtransform round idtransform setlinewidth pop 2 setlinecap 0 0 moveto hblocks 0 rlineto 0 vblocks rlineto hblocks neg 0 rlineto closepath stroke grestore} if fat5 { gsave newpath 0 0.48 blocksize div dtransform round idtransform setlinewidth pop mark {5 0 moveto 0 vblocks rlineto stroke} 5 hblocks 5 div cvi] xrpt mark {0 5 moveto hblocks 0 rlineto stroke} 5 vblocks 5 div cvi] yrpt grestore} if fatter10 { gsave newpath 0 0.96 blocksize div dtransform round idtransform setlinewidth pop mark {10 0 moveto 0 vblocks rlineto stroke} 10 hblocks 10 div cvi] xrpt mark {0 10 moveto hblocks 0 rlineto stroke} 10 vblocks 10 div cvi] yrpt grestore} if grestore} def /fatterborder {true } store /fat5 {true} store /fatter10 {true} store /thingridlines {0} store %%%%%%%%%%%%%%%%%%%%%%%%% fourier begins here %%%%%%%%%%%%%%%%% zzz % target triangle wave % per skilling, series is 1 -1/9 + 1/25 - 1/49 + 1/81 % or 1 -.1111 .0400 - .0204 .01235 % square cosine series is 1 -1/3 1/5 -1/7 1/9 % or 1 -.3333 .2000 -.1429 .1111 /signal [ 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] store /signal1 [ 20 20 20 20 20 20 20 20 20 20 % rename for square wave -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 20 20 20 20 20 20 20 20 20 20 ] store /signal2 [ 20 20 20 20 20 20 20 20 20 20 % rename to explore sample rates 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 -20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ] store signal == signal length 1 sub /points exch store 360 points div /inc exch store 0 1 1 points { /posn exch store posn inc mul inc 2 div sub /ang exch store signal posn get signal posn 1 sub get add 2 div ang cos mul add dup == } for /intf1 exch points div store (\n\n\n\n) print 0 1 1 points { /posn exch store posn inc mul inc 2 div sub /ang exch store signal posn get signal posn 1 sub get add 2 div ang 3 mul cos mul add dup == } for /intf3 exch points div intf1 div store 0 1 1 points { /posn exch store posn inc mul inc 2 div sub /ang exch store signal posn get signal posn 1 sub get add 2 div ang 5 mul cos mul add dup == } for /intf5 exch points div intf1 div store 0 1 1 points { /posn exch store posn inc mul inc 2 div sub /ang exch store signal posn get signal posn 1 sub get add 2 div ang 7 mul cos mul add dup == } for /intf7 exch points div intf1 div store 0 1 1 points { /posn exch store posn inc mul inc 2 div sub /ang exch store signal posn get signal posn 1 sub get add 2 div ang 9 mul cos mul add dup == } for /intf9 exch points div intf1 div store (\n\n) print intf1 == intf3 == intf5 == intf7 == intf9 == (\n\n) print intf3 dup mul intf5 dup mul add intf7 dup mul add intf9 dup mul add sqrt 100 mul /totaldist exch store totaldist == % showpage % eof