<< Chapter < Page
  Digital signal processing - dsp     Page 10 / 27
Chapter >> Page >

Let's see some code!

I will present and explain this class in fragments. A complete listing of the class is provided in Listing 35 near the end of the module.

Beginning of the class named PlotALot01

As mentioned earlier, this class contains a main method. The main method is provided so that the class can be run as an application for self-test purposes, which is common practice in Javaprogramming. The main method also illustrates the proper use of the class.

The beginning of the class and the beginning of the main method are shown in Listing 1 .

Listing 1. Beginning of the class named PlotALot01.
public class PlotALot01{ public static void main(String[]args){ PlotALot01 plotObjectA =new PlotALot01("A",158,237,36,5,4,4); PlotALot01 plotObjectB = new PlotALot01("B");

Instantiate two plotting objects

Listing 1 instantiates two independent plotting objects. The first plotting object, referred to by plotObjectA is instantiated by calling the constructor that accepts plotting parameters. A description of each of theconstructor parameters was provided earlier . You may find it useful to compare the values shown in Listing 1 with the overall plotting parameters listed earlier to confirm how they are related.

The second plotting object, referred to by plotObjectB is instantiated by calling the constructor that accepts only the page title as aparameter and uses default values for all of the plotting parameters. You will see those default values later in the code.

Feed the plotting object titled "A"

Listing 2 contains a for loop that feeds 275 values to the plotting object titled "A". Most of the code in Listing 2 is required to set fifteen specific values to test for propertransitions as described earlier. This code is straightforward and shouldn't require further explanation.

(I was able to determine the correct locations for these values by knowing the size of the Frame, inset values for the Frame, the space betweentraces, the number of pixels dedicated to each sample, etc.)

Listing 2. Feed the plotting object titled "A".
for(int cnt = 0;cnt<275;cnt++){ if(cnt == 147){plotObjectA.feedData(0); }else if(cnt == 148){plotObjectA.feedData(0); }else if(cnt == 149){plotObjectA.feedData(25); }else if(cnt == 150){plotObjectA.feedData(-25); }else if(cnt == 151){plotObjectA.feedData(25); }else if(cnt == 152){plotObjectA.feedData(0); }else if(cnt == 153){plotObjectA.feedData(0); }else if(cnt == 26){plotObjectA.feedData(0); }else if(cnt == 27){plotObjectA.feedData(0); }else if(cnt == 28){plotObjectA.feedData(20); }else if(cnt == 29){plotObjectA.feedData(20); }else if(cnt == 30){plotObjectA.feedData(-20); }else if(cnt == 31){plotObjectA.feedData(-20); }else if(cnt == 32){plotObjectA.feedData(0); }else if(cnt == 33){plotObjectA.feedData(0); }else{plotObjectA.feedData( (Math.random() - 0.5)*25);}//end else }//end for loop

White random noise

The final statement in Listing 2 uses a random number generator to feed white random noise to the plotting object for all data values other than the fifteendata values specified in the preceding statements. You can see the random values plotted and marked by round ovals in Figure 5 .

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
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