View Full Version : Request for Lisp
aledtaylor
19th Dec 2005, 02:33 pm
Please help
I need a to draw sine waves to illustrate the display on an oscilloscope.
I can draw a sine wave manually without any problem but I now need to draw 2 sine waves with different wavelengths and frequencies added together.
I also need to combine them as 'Amplitude Modulation' and 'Frequency Modulation'.
Does anyone have any lisp routines that can do any of these?
Many thanks in advance.
David Bethel
19th Dec 2005, 03:26 pm
(initget 7)
(setq amp (getdist "\nAmplitude: "))
(initget 7)
(setq frq (getdist "\nFrequency: "))
(initget 6)
(setq rep (getint "\n# of Points per Wave <1000>: "))
(and (not rep)
(setq rep 1000))
(setq i 0
inc (/ (* 2 pi) rep))
(command "_.PLINE")
(repeat (1+ rep)
(command (list (* i frq) (* amp (sin i))))
(setq i (+ i inc)))
(command "")
I would be interested to know how you draw a sine wave manually. -David
aledtaylor
19th Dec 2005, 04:48 pm
Thank you for the prompt reply.
I've tried the lisp and it draws a sin wave fine. I'm impressed
The 'Frequency' value seems to work like wavelength but is 6.2832x too big. Wavelength at 1x would be great.
This is how you draw a sine wave manually
http://www.cadimage.net/postimages/sin.jpg
Many thanks again. This will be very useful to me.
David Bethel
20th Dec 2005, 05:47 pm
The 6.28 is (* pi 2.0) which equates to the number of radians in a circle. Frequency was probably the wrong term. Your method reminds me of when I was working sheet metal and had to do things like this with a square and set of dividers. It was fairly accurate but very time consuming. -David
aledtaylor
21st Dec 2005, 03:08 pm
I've fixed the wavelength issue.
(defun c:sin()
(initget 7)
(setq amp (getdist "\nAmplitude: "))
(initget 7)
(setq wav (getdist "\nWavelength: "))
(initget 6)
(setq rep (getint "\n# of Points per Wave <36>: "))
(and (not rep)
(setq rep 36))
(setq i 0
inc (/ (* 2 pi) rep))
(command "_.PLINE")
(repeat (1+ rep)
(command (list (* i (/ wav (* 2 pi))) (* amp (sin i))))
(setq i (+ i inc)))
(command "")
)
this is the code for 2 sine waves added together:
(defun c:sin2()
(initget 7)
(setq amps (getdist "\nAmplitude-small: "))
(initget 7)
(setq rat (getdist "\nNumber of small wavelengths in large: "))
(initget 7)
(setq ampl (getdist "\nAmplitude-large: "))
(initget 7)
(setq wav (getdist "\nWavelength-large: "))
(initget 6)
(setq rep (getint "\n# of Points per large Wave <1000>: "))
(and (not rep)
(setq rep 1000))
(setq i 0
inc (/ (* 2 pi) rep))
(command "_.PLINE")
(repeat (1+ rep)
(command (list (* i (/ wav (* 2 pi))) (+ (* ampl (sin i)) (* amps (sin (* i rat))))))
(setq i (+ i inc)))
(command "")
)
http://www.cadimage.net/postimages/sin2.jpg
And this is the code for amplitude modulation:
(defun c:sinam()
(initget 7)
(setq amp (getdist "\nAmplitude: "))
(initget 7)
(setq rat (getdist "\nNumber of small wavelengths in large: "))
(initget 6)
(setq md (getdist "\nModulation depth percentage: "))
(initget 7)
(setq wav (getdist "\nWavelength-large: "))
(initget 6)
(setq rep (getint "\n# of Points per large Wave <1000>: "))
(and (not rep)
(setq rep 1000))
(setq i 0
inc (/ (* 2 pi) rep))
(command "_.PLINE")
(repeat (1+ rep)
(command (list (* i (/ wav (* 2 pi))) (* (* amp (sin(* i rat))) (+ (* (/ md 200) (sin i)) (- 1 (/ md 200))))))
(setq i (+ i inc)))
(command "")
)
http://www.cadimage.net/postimages/sinam.jpg
David Bethel
21st Dec 2005, 04:01 pm
Now all we have to do is find a radio that can recieve those signals :shock: :shock: Good Job -David
Powered by vBulletin™ Version 4.1.2 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.