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

I am good and you I am from sierra Leone and I am new her
kanu Reply
u are welcome bro, here is a good platform for you to be
That i know,thanks bro.
what the main definition of economic
Uhara Reply
Essay about Microsoft
Kwena Reply
what is economics
Julie Reply
what do you mean by means in economics
economic is the wealth of a country.
monetary policy is refer to as being expansionary or contractionary.
pls who can help me to explain money market and capital market
money market is base on short term loan which is within one year period while capital market is long term loan more than one year...
money market is a market were short term loans are dealt with while capital market is a market were long term loans are traded
What is mean by monetory policy
monetary polices are rules that control the rate of monetary exchange in an economic as a whole.
wealth of the nation
important of unemployment
Otwe Reply
Important of unemployed
what is meaning scarcity
Scarcity can be define as human wants to goods,services,resources for exceed of what is available
hi guys
How are you
what is consumer
Brenda Reply
how do consumer help people
by export trading
How do you mean Jayah
what is different between price and quantity
what is MRS
definition of economics according to Adam Smith
Ijeoma Reply
economic is a wealth of nation
in the view of Adam Smith economics is the study of activities of people in production of wealth
Economics is any human activity that lead to the provision of substance and or amassing wealth.
What do you really think is the remedy for scarcity in Nigeria 🇳🇬
John Reply
different the term economics
zfekere Reply
importance of studying economics
Haruna Reply
importance of economics
different the term economics
mixed economic
you have just been appointed in the director of finance for your state internal revenue board with the knowledge of elasticity advice the state government on how the I.G.R of the state could be raised through exercise duties bearing in mind the implication and incident of taxing setting products
Kenechukwu Reply
Hello,Thanks for your replay
mention 5 characteristics of traditional societies
Pono Reply
dominance of agriculture and ignorance of development avenues are some characteristics of traditional societies.
what's defined as unemployment
Lyrikal Reply
what is elasticity
Olakunle Reply
Elasticity is defined as the degree of responsiveness of quantity demanded to slight change in price, cost of other products and income of consumer.....
elasticity simply means change. it is the degree of responsiveness of quantity demanded of a commodity to changes in the price of a commodity
what is monetary policy
Monetary Policy; is the objectives of the central bank in exercising its control over money, interest rates, and credit conditions.
how can I connect myself to this Ambrose platform
kanu Reply
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?