<< 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 small and Microbuisenes
tadesse Reply
what is model
Daniel Reply
The wealth of Nations
Yusuf Reply
the wealth of nations, is it the first?
Yes very sure it was released in 1759
thank you Yusuf.
then when did he died?
17 July 1790 Born: 16 June 1723, Kirkcaldy, United Kingdom Place of death: Panmure House, Edinburgh, United Kingdom
that's my today questions, thank you Yusuf it's bed time see u after.
what is fiscal policy
kemigisha Reply
what's mode?
Umar Reply
mode is the highest occurring frequency in a distribution
mode is the most commonly occurring item in a set of data.
Please, what is the difference between monopoly and monopsony?
Olaleye Reply
is there monopsony word?
I have no idea though
please, in which year Adam smith was born?
monopsony is when there's only one buyer while monopoly is when there's only one producer.
who have idea on Banter
like trade by barter?
Monopoly is when there's excessively one seller and there is no entry in the market while monopsony is when there is one buyer
Adam smith was born in 1723
 (uncountable) Good humoured, playful, typically spontaneous conversation. verb (intransitive) To engage in banter or playful conversation. (intransitive) To play or do something amusing. (transitive) To tease mildly.
which book Adam smith published first? the first book of Adam smith pls.
what is market power and how can it affect an economy?
Gab Reply
market power:- where a firm is said to be a price setter.market power benefits the powerful at the expense of others.
Market power refers to the ability of a firm (or group of firms) to raise and maintain price above the level that would prevail under competition is referred to as market or monopoly power. The exercise of market power leads to reduced output and loss of economic welfare
find information about the national budget
three branches of economics in which tourism is likely to figure
Makgotso Reply
What are those three branches?
explain why Nigeria adopted labour intensive techniques to capital intensive techniques
Terdoo Reply
meaning of monopolystic competetion?
Jethail Reply
can I join the group
what is economic integration
Mohamed Reply
why does it makes sense to let the sewage disposal company in your town have a monopoly?
Janice Reply
how might a monopoly affect price?
how might a monopoly affect prices?
The principle of Economic is one to be involved in any economic buying substance
Anastassiya Reply
reason of corporation
What is economic integration
what are the principle of economics?
oche Reply
What is (Qs)
Bigi Reply
What is (Qs) and (Qd)
Quantity of supply and Quantity of demand
Qs: Is quantity of supply and Qd: quantity of demand
give as me quantitys
among all the definition of economics which of the definition is generally acceptable?
i science that studies human behavior as a relationship between ends and scarcity that have alternative uses
what are the principle of economics?
what is small and micro busenese
why small buiseness ineconomic development
how to start a small busines
what are the source for business ideas?
what is franchising?
what are the diffirent forms of business organization?
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?