<< Chapter < Page
  Digital signal processing - dsp     Page 14 / 14
Chapter >> Page >

Case C output in numeric form

The output produced by the code in Listing 7 is shown in Figure 14 .

Figure 14. Case C output in numeric form.
Case C Real:0.0 0.999 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0imag: 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

If you plot the real and imaginary input values from Listing 7 , you will see that they match the input values in Figure 13 . If you plot the real and imaginary output values in Figure 14 , you will see that they match the output values shown in Figure 13 .

Listing 7 signals the end of the main method.

The display method

Listing 8 shows the code for a simple method named display . The purpose of the display method is to display a real series and an imaginary series, each contained in an incoming array object of type double . The double values are truncated to no more than four digits before displaying them. Then they aredisplayed on a single line.

Listing 8. The display method.
static void display(double[] real,double[] imag){System.out.println("Real: "); for(int cnt=0;cnt<real.length;cnt++){ System.out.print(((int)(1000.0*real[cnt])) /1000.0 + " ");}//end for loop System.out.println();System.out.println("imag: "); for(int cnt=0;cnt<imag.length;cnt++){ System.out.print(((int)(1000.0*imag[cnt])) /1000.0 + " ");}//end for loop System.out.println();}//end display }//end class Fft02

Listing 8 also signals the end of the controlling class named Fft02 .

Run the program

I encourage you to copy and compile the program that you will find in Listing 9 . Experiment with different complex input series.

I also encourage you to download the applet from (External Link) or from here and experiment with it as well. Compare the numeric output produced by this program with the graphic output produced by theapplet.

Finally, I encourage you to examine the source code for the applet. Concentrate on that portion of the source code that performs the FFT. Hopefully,what you have learned in this module will make it easier for you to understand the source code for the FFT.

Summary

In this module, I have explained some of the underlying signal processing concepts that make the FFT possible. I illustrated those concepts in a programdesigned specifically to be as simple as possible while still illustrating the concepts.

Now that you understand those concepts, you should be able to better understand explanations of the mechanics of the FFT algorithm that appear onvarious websites.

Complete program listings

A complete listing of the program is provided in Listing 9 below.

Listing 9. Fft02.java.
/*File Fft02.java Copyright 2004, R.G.Baldwin Rev 4/30/04This program DOES NOT implement an FFT algorithm. Rather,this program illustrates the underlying FFT concepts in a form that is much more easilyunderstood than is normally the case with an actual FFT algorithm. The steps in theimplementation of a typical FFT algorithm are as follows:1. Decompose an N-point complex series into N individual complex values, each consisting of asingle complex sample. The order of the decomposition in an FFT algorithm is rathercomplicated. It is this order of decomposition, and the order of the subsequent recombination oftransform results that causes the FFT to be so fast. It is also that order that makes thealgorithm somewhat difficult to understand. This program does not implement that order ofdecomposition and recombination. 2. Calculate the transform of each of the Ncomplex samples, treating each as if it were located at the beginning of the complex series.This step is trivial. The real part of the transform of a single complex sample located atthe beginning of the series is a complex constant whose values are proportional to the real andimaginary values that make up the complex sample. 3. Correct each of the N transform results toreflect the actual position of the complex sample in the series. This involves the application ofsine and cosine curves to the real and imaginary parts of the transform. This step is usuallycombined with the recombination step that follows.4. Recombine the N transform results into a single transform result that represents thetransform of the original complex series. This is a very complicated operation in a real FFTalgorithm. It must reverse the order of decomposition in the first step describedearlier. As mentioned earlier, it is the order of the decomposition and subsequent recombinationthat minimizes the arithmetic operations required and gives the FFT its tremendous speed. Thisprogram does not implement the special order of decomposition and recombination used in an actualFFT algorithm. This program creates three separate complexseries, applies the processes listed above to each of those series, and displays the results onthe screen. No attempt is made to manage the decomposition and the subsequent recombination inthe manner of a true FFT algorithm. Therefore, this program is designed to illustrate theprocesses involved, and is not designed to provide the speed of a true FFT algorithm.The decomposition process in this program takes the complex samples in the order that they appearin the input complex series. The transform of each complex sample is simplythe sample itself. This is the result that would be obtained by actually computing the transformof the complex sample if the sample were the first sample in the series.The transform result for each complex sample is then corrected by applying sine and cosine curvesto reflect the actual position of the complex sample within the complex series.The real and imaginary parts of the corrected transform results are then added to accumulatorsthat are used to accumulate the corrected real and imaginary parts from the correctedtransforms for all of the individual complex samples.Once the real and imaginary parts have been accumulated for all of the complex samples, thereal part of the accumulator represents the real part of the transform of the original complexseries. The imaginary part of the accumulator represents the imaginary part of the transform ofthe original complex series. Tested using SDK 1.4.2 under WinXP************************************************/ class Fft02{public static void main(String[] args){//Instantiate an object that will implement // the processes used in an FFT, but not in// the order required by an FFT algorithm. Transform transform = new Transform();//Prepare the input data and the output // arrays for Case A. Note that for this// case, the input complex series contains // non-zero values only in the real part.// Also, most of the values in the real part // are zero.System.out.println("Case A"); double[]realInA = {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1};double[] imagInA ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; double[]realOutA = new double[16];double[] imagOutA = new double[16]; //Perform the transform and display the// transformed results for the original // complex series.transform.doIt(realInA,imagInA,2.0,realOutA, imagOutA);display(realOutA,imagOutA); //Process and display the results for Case B.// Note that the input complex series // contains non-zero values in both the real// and imaginary parts. However, most of the // values in the real and imaginary parts are// zero. System.out.println("\nCase B");double[] realInB ={0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; double[]imagInB = {0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,-1};double[] realOutB = new double[16]; double[]imagOutB = new double[16];transform.doIt(realInB,imagInB,2.0,realOutB, imagOutB);display(realOutB,imagOutB); //Process and display the results for Case C.// Note that the input complex series // contains non-zero values in both the real// and imaginary parts. In addition, very // few of the values in the complex series// have a value of zero. (The values of the // complex samples actually describe a cosine// curve and a sine curve.) System.out.println("\nCase C");double[] realInC ={1.0,0.923,0.707,0.382,0.0,-0.382,-0.707, -0.923,-1.0,-0.923,-0.707,-0.382,0.0,0.382,0.707,0.923}; double[]imagInC = {0.0,-0.382,-0.707,-0.923,-1.0,-0.923,-0.707,-0.382,0.0,0.382,0.707,0.923, 1.0,0.923,0.707,0.382};double[] realOutC = new double[16]; double[]imagOutC = new double[16];transform.doIt(realInC,imagInC,16.0,realOutC, imagOutC);display(realOutC,imagOutC); }//end main//===========================================// //The purpose of this method is to display// a real series and an imaginary series, // each contained in an incoming array object// of type double. The double values are // truncated to no more than four digits// before displaying them. Then they are // displayed on a single line.static void display(double[] real,double[] imag){System.out.println("Real: "); for(int cnt=0;cnt<real.length;cnt++){ System.out.print(((int)(1000.0*real[cnt])) /1000.0 + " ");}//end for loop System.out.println();System.out.println("imag: "); for(int cnt=0;cnt<imag.length;cnt++){ System.out.print(((int)(1000.0*imag[cnt])) /1000.0 + " ");}//end for loop System.out.println();}//end display }//end class Fft02//=============================================// //This class applies the processes normally used// in an FFT algorithm. However, this class does // not apply those processes in the special order// required of an FFT algorithm. It is that // special order that minimizes the arithmetic// requirements of an FFT algorithm and causes it // to be very fast. The purpose of an object of// this class is to illustrate the processes in a // more easily understood fashion that is often// the case with an actual FFT algorithm. class Transform{void doIt(double[] realIn,double[]imagIn, double scale,double[]realOut, double[]imagOut){ //Each complex value in the incoming arrays// represents both a complex sample and the // transform of that complex sample under the// assumption that the complex sample appears // at the beginning of the series.//Correct the transform result for each of // the complex samples in the series to// reflect the actual position of the complex // sample in the series. Add the corrected// transform result into accumulators in // order toproduce the transform of the // original complex series.for(int cnt = 0;cnt<realIn.length;cnt++){ correctAndRecombine(realIn[cnt], imagIn[cnt], cnt,realIn.length, scale,realOut, imagOut);}//end for loop }//end doIt//===========================================// //This method accepts an incoming complex// sample value and the position in the series // associated with that sample. The method// calculates the real and imaginary transform // values associated with that complex sample// when it is located at the specified // position. Then it updates the corresponding// real and imaginary values contained in array // objects used to accumulate the real and// imaginary values for all of the samples. // References to the array objects are received// as input parameters. Outgoing results are // scaled by an incoming parameter in an// attempt to cause the output values to fall // within a reasonable range in case someone// wants to plot them. void correctAndRecombine(double realSample,double imagSample, int position,int length,double scale,double[] realOut,double[]imagOut){ //Calculate the complex transform values for// each sample in the complex output series. for(int cnt = 0; cnt<length; cnt++){ double angle =(2.0*Math.PI*cnt/length)*position; //Calculate output based on real inputrealOut[cnt] +=realSample*Math.cos(angle)/scale; imagOut[cnt]+= realSample*Math.sin(angle)/scale;//Calculate output based on imag input realOut[cnt]-= imagSample*Math.sin(angle)/scale;imagOut[cnt] +=imagSample*Math.cos(angle)/scale; }//end for loop}//end correctAndRecombine }//end class transform

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Java1486-Fun with Java, Understanding the Fast Fourier Transform (FFT) Algorithm
  • File: Java1486.htm
  • Published: 01/04/05

Baldwin explains the underlying signal processing concepts that make the Fast Fourier Transform (FFT) algorithm possible.

Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

-end-

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
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