<< Chapter < Page
  Digital signal processing - dsp     Page 8 / 19
Chapter >> Page >

The constructor

The constructor begins in Listing 4 . The code in Listing 4 is identical to that shown earlier in Listing 2 . This code generates the five sinusoidal pulses and stores the data representing those pulses in the arrays referred to by data1 through data5 . So far, except for the declaration of some extra variables, this program isn't much different from the program named Dsp031a discussed earlier in this module.

Listing 4. Beginning of the constructor.
public Dsp031(){//constructor //Create the raw datafor(int x = 0;x<len/16;x++){ data1[x]= amp*Math.cos(2*pi*x*freq); }//end for loopfor(int x = 0;x<len/8;x++){ data2[x]= amp*Math.cos(2*pi*x*freq); }//end for loopfor(int x = 0;x<len/4;x++){ data3[x]= amp*Math.cos(2*pi*x*freq); }//end for loopfor(int x = 0;x<len/2;x++){ data4[x]= amp*Math.cos(2*pi*x*freq); }//end for loopfor(int x = 0;x<len;x++){ data5[x]= amp*Math.cos(2*pi*x*freq); }//end for loop

Perform the spectral analysis

The remainder of the constructor is shown in Listing 5 . This code calls the transform method of the ForwardRealToComplex01 class five times in succession to perform the spectral analysis on each of the five pulses shown in Figure 1 .

(I explained the transform method in detail in the previous module titled Spectrum Analysis using Java, Sampling Frequency, Folding Frequency, and the FFT Algorithm .)

Listing 5. Perform the spectral analysis.
mag1 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data1,real, imag,angle,mag1,zeroTime,lowF,highF);mag2 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data2,real, imag,angle,mag2,zeroTime,lowF,highF);mag3 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data3,real, imag,angle,mag3,zeroTime,lowF,highF);mag4 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data4,real, imag,angle,mag4,zeroTime,lowF,highF);mag5 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data5,real, imag,angle,mag5,zeroTime,lowF,highF);}//end constructor

Each time the transform method is called, it computes the magnitude spectrum for the incoming data and saves it in the output array.

(Note that the real, imag, and angle arrays are not used later, so they are discarded each time a new spectral analysis is performed.)

The interface methods

The Dsp031 class also implements the interface named GraphIntfc01 . The remaining code in the program consists of the methods required to satisfy thatinterface. Except for the identification of the arrays from which the methods extract data to be returned for plotting, these methods are identical to thosedefined in the earlier class named Dsp031a . Therefore, I won't discuss them further.

Questions & Answers

Explain the following terms . (1) Abiotic factors in an ecosystem
Nomai Reply
Abiotic factors are non living components of ecosystem.These include physical and chemical elements like temperature,light,water,soil,air quality and oxygen etc
Qasim
what is biology
daniel Reply
what is diffusion
Emmanuel Reply
passive process of transport of low-molecular weight material according to its concentration gradient
AI-Robot
what is production?
Catherine
Pathogens and diseases
how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
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 respiration
Deborah
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan 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