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

Three charges q_{1}=+3\mu C, q_{2}=+6\mu C and q_{3}=+8\mu C are located at (2,0)m (0,0)m and (0,3) coordinates respectively. Find the magnitude and direction acted upon q_{2} by the two other charges.Draw the correct graphical illustration of the problem above showing the direction of all forces.
Kate Reply
To solve this problem, we need to first find the net force acting on charge q_{2}. The magnitude of the force exerted by q_{1} on q_{2} is given by F=\frac{kq_{1}q_{2}}{r^{2}} where k is the Coulomb constant, q_{1} and q_{2} are the charges of the particles, and r is the distance between them.
Muhammed
What is the direction and net electric force on q_{1}= 5µC located at (0,4)r due to charges q_{2}=7mu located at (0,0)m and q_{3}=3\mu C located at (4,0)m?
Kate Reply
what is the change in momentum of a body?
Eunice Reply
what is a capacitor?
Raymond Reply
Capacitor is a separation of opposite charges using an insulator of very small dimension between them. Capacitor is used for allowing an AC (alternating current) to pass while a DC (direct current) is blocked.
Gautam
A motor travelling at 72km/m on sighting a stop sign applying the breaks such that under constant deaccelerate in the meters of 50 metres what is the magnitude of the accelerate
Maria Reply
please solve
Sharon
8m/s²
Aishat
What is Thermodynamics
Muordit
velocity can be 72 km/h in question. 72 km/h=20 m/s, v^2=2.a.x , 20^2=2.a.50, a=4 m/s^2.
Mehmet
A boat travels due east at a speed of 40meter per seconds across a river flowing due south at 30meter per seconds. what is the resultant speed of the boat
Saheed Reply
50 m/s due south east
Someone
which has a higher temperature, 1cup of boiling water or 1teapot of boiling water which can transfer more heat 1cup of boiling water or 1 teapot of boiling water explain your . answer
Ramon Reply
I believe temperature being an intensive property does not change for any amount of boiling water whereas heat being an extensive property changes with amount/size of the system.
Someone
Scratch that
Someone
temperature for any amount of water to boil at ntp is 100⁰C (it is a state function and and intensive property) and it depends both will give same amount of heat because the surface available for heat transfer is greater in case of the kettle as well as the heat stored in it but if you talk.....
Someone
about the amount of heat stored in the system then in that case since the mass of water in the kettle is greater so more energy is required to raise the temperature b/c more molecules of water are present in the kettle
Someone
definitely of physics
Haryormhidey Reply
how many start and codon
Esrael Reply
what is field
Felix Reply
physics, biology and chemistry this is my Field
ALIYU
field is a region of space under the influence of some physical properties
Collete
what is ogarnic chemistry
WISDOM Reply
determine the slope giving that 3y+ 2x-14=0
WISDOM
Another formula for Acceleration
Belty Reply
a=v/t. a=f/m a
IHUMA
innocent
Adah
pratica A on solution of hydro chloric acid,B is a solution containing 0.5000 mole ofsodium chlorid per dm³,put A in the burret and titrate 20.00 or 25.00cm³ portion of B using melting orange as the indicator. record the deside of your burret tabulate the burret reading and calculate the average volume of acid used?
Nassze Reply
how do lnternal energy measures
Esrael
Two bodies attract each other electrically. Do they both have to be charged? Answer the same question if the bodies repel one another.
JALLAH Reply
No. According to Isac Newtons law. this two bodies maybe you and the wall beside you. Attracting depends on the mass och each body and distance between them.
Dlovan
Are you really asking if two bodies have to be charged to be influenced by Coulombs Law?
Robert
like charges repel while unlike charges atttact
Raymond
What is specific heat capacity
Destiny Reply
Specific heat capacity is a measure of the amount of energy required to raise the temperature of a substance by one degree Celsius (or Kelvin). It is measured in Joules per kilogram per degree Celsius (J/kg°C).
AI-Robot
specific heat capacity is the amount of energy needed to raise the temperature of a substance by one degree Celsius or kelvin
ROKEEB
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