Skip to content Skip to navigation Skip to collection information

OpenStax_CNX

You are here: Home » Content » Introduction to G Programming » Graphs

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • NSF Partnership display tagshide tags

    This collection is included inLens: NSF Partnership in Signal Processing
    By: Sidney Burrus

    Click the "NSF Partnership" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • Featured Content display tagshide tags

    This collection is included inLens: Connexions Featured Content
    By: Connexions

    Click the "Featured Content" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

Graphs

Module by: Eduardo Perez. E-mail the author

Summary: The creation of this content was supported in some part by NSF grant 0538934.

Waveform Chart

Waveform Charts provide a historical graphical representation of numeric data.

The following example will build a simple G program that will allow you to chart a sine wave as it is being generated on a point-by-point basis using the equation:

y i = sin ( 0.2 x i ) y i =sin(0.2xi)
(1)
Figure 1: Waveform Chart
A waveform chart with containing a Sine Wave. The amplitude of the Sine wave is 1.

Start with a while loop and add into it a Multiply and Sine functions, a numeric constant with value 0.2 and a Boolean control to stop the loop when its value is True. Arrange the diagram to look as in Figure 2.

Figure 2: While Loop For Waveform Chart
A diagram of a 'while loop for waveform chart'. The diagram consists of several icons from left to right there is an orange box containing '0.2' and underneath this there is a blue box containg 'i'. lines connect these icons to a triangular box containing 'x'. A line then connects this triangle to a wave icon. Underneath this row of icons, there is a 'stop' icon connected to a red button icon.

To select a waveform chart, right click on the Front Panel window and select Waveform Chart from the Controls >> Modern >> Graph menu.

Figure 3: Selecting Waveform Chart
A row of icons. The row is labeled 'waveform chart'.

This places the Waveform Chart in the Front Panel window.

Figure 4: Waveform Chart in Front Panel window
An empty waveform chart.

In the Block Diagram window, make sure that the Waveform Chart terminal is inside the while loop. Wire the output of the Sine function to this terminal.

Notice that Waveform Chart terminal is that of a numeric output.

Figure 5: Waveform Chart Terminal
A diagram of a 'while loop for waveform chart'. The diagram consists of several icons from left to right there is an orange box containing '0.2' and underneath this there is a blue box containg 'i'. lines connect these icons to a triangular box containing 'x'. A line then connects this triangle to a wave icon and finally the wave icon is connected to a graph icon. Underneath this row of icons, there is a 'stop' icon connected to a red button icon.

Most modern computers will run this program too fast. Thus, before this program is executed, a delay of 125 milliseconds will be inserted in the while loop. This will allow users to see how the Waveform Chart operates as data samples are plotted in the chard.

From the Functions >> Programming >> Timing select Wait Until Next ms Multiple. This will put the while loop to sleep for the indicated number of milliseconds.

Figure 6: Wait Until Next ms Multiple
A row of four icons labeled from left to right, 'tick count (ms)', 'wait (ms)', and 'wait until ne..'. This row is listed under the level headers Programming and Timing.

Drop the Wait Until Next ms Multiple function inside the loop and wire a constant to it with the value 125. This will delay the loop for 125 milliseconds. The final Waveform Chart program is shown in Figure 7.

Figure 7: Waveform Chart Program
A diagram of a 'while loop for waveform chart'. The diagram consists of several icons from left to right there is an orange box containing '0.2' and underneath this there is a blue box containg 'i'. lines connect these icons to a triangular box containing 'x'. A line then connects this triangle to a wave icon and finally the wave icon is connected to a graph icon. Underneath this row of icons, there is another row of icons from left to right there is a blue box containing '125' that is also connected to a metronome icon. There is also a 'stop' icon connected to a red button icon.

The default graphing mode of the Waveform Chart is autoscaling. You will notice the auto-scaling property when the program first begins to run and the y-axis, labeled Amplitude, updates automatically as new numerical values are aggregated and displayed on the chart.

Figure 8: Waveform Chart Autoscaling
A diagram of a waveform chart autoscaling.

As the program continues to run, the graph continues to build as per the values associated with the x-axis, labeled Time, which correspond to the index value of the equations.

Figure 9: Accumulating Values for the Waveform Chart
A diagram of Accumulating values for the Waveform Chart.

As the program continues to run, the autoscaling property also applies to the x-axis. Noticed the updated x-axis. For this example, the x-axis will continue updating so as long as the program is running. This gives the appearance of a scrolling strip chart.

Figure 10: Scrolling X-Axis
A diagram showing a scrolling X-axis.

Stopping and restarting the G program retains the numeric history and continues to aggregate the values for display.

Figure 11: Graph History Retained Between Runs
A waveform chart containing a sine wave with an applitude of 1. In the middle of the wave, the bottom of the trough exists at y=0 instead of y=-1.

The Waveform Chart options can be easily updated by right clicking on the Waveform Chart and selecting the appropriate option to update from the pop-up menu.

Selecting Properties from this pop-up menu brings up the Waveform Chart dialog window (Figure 13).

Figure 12: Waveform Chart Pop-Up Menu
A waveform chart with a pop-up menu present on top of the chart. The item Properties is highlighted blue on the menu.

Figure 13: Waveform Chart Options Dialog Box
A typical windows window, showing the chart properties of the waveform chart.

Waveform Graph

The Waveform Graph allows numeric arrays to be displayed graphically in the Front Panel window.

Similar to the previous example, we will build a simple G program that will allow you to graph a sine wave using the equation:

y i = sin ( 0.2 x i ) y i =sin(0.2xi)
(2)

for i=0, 1, 2, … , 99.

Figure 14: Waveform Graph
A waveform chart with two simultaneously occurring sine waves. There are also noisy waves overlaid on top of the smoth sine waves labeled in blue and red.

Single Plot

Start by building the following program shown in Figure 15.

Figure 15: For Loop Sine Wave
An icon consisting of a blue box containing '100'connected to a big box containing a five items, a blue box containing an 'N'in the upper left of the big box, and then a row of icons from left to right an orange box containing '0.2'over another blue box containing 'i'. These icons connect via line to a triangle containing 'x'which is connected to a sine wave icon.

Right click on the Front Panel window, select Waveform Graph from the Modern >> Graph pop-up menu, and drop it on the Front Panel window.

Figure 16: Select Waveform Graph
A row of icons located in the levels headers Modern, graph.

In the Block Diagram window you will see the Waveform Graph terminal. Wire the Sine function output to the Waveform Graph terminal through the For Loop.

Figure 17: Waveform Graph Diagram
An icon consisting of a blue box containing '100'connected to a big box containing a five items, a blue box containing an 'N'in the upper left of the big box, and then a row of icons from left to right an orange box containing '0.2'over another blue box containing 'i'. These icons connect via line to a triangle containing 'x'which is connected to a sine wave icon. On the right of this big box an orange line connects to a 'waveform graph' icon.

Run the program. The resulting graph is shown in Figure 18.

Figure 18: Sine Wave Graph
A sine wave graph with an amplitude of 1.

Multiplots

In this example a sine wave and a noisy sine wave will be plotted. Modify the previous example to add noise to the sine operation as shown in Figure 19.

Figure 19: Sine and Noisy Sine Waveforms
An icon consisting of a blue box containing '100'connected to a big box containing a five items, a blue box containing an 'N' in the upper left of the big box, and then a row of icons from left to right an orange box containing '0.2'over another blue box containing 'i'. These icons connect via line to a triangle containing 'x' which is connected to a sine wave icon. Below the Sine wave icon there is an orange box containing '0.5'. Lines go from theses to icons to a final icon. between these two lines there is an icon of dice, which also points to the final icon.

Add a Build Array operator and wire the output of the Sine function and the multi-add operator containing the sine value plus some random noise between -0.5 and 0.5 to the Build Array operator. Wire the output of the Build Array operator to the Waveform Graph terminal.

Figure 20: Bundle Arrays for Multiplotting
An icon consisting of a blue box containing '100'connected to a big box containing a five items, a blue box containing an 'N' in the upper left of the big box, and then a row of icons from left to right an orange box containing '0.2'over another blue box containing 'i'. These icons connect via line to a triangle containing 'x' which is connected to a sine wave icon. Below the Sine wave icon there is an orange box containing '0.5'. Lines go from theses to icons to a final icon in the big box. Between these two lines there is an icon of dice, which also points to the final icon in the big box.Two orange lines extend from the big box to another icon outside the box which connects via a line to a 'waveform graph' icon.

You can continue adding 1D arrays to be multiplotted into a single Waveform Graph.

Run the program. The multiplot result is shown in Figure 21.

Figure 21: Multiplot
A sine wave on a graph with a noisy red wave plotted on top of it.

XY Graph

The XY Graph plots x vs. y numeric values contained in arrays.

Figure 22: XY Graph
An 'XY graph' that consist of a spiral plotted on the graph.

The example shown in Figure 23 generates the spiral shown in Figure 22.

Figure 23: Spiral G Program
An array of icon labeled 'Spiral G Program'.

Collection Navigation

Content actions

Download:

Collection as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add:

Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks