30 July, 2023

Charts Based On Parametric Equations: Sinusoidal (Oscilloscope-type) Curves

Curves that can be used in physics for analysing pairs of simple harmonic motions are generally known as Lissajous Curves. They describe the superposition of two oscillations taking place at the right angle to each other,  at different frequencies. Their main application can be found in oscilloscopes. These instruments allow observation of two superimposed sine waves coming from varying signal voltages of sinusoidal nature. Depending on the frequency and amplitude of each wave, and the phase between them, we can see interesting patterns emerging.

Because the superimposed two perpendicular oscillations can be described with parametric equations for x and y in the Cartesian coordinate system, we can quite easily demonstrate the resulting shapes graphically using Excel charts. Let's look first at some of "oscilloscopic" patterns generated with Excel.

When the ratio of frequencies is rational, a closed form curves are generated as shown in these examples:


If the ratio is not rational, the generated curves appear as open (not closed):

And finally, if the two frequencies are exactly the same and in phase, then we get a straight diagonal line as output shown here:

We don't need a physical instrument to create this kind of patterns. They have been plotted with the following Excel VBA macro:

Sub CreateOscilloscopeSignals()
'This macro generates plots based on the Lissajous equations
'The ReDim statements are used to size the arrays for X and Y values

Dim i As Integer, numPoints As Integer, Amp As Integer, Bmp As Integer
Dim a As Integer, b As Integer
Dim chartObj As ChartObject
Dim oChart As Chart
Dim xValues() As Double, yValues() As Double, fi As Double
Dim tit As String
'Define the number of data points and calculate X and Y values
numPoints = 2000    'Change as needed
ReDim xValues(1 To numPoints)
ReDim yValues(1 To numPoints)
Amp = 20: Bmp = 20        'Amplitudes in the horizontal and vertical directions
fi = 0         'Phase angle; adjust if needed to clearly see the lobes
'Set and use random parameters (within some limits) for the curves
' "a" determines horizontally aligned lobes, "b" - vertically aligned lobes

a = WorksheetFunction.RandBetween(1, 12): b = WorksheetFunction.RandBetween(1, 12)
'Calculate X and Y values using the Lissajous equations
For i = 1 To numPoints
    xValues(i) = Amp * Sin(WorksheetFunction.Radians(a * i + fi))
    yValues(i) = Bmp * Sin(WorksheetFunction.Radians(b * i))
Next i
'Create a new chart object
Set chartObj = ActiveSheet.ChartObjects.Add(Top:=10, Left:=100, Width:=600, Height:=500)
Set oChart = chartObj.Chart
oChart.ChartType = xlXYScatterSmoothNoMarkers   'Set the chart type to the line chart
'Set X and Y values for the chart series
    chartObj.Chart.SeriesCollection(1).Values = yValues
    chartObj.Chart.SeriesCollection(1).xValues = xValues
'The code below can be modified as needed
    ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
    ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
    ActiveChart.SetElement (msoElementPrimaryValueGridLinesNone)
    ActiveChart.SetElement (msoElementPrimaryCategoryGridLinesNone)
'Add chart title and title of the axes
    oChart.Axes(xlCategory).HasTitle = True
    oChart.Axes(xlCategory).AxisTitle.Caption = "Horizontal vibration"
    oChart.Axes(xlValue).HasTitle = True
    oChart.Axes(xlValue).AxisTitle.Caption = "Vertical vibration"
    oChart.HasTitle = True
    tit = "Oscilloscope " & a & "-" & b
    oChart.ChartTitle.Text = tit
    With Selection.Font
        .Bold = msoTrue
        .Size = 14
    End With
'Set/change some elements of the chart
    With Selection.Format.Line
        .Visible = msoTrue
        .Weight = 0.25
    End With
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 255, 200)
    End With
    With Selection.Format.Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 112, 192)
        .Weight = 2
    End With
End Sub

To plot your own patterns of sinusoidal curves just copy the macro code to one of the modules in your workbook sheets and experiment with different settings and parameters.

No comments:

Post a Comment

All comments are held for moderation. I reserve the right to edit, censor, delete and - if necessary - block comments.