<< Chapter < Page
  Digital signal processing - dsp     Page 13 / 24
Chapter >> Page >

Will discuss the code in fragments

As usual, I will discuss the code in fragments. A complete listing of the program is presented in Listing 19 near the end of the module. Because of the similarity of Dsp028 with Dsp029 discussed earlier, the fragments for Dsp028 will be much larger and will be explained in much less detail.

Beginning of the class named Dsp028

The class definition begins in Listing 8 . For reasons that you already understand, this class implements the interface named GraphIntfc01.

Listing 8. Beginning of the class named Dsp028.
class Dsp028 implements GraphIntfc01{ final double pi = Math.PI;//for simplification//Begin default parameters int len = 400;//data length//Sample that represents zero time. int zeroTime = 0;//Low and high frequency limits for the // spectral analysis.double lowF = 0.0; double highF = 1.0;int numberSpectra = 5; //Frequencies of the sinusoidsdouble[] freq = {0.1,0.2,0.3,0.4,0.5};//Amplitudes of the sinusoids double[]amp = {60,70,80,90,100}; //End default parameters

The code in Listing 8 defines a set of default parameter values that are used in the event that a file named Dsp028.txt does not exist in the current directory.

Declare array variables

The code in Listing 9 declares several array variables that will be used to point to array objects whose purposes are explained in the comments.

Listing 9. Declare array variables.
//Following arrays will contain data that is // input to the spectral analysis process.double[] data1;double[] data2;double[] data3;double[] data4;double[] data5;//Following arrays receive information back // from the spectral analysis that is not used// in this program. double[]real; double[]imag; double[]angle; //Following arrays receive the magnitude// spectral information back from the spectral // analysis process.double[] magnitude1;double[] magnitude2;double[] magnitude3;double[] magnitude4;double[] magnitude5;

The constructor

The constructor for the class begins in Listing 10 . The constructor begins by getting the parameters from a file named Dsp028.txt . If that file doesn't exist in the current directory, default parameters are used.

Listing 10. Beginning of the constructor.
public Dsp028(){//constructor if(new File("Dsp028.txt").exists()){getParameters(); }//end if

Always processes five sinusoids

For simplicity, this program always processes five sinusoids, even if fewer than five were requested as the input parameter for numberSpectra . In that case, the extra sinusoids are processed using default values and simplyignored when the results are plotted.

Create the raw sinusoidal data

The code in Listing 11 instantiates array objects and creates the sinusoidal data upon which spectral analysis will be performed.

Listing 11. Create the raw sinusoidal data.
//First create empty array objects. double[]data1 = new double[len];double[] data2 = new double[len]; double[]data3 = new double[len];double[] data4 = new double[len]; double[]data5 = new double[len];//Now populate the array objects for(int n = 0;n<len;n++){ data1[n]= amp[0]*Math.cos(2*pi*n*freq[0]); data2[n]= amp[1]*Math.cos(2*pi*n*freq[1]); data3[n]= amp[2]*Math.cos(2*pi*n*freq[2]); data4[n]= amp[3]*Math.cos(2*pi*n*freq[3]); data5[n]= amp[4]*Math.cos(2*pi*n*freq[4]); }//end for loop

Questions & Answers

how to study physic and understand
Ewa Reply
what is conservative force with examples
Moses
what is work
Fredrick Reply
the transfer of energy by a force that causes an object to be displaced; the product of the component of the force in the direction of the displacement and the magnitude of the displacement
AI-Robot
why is it from light to gravity
Esther Reply
difference between model and theory
Esther
Is the ship moving at a constant velocity?
Kamogelo Reply
The full note of modern physics
aluet Reply
introduction to applications of nuclear physics
aluet Reply
the explanation is not in full details
Moses Reply
I need more explanation or all about kinematics
Moses
yes
zephaniah
I need more explanation or all about nuclear physics
aluet
Show that the equal masses particles emarge from collision at right angle by making explicit used of fact that momentum is a vector quantity
Muhammad Reply
yh
Isaac
A wave is described by the function D(x,t)=(1.6cm) sin[(1.2cm^-1(x+6.8cm/st] what are:a.Amplitude b. wavelength c. wave number d. frequency e. period f. velocity of speed.
Majok Reply
what is frontier of physics
Somto Reply
A body is projected upward at an angle 45° 18minutes with the horizontal with an initial speed of 40km per second. In hoe many seconds will the body reach the ground then how far from the point of projection will it strike. At what angle will the horizontal will strike
Gufraan Reply
Suppose hydrogen and oxygen are diffusing through air. A small amount of each is released simultaneously. How much time passes before the hydrogen is 1.00 s ahead of the oxygen? Such differences in arrival times are used as an analytical tool in gas chromatography.
Ezekiel Reply
please explain
Samuel
what's the definition of physics
Mobolaji Reply
what is physics
Nangun Reply
the science concerned with describing the interactions of energy, matter, space, and time; it is especially interested in what fundamental mechanisms underlie every phenomenon
AI-Robot
what is isotopes
Nangun Reply
nuclei having the same Z and different N s
AI-Robot
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Digital signal processing - dsp. OpenStax CNX. Jan 06, 2016 Download for free at https://legacy.cnx.org/content/col11642/1.38
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?

Ask