In this chapter we will make a really cool, albeit fairly simple program. Our goal is to build an Oscilloscope simulator that can generate Lissajou patterns from horizontal and vertical input frequencies.
In physics we often deal with examples of Simple Harmonic Motion (SHM). SHM is a "type of periodic motion or oscillation motion where the restoring force is directly proportional to the displacement and acts in the direction opposite to that of displacement." Classic examples of SHM are a mass on a swinging pendulum or a mass on an oscillating spring. Imagine a pendulum attached to a pen swinging back and forth in simple harmonic motion over a moving treadmill of paper as seen in the figure. The result is a sine curve.
We would also get a sine curve for an oscillating mass on a spring as you can see in the image and animation.
The equation for the position of a particle on a sine wave curve is given by the following equation.
So if we graphed this equation against time we would have a sine curve that would start wherever the phase shift was. If we entered a phase shift of 90 the graph would start at a maximum of +1. If we entered a phase shift of 30, our graph would start at a +0.5.
An interesting thing occurs if you graph this sine curve against a second sine curve. Notice this second curve will not have a phase shift parameter.
The differences between the two signals will be different frequencies and the phase shift. When these two equations are graphed against each other we form "spirograph" type images called "Lissajou Figures". We can interpret Lissajou patterns we see on an oscilloscope to determine unknown frequencies when we compare it to a known frequency. Here is a really good visualization of how the two sine curves of different frequencies are being graphed to create Lissajou figures. Notice that the vertical input frequency is actually controlling the horizontal component and the horizontal frequency is controlling the vertical component of the Lissajou figure.
The easiest way to interpret Lissajou figures and determine the ratio between the horizontal and vertical frequencies is to circumscribe the Lissajou pattern with a box. The horizontal signal is related to how many times the pattern touches the side of the box. The vertical signal is related to how many times the pattern touches the top of the box. Notice in the animation below that the pattern touches the side of the box 3 times and the top of the box 2 times. These are not the actual frequencies, rather they describe the RATIO of the frequencies. H:V = 3:2
Below are a couple more examples. In the first example there is 1 point of horizontal tangency and 2 points of vertical tangency so the ratio is: H:V = 1:2. In the second example there are 5 points of horizontal tangency and 4 points of vertical tangency for a ratio of H:V = 5:4. A simple circle would be a 1:1 ratio.
INPUTS:
A user can update two frequencies from 1-10 Hz in 1 Hz increments.
A button can be clicked to compare the two signal while phase shifting from 0-360˚ by 10˚.
OUTPUTS:
Graphical output of the Lissajou pattern
Phase angle constantly updates by 10˚ while program is running.
CRITERIA & CONSTRAINTS:
Clicking the button will run the function and spin the Lissajou pattern.
Your program should have an impressive interface. (colors and graphics)
Specify units.
Set data validation drop down menus of 1-10 for both the X and Y frequencies.
Create a Phase variable, set it to zero and add it to the GUI.
Create a while loop that runs while the Phase angle is less than 360.
In the while loop get the Phase angle from the GUI, add 10 to it and put it back on the GUI.
After the while loop set the Phase angle back to zero.
We will just go ahead and add data directly on the graph.
Since we are using a scatter plot we need a lot of data points so it looks more like a smooth curve. We will go through two cycles of a sine wave or 720˚. In cell P1 create a time interval by entering =1/720
In cells Q1, R1 and S1, enter headers t, x and y respectively.
In column Q, starting in cell Q2, enter 0 but then increment down the column by the time interval in cell $P$1. Drag this down 720 rows.
In column R, we will enter the x equation from above. The amplitude A will just be 1. The phase angle needs to be converted to radians. The only variable that changes in this formula is time so make sure all other variables are grabbing the same thing each time. This formula should grab the X-frequency. Drag this equation down 720 rows.
In column S, we will enter the y equation from above. The amplitude B will just be 1. The only variable that changes in this formula again is time so make sure all other variables are grabbing the same thing each time. This formula should grab the Y-frequency. Drag this equation down 720 rows.
If done correctly your x and y values should be back at 0,0 at 360˚ and 720˚. Again, we could have used t=1/360 and then just used 360 rows but the Lissajou figures are then more dotted and not as smooth.
Create the Scatter Plot with x-axis from R2:R722 and Series 1 from S2:S722. Use column R as labels.
Now a user can select two frequencies and then click the button which will continually change the phase angle by 10˚ which will in effect rotate our Lissajou figure around. Cool huh?