<< Chapter < Page
  Digital signal processing - dsp     Page 13 / 25
Chapter >> Page >

To make a long story short, the class named Convolve01 provides a static method named convolve , which applies an incoming convolution operator to an incoming set of data and deposits thefiltered data in an output array whose reference is received as an incoming parameter.

This class could easily be broken out and put in a library as a stand-alone class, or the convolve method could be added to a class containing a variety of DSP methods.

The discrete Fourier transform (dft)

The entire class named Dft01 is shown in Listing 18 .

As with convolution, if you already understand the discrete Fourier transform, you will probably find the code in this class to be straightforward.If not, the code will probably still be straightforward, but the reasons for the code may be obscure. Since the purpose of this module is not to explain digitalsignal processing concepts, I won't attempt to provide a detailed explanation for the code in this method at this time.

Listing 18. The discrete Fourier transform (DFT).
class Dft01{ public static void dft(double[] data,int dataLen, double[]spectrum){ //Set the frequency increment to// the reciprocal of the data // length. This is convenience// only, and is not a requirement // of the DFT algorithm.double delF = 1.0/dataLen; //Outer loop iterates on frequency// values. for(int i=0; i<dataLen;i++){ double freq = i*delF;double real = 0; double imag = 0;//Inner loop iterates on time- // series points.for(int j=0; j<dataLen; j++){ real += data[j]*Math.cos( 2*Math.PI*freq*j);imag += data[j]*Math.sin(2*Math.PI*freq*j); spectrum[i]= Math.sqrt( real*real + imag*imag);}//end inner loop }//end outer loop}//end dft }//end Dft01

Once again, to make a long story short, this class provides a static method named dft , which computes and returns the amplitude spectrum of an incoming time series.

The amplitude spectrum is computed as the square root of the sum of the squares of the real and imaginary parts.

A DFT algorithm can compute any number of points in the frequency domain. In this case, the number of points computed in the frequency domain is equal to thenumber of samples in the incoming time series, which is a fairly common practice.

The method deposits the frequency data in an array whose reference is received as an incoming parameter.

As with convolution, this class could easily be broken out and put in a library as a stand-alone class, or the dft method could be added to a class containing a variety of DSP methods.

Two plotting programs

Now that you have examined the sample data-generator programs, some of you may be interested in an explanation of the plotting program itself.

If you are interested only in how to use the plotting programs, and are not interested in the programming details of the plotting programs, skip ahead tothe section titled Run the Program .

If you are interested in learning how the plotting programs do what they do, keep reading.

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