<< 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

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
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