<< Chapter < Page | Chapter >> Page > |
The plotting program named Graph06 can be used to plot the sinusoidal data as follows:
java Graph06 Dsp029
Listing 5. The code for GraphIntfc01. |
---|
public interface GraphIntfc01{
public int getNmbr();public double f1(double x);
public double f2(double x);public double f3(double x);
public double f4(double x);public double f5(double x);
}//end GraphIntfc01 |
When executed in this manner, the program named Graph06 instantiates an object of the class named Dsp029 and then calls the interface methods on that object to obtain the data to be plotted.
In this case, the constructor for the Dsp029 class populates the five array objects with sinusoidal data. The subsequent call to theinterface methods by the program named Graph06 causes that sinusoidal data to be retrieved and plotted by Graph06.
A brief description of each of the interface methods is provided in the following sections.
Plotting programs based on GraphIntfc01 can be used to plot any number of functions from one to five.
The method named getNmbr must return an integer value between 1 and 5 that specifies the number of functions to be plotted. Theplotting program uses that value to divide the total plotting surface into the specified number of plotting areas, and plots each of the functions named f1 through fn in one of those plotting areas.
As you can see in Listing 5 , each of these methods receives a double value as an incoming parameter and returns a double value. In essence, each of thesemethods receives a value for the horizontal coordinate x and returns the corresponding value for the vertical coordinate y.
Each of these methods provides the data to be plotted in one plotting area. The method named f1 provides the data for the top plotting area; the method named f2 provides the data for the first plotting area down from the top, and so forth.
(For example, if the getNmbr method returns a value of 4, the method named f5 will never be called. If getNmbr returns 5, the method named f5will be called to provide the data for the bottom plotting area.)
Each plotting area contains a horizontal axis. The plotting program moves across the horizontal axis in each plotting area one step at a time (moving in incremental steps equal to the plotting parameter named xCalcInc , which you will find if you examine the code for Graph06 ) .
At each step along the way, the plotting program calls the method associated with that plotting area, ( f1 , f2 , etc.) , passing the horizontal position as a parameter to the method.
The value returned by the method is assumed to be the vertical value associated with that horizontal position, and that is the vertical value that isplotted for that horizontal position.
Notification Switch
Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?