1000 print "All waves, including human speach, the sound of a running gasoline engine"
1100 print "a musical instrument, etc. are made up of combinations of sin waves. The"
1200 print "sin wave is the most fundamental of all waves. This program demonstrates"
1300 print "the generation of a squarewave, a sawtooth wave and a triangular wave."
1400 print "When the program is run, it will ask you for number of harmonics. Typically,"
1500 print "they could be from 1 to 100, except for the trangle wave. The higher the"
1600 print "number, the more accurate will be the shape of the wave. It will then ask"
1700 print "which type of wave to generate with a selection of 1, 2, or 3. Have fun."
1800 print
1900 expunge
2000 print "Input number of Harmonics";
2100 input n
2200 print "Select waveform: 1 for squarewave, 2 for sawtooth, 3 for triangle";
2300 input w
2400 rem ///////////////////////////////////
2500 rem ///Print a square wave in asterisks
2600 rem ///////////////////////////////////
2700 let a2 = 720
2800 for a = 1 to a2 step 40
2900 on w gosub 3300,5200,6200
3000 next
3100 goto 2000
3200 stop
3300 rem square_f
3400 let y = 0
3500 let u = 0
3600 let s = 2
3700 for h = 1 to n step 2
3800 let u = u+((1/h)*sin(h*a))
3900 next
4000 rem Multiply Series with amplitude of 10
4100 rem Add a :carrier of 15 so that negative values
4200 rem don't get clipped
4300 let y = 10*u+15
4400 gosub 4600
4500 return
4600 rem plot_star
4700 for x = 1 to y
4800 print " ";
4900 next
5000 print "*"
5100 return
5200 rem sawtooth_f
5300 let y = 0
5400 let u = 0
5500 let s = 2
5600 for h = 1 to n step 1
5700 let u = u+(1/h)*sin(h*a+(h%2*180))
5800 next
5900 let y = 10*u+15
6000 gosub 4600
6100 return
6200 rem triangle_f
6300 let y = 0
6400 if n > 30 then n = 30
6500 let u = 0
6600 let s = 2
6700 for h = 1 to n step 2
6800 let u = u+(n/fact(h))*cos(h*a)
6900 next
7000 let y = 10*u/h+20
7100 gosub 4600
7200 return