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

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
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