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

The code in Listing 1 defines a convenience constant representing the value of pi and then defines the set of default parameters that will be used by the program in the event that the file named Dsp029.txt does not exist in the current directory.

Create array objects to hold sinusoidal data

The code in Listing 2 creates five array objects that will be populated with sinusoidal data.

Listing 2. Create array objects to hold sinusoidal data.
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];

Get the parameters

The constructor begins in Listing 3 . The code in this fragment calls the method named getParameters to read the parameters from the file named Dsp029.txt .

Listing 3. Get the parameters.
public Dsp029(){//constructor if(new File("Dsp029.txt").exists()){getParameters(); }//end if

Before calling the getParameters method, however, the program calls the exists method of the File class to confirm that the file actually exists. If the file doesn't exist, thecall to getParameters is skipped, causing the default parameters defined in Listing 1 to be used instead.

The getparameters method

The getParameters method is straightforward, so I won't discuss it in detail. You can view it in Listing 16 . Suffice it to say that the method reads the input parameters from the disk file and writes their valuesinto the variables declared in Listing 1 , overwriting the default values stored in those variables.

In addition, the getParameters method displays the values read from the disk file in the format shown in Figure 4 and Figure 6 .

Create the sinusoidal data

For simplicity, this program always generates five sinusoids, even if fewer than five were requested as the input parameter value for numberSinusoids . In that case, the extra sinusoids are generated using default values and are simply ignored when the sinusoids are plotted.

The code fragment in Listing 4 creates the sinusoidal data for each of the five specified frequencies and saves that data in the array objects that werecreated in Listing 2 .

Listing 4. Create the sinusoidal data.
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}//end constructor

The end of the constructor

Listing 4 also signals the end of the constructor. When the constructor terminates, an object of the Dsp029 class has been instantiated. The five arrays shown in Listing 4 have been populated with sinusoidal data according to the parameters read from the file named Dsp029.txt or according to the default values of the parameters shown in Listing 1 .

Plotting the sinusoidal data

In order to better understand what is going on in the plotting process, it would be helpful for you to review the module titled Plotting Engineering and Scientific Data using Java . However, assuming that you don't have the time to do that, I will provide a very brief explanation asto how the plotting programs work.

Questions & Answers

I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?