<< 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?
Umar
Yes very sure it was released in 1759
Yusuf
thank you Yusuf.
Umar
then when did he died?
Umar
17 July 1790 Born: 16 June 1723, Kirkcaldy, United Kingdom Place of death: Panmure House, Edinburgh, United Kingdom
Yusuf
1790
Yusuf
that's my today questions, thank you Yusuf it's bed time see u after.
Umar
what is fiscal policy
kemigisha Reply
what's mode?
Umar Reply
mode is the highest occurring frequency in a distribution
Bola
mode is the most commonly occurring item in a set of data.
Umar
Please, what is the difference between monopoly and monopsony?
Olaleye Reply
is there monopsony word?
Umar
I have no idea though
Umar
please, in which year Adam smith was born?
Umar
monopsony is when there's only one buyer while monopoly is when there's only one producer.
Bola
who have idea on Banter
Ibrahim
like trade by barter?
Bola
Monopoly is when there's excessively one seller and there is no entry in the market while monopsony is when there is one buyer
kemigisha
Adam smith was born in 1723
Bola
 (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.
Umar
which book Adam smith published first? the first book of Adam smith pls.
Umar
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.
Umar
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
Kartheek
find information about the national budget
Molahlegi
three branches of economics in which tourism is likely to figure
Makgotso Reply
What are those three branches?
IlRegno
explain why Nigeria adopted labour intensive techniques to capital intensive techniques
Terdoo Reply
meaning of monopolystic competetion?
Jethail Reply
can I join the group
Nonso
yes.
Nurudeen
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?
Janice
how might a monopoly affect prices?
Janice
The principle of Economic is one to be involved in any economic buying substance
Anastassiya Reply
reason of corporation
Mohamed
What is economic integration
Mohamed
what are the principle of economics?
oche Reply
What is (Qs)
Bigi Reply
What is (Qs) and (Qd)
Bigi
Quantity of supply and Quantity of demand
Dilshoda
Qs: Is quantity of supply and Qd: quantity of demand
Cabdikariim
give as me quantitys
ahmed
among all the definition of economics which of the definition is generally acceptable?
oche
i science that studies human behavior as a relationship between ends and scarcity that have alternative uses
ousman
okay......
oche
what are the principle of economics?
oche
what is small and micro busenese
tadesse
why small buiseness ineconomic development
tadesse
how to start a small busines
tadesse
what are the source for business ideas?
tadesse
what is franchising?
tadesse
what are the diffirent forms of business organization?
tadesse
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?

Ask