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

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
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