<< 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 do you get the 2/50
Abba Reply
number of sport play by 50 student construct discrete data
Aminu Reply
width of the frangebany leaves on how to write a introduction
Theresa Reply
Solve the mean of variance
Veronica Reply
Step 1: Find the mean. To find the mean, add up all the scores, then divide them by the number of scores. ... Step 2: Find each score's deviation from the mean. ... Step 3: Square each deviation from the mean. ... Step 4: Find the sum of squares. ... Step 5: Divide the sum of squares by n – 1 or N.
kenneth
what is error
Yakuba Reply
Is mistake done to something
Vutshila
Hy
anas
hy
What is the life teble
anas
hy
Jibrin
statistics is the analyzing of data
Tajudeen Reply
what is statics?
Zelalem Reply
how do you calculate mean
Gloria Reply
diveving the sum if all values
Shaynaynay
let A1,A2 and A3 events be independent,show that (A1)^c, (A2)^c and (A3)^c are independent?
Fisaye Reply
what is statistics
Akhisani Reply
data collected all over the world
Shaynaynay
construct a less than and more than table
Imad Reply
The sample of 16 students is taken. The average age in the sample was 22 years with astandard deviation of 6 years. Construct a 95% confidence interval for the age of the population.
Aschalew Reply
Bhartdarshan' is an internet-based travel agency wherein customer can see videos of the cities they plant to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400 a. what is the probability of getting more than 12,000 hits? b. what is the probability of getting fewer than 9,000 hits?
Akshay Reply
Bhartdarshan'is an internet-based travel agency wherein customer can see videos of the cities they plan to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400. a. What is the probability of getting more than 12,000 hits
Akshay
1
Bright
Sorry i want to learn more about this question
Bright
Someone help
Bright
a= 0.20233 b=0.3384
Sufiyan
a
Shaynaynay
How do I interpret level of significance?
Mohd Reply
It depends on your business problem or in Machine Learning you could use ROC- AUC cruve to decide the threshold value
Shivam
how skewness and kurtosis are used in statistics
Owen Reply
yes what is it
Taneeya
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