<< Chapter < Page
  Digital signal processing - dsp     Page 20 / 24
Chapter >> Page >

I suggest that you begin by compiling and running the following files to confirm that everything is working correctly on your machine before attemptingto compile and run the spectral analysis programs:

  • Dsp029.java
  • GraphIntfc01.java
  • Graph06.java

Make sure that you create an appropriate file named Dsp029.txt , as described in Figure 2 . You should be able to reproduce my results if everything is working correctly.

Once you confirm that things are working correctly, copy, compile, and run the spectral analysis programs. Experiment with the parameters and try tounderstand the result of making changes to the parameters. Confirm the flexibility of the DFT algorithm and the speed of the FFT algorithm.

Summary

In this module I have provided and explained programs that illustrate the impact of sampling and the Nyquist folding frequency.

I have also provided and explained several different programs used for performing spectral analysis. The first program was a very general program thatimplements a Discrete Fourier Transform (DFT) algorithm. I explained this program in detail.

The second program was a less general, but much faster program that implements a Fast Fourier Transform (FFT) algorithm. I will defer an explanation of this program until a future module. I provided it in this moduleso that you can use it and compare it with the DFT program in terms of speed and flexibility.

What's next?

Future modules will discuss other aspects of spectral analysis including:

  • Frequency resolution versus data length.
  • The relationship between the phase angle and delays in the time domain.
  • The reversible nature of the Fourier transform involving both forward and inverse Fourier transforms.
  • Additional material aimed towards an understanding of the signal processing concepts behind the FFT algorithm.

Complete program listings

Complete listings of all the programs discussed in this module follow.

Listing 16. Dsp029.java.
/* File Dsp029.java Copyright 2004, R.G.BaldwinRev 5/6/04 Generates and displays up to five sinusoidshaving different frequencies and amplitudes. Very useful for providing a visual illustration of theway in which frequencies above half the sampling frequency fold back down into the area boundedby zero and half the sampling frequency (the Nyquist folding frequency).Gets input parameters from a file named Dsp029.txt. If that file doesn't exist in thecurrent directory, the program uses a set of default parameters.Each parameter value must be stored as characters on a separate line in the file named Dsp029.txt.The required parameters are as follows: Data length as type intNumber of sinusoids as type int. Max value is 5. List of sinusoid frequency values as type double.List of sinusoid amplitude values as type double. The number of values in each of the lists mustmatch the value for the number of spectra. Note: All frequency values are specified as adouble representing a fractional part of the sampling frequency.Here is a set of sample parameter values. Don't allow blank lines at the end of the data in thefile. 400.05 0.10.9 1.11.9 2.190 9090 9090 The plotting program that is used to plot theoutput data from this program requires that the program implement GraphIntfc01. For example,the plotting program named Graph06 can be used to plot the data produced by this program. Whenit is used, the usage information is: java Graph06 Dsp029Tested using SDK 1.4.2 under WinXP. ************************************************/import java.util.*; import java.io.*;class Dsp029 implements GraphIntfc01{ final double pi = Math.PI;//for simplification//Begin default parameters int len = 400;//data lengthint numberSinusoids = 5; //Frequencies of the sinusoids double[]freq = {0.1,0.25,0.5,0.75,0.9}; //Amplitudes of the sinusoidsdouble[] amp = {75,75,75,75,75};//End default parameters //Following arrays will be populated with// sinusoidal data to be plotted 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];public Dsp029(){//constructor //Get the parameters from a file named// Dsp029.txt. Use the default parameters // if the file doesn't exist in the current// directory. if(new File("Dsp029.txt").exists()){getParameters(); }//end if//Note that this program always generates // five sinusoids, even if fewer than five// were requested as the input parameter // for numberSinusoids. In that case, the// extras are generated using default values // and simply ignored when the results are// plotted. //Create the raw data. Note that the// argument for a sinusoid at half the // sampling frequency would be (2*pi*x*0.5).// This would represent one half cycle or pi // radians per sample.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 //-------------------------------------------////This method gets processing parameters from // a file named Dsp029.txt and stores those// parameters in instance variables belonging // to the object of type Dsp029.void getParameters(){ int cnt = 0;//Temporary holding area for strings. Allow // space for a few blank lines at the end// of the data in the file. String[]data = new String[20];try{ //Open an input stream.BufferedReader inData = new BufferedReader(new FileReader("Dsp029.txt")); //Read and save the strings from each of// the lines in the file. Be careful to // avoid having blank lines at the end,// which may cause an ArrayIndexOutOfBounds // exception to be thrown.while((data[cnt] =inData.readLine()) != null){ cnt++;}//end while inData.close();}catch(IOException e){} //Move the parameter values from the// temporary holding array into the instance // variables, converting from characters to// numeric values in the process. cnt = 0;len = (int)Double.parseDouble(data[cnt++]);numberSinusoids = (int)Double.parseDouble( data[cnt++]); for(int fCnt = 0;fCnt<numberSinusoids; fCnt++){freq[fCnt] = Double.parseDouble(data[cnt++]);}//end for loop for(int aCnt = 0;aCnt<numberSinusoids; aCnt++){amp[aCnt] = Double.parseDouble(data[cnt++]);}//end for loop //Print parameter values.System.out.println(); System.out.println("Data length: " + len);System.out.println( "Number sinusoids: " + numberSinusoids);System.out.println("Frequencies"); for(cnt = 0;cnt<numberSinusoids;cnt++){ System.out.println(freq[cnt]); }//end for loopSystem.out.println("Amplitudes"); for(cnt = 0;cnt<numberSinusoids;cnt++){ System.out.println(amp[cnt]); }//end for loop}//end getParameters //-------------------------------------------////The following six methods are required by the // interface named GraphIntfc01. The plotting// program pulls the data values to be plotted // by calling these methods.public int getNmbr(){ //Return number of functions to// process. Must not exceed 5. return numberSinusoids;}//end getNmbr //-------------------------------------------//public double f1(double x){ int index = (int)Math.round(x);if(index<0 || index>data1.length-1){ return 0;}else{ return data1[index]; }//end else}//end function //-------------------------------------------//public double f2(double x){ int index = (int)Math.round(x);if(index<0 || index>data2.length-1){ return 0;}else{ return data2[index]; }//end else}//end function //-------------------------------------------//public double f3(double x){ int index = (int)Math.round(x);if(index<0 || index>data3.length-1){ return 0;}else{ return data3[index]; }//end else}//end function //-------------------------------------------//public double f4(double x){ int index = (int)Math.round(x);if(index<0 || index>data4.length-1){ return 0;}else{ return data4[index]; }//end else}//end function //-------------------------------------------//public double f5(double x){ int index = (int)Math.round(x);if(index<0 || index>data5.length-1){ return 0;}else{ return data5[index]; }//end else}//end function //-------------------------------------------//}//end class Dsp029

Questions & Answers

Discuss the differences between taste and flavor, including how other sensory inputs contribute to our  perception of flavor.
John Reply
taste refers to your understanding of the flavor . while flavor one The other hand is refers to sort of just a blend things.
Faith
While taste primarily relies on our taste buds, flavor involves a complex interplay between taste and aroma
Kamara
which drugs can we use for ulcers
Ummi Reply
omeprazole
Kamara
what
Renee
what is this
Renee
is a drug
Kamara
of anti-ulcer
Kamara
Omeprazole Cimetidine / Tagament For the complicated once ulcer - kit
Patrick
what is the function of lymphatic system
Nency Reply
Not really sure
Eli
to drain extracellular fluid all over the body.
asegid
The lymphatic system plays several crucial roles in the human body, functioning as a key component of the immune system and contributing to the maintenance of fluid balance. Its main functions include: 1. Immune Response: The lymphatic system produces and transports lymphocytes, which are a type of
asegid
to transport fluids fats proteins and lymphocytes to the blood stream as lymph
Adama
what is anatomy
Oyindarmola Reply
Anatomy is the identification and description of the structures of living things
Kamara
what's the difference between anatomy and physiology
Oyerinde Reply
Anatomy is the study of the structure of the body, while physiology is the study of the function of the body. Anatomy looks at the body's organs and systems, while physiology looks at how those organs and systems work together to keep the body functioning.
AI-Robot
what is enzymes all about?
Mohammed Reply
Enzymes are proteins that help speed up chemical reactions in our bodies. Enzymes are essential for digestion, liver function and much more. Too much or too little of a certain enzyme can cause health problems
Kamara
yes
Prince
how does the stomach protect itself from the damaging effects of HCl
Wulku Reply
little girl okay how does the stomach protect itself from the damaging effect of HCL
Wulku
it is because of the enzyme that the stomach produce that help the stomach from the damaging effect of HCL
Kamara
function of digestive system
Ali Reply
function of digestive
Ali
the diagram of the lungs
Adaeze Reply
what is the normal body temperature
Diya Reply
37 degrees selcius
Xolo
37°c
Stephanie
please why 37 degree selcius normal temperature
Mark
36.5
Simon
37°c
Iyogho
the normal temperature is 37°c or 98.6 °Fahrenheit is important for maintaining the homeostasis in the body the body regular this temperature through the process called thermoregulation which involves brain skin muscle and other organ working together to maintain stable internal temperature
Stephanie
37A c
Wulku
what is anaemia
Diya Reply
anaemia is the decrease in RBC count hemoglobin count and PVC count
Eniola
what is the pH of the vagina
Diya Reply
how does Lysin attack pathogens
Diya
acid
Mary
I information on anatomy position and digestive system and there enzyme
Elisha Reply
anatomy of the female external genitalia
Muhammad Reply
Organ Systems Of The Human Body (Continued) Organ Systems Of The Human Body (Continued)
Theophilus Reply
what's lochia albra
Kizito
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