Fourier Series Approximation to a Square Wave


The plot below shows a sequence of approximations to a square wave constructed by adding together sinusoids. It is implemented by a Java class derived from Plot that computes the data to be plotted on the fly:


If your browser recognized the applet tag, you would see an applet here.

Note that you can zoom in on any region of the graph by drawing a box. Start at the upper left corner of the region you wish to view in more detail, and drag downwards and to the right. Dragging upwards instead allows you to zoom out. When zooming out, a reference box is drawn that will represent the current view, and dragging will cause a box to be displayed that represents the new view. Zooming out will only go as far as the original scale. Clicking on the "fill" button at the upper right brings all data within range.

The source code defines a class PlotFourierSeries derived from Plot. This class contains a sequence of Java statements in its init() method that configures and constructs the plot. This particular example also demonstrates a number of features. In particular, no marks are made at all for each plotted point, so the plot consists entirely of connected lines. The X and Y ranges and tick marks are not given, so they get computed automatically to just fit the data.


Up to the Example index - Forward to a black and white plot using unique marks
Copyright © 1997, The Regents of the University of California. All rights reserved.
Last updated: 10/13/97, comments to: eal@eecs.berkeley.edu