<< Chapter < Page
  Digital signal processing - dsp     Page 13 / 14
Chapter >> Page >
Listing 17. InverseComplexToRealFFT01.java,
/*File InverseComplexToRealFFT01.java Copyright 2004, R.G.BaldwinRev 5/24/04 The static method named inverseTransform performsa complex to real Fourier transform using a complex-to-complex FFT algorithm. A specificparameter is passed to the FFT algorithm that causes this to be an inverse Fourier transform.See InverseComplexToReal01 for a version that does not use an FFT algorithm but uses a DFTalgorithm instead. Incoming parameters are:double[] realIn - incoming real datadouble[] imagIn - incoming imaginary datadouble[] realOut - outgoing real dataRequires spectral input data extending from zero to the sampling frequency.Assumes real input consists of positive frequency points for a symmetric real frequencyfunction. That is, the real input is assumed to be symmetric about the folding frequency. Doesnot test this assumption. Assumes imaginary input consists of positivefrequency points for an asymmetric imaginary frequency function. That is, the imaginary inputis assumed to be asymmetric about the folding frequency. Does not test thisassumption. The assumption of a symmetric real part and anasymmetric imaginary part guarantees that theimaginary output is all zeros. Thus, the program does not return an imaginary output.Does not test the assumption that the imaginary is all zeros.CAUTION: THE INCOMING DATA LENGTH MUST BE A POWER OF TWO. OTHERWISE, THIS PROGRAM WILL FAILTO RUN PROPERLY. Returns a number of points equal to the incomingdata length. Those points are uniformly distributed beginning at zero.************************************************/ public class InverseComplexToRealFFT01{public static void inverseTransform( double[]realIn, double[]imagIn, double[]realOut){ double pi = Math.PI;//for convenienceint dataLen = realIn.length; double[]imagOut = new double[dataLen];//The complexToComplex FFT method does an // in-place transform causing the output// complex data to be stored in the arrays // containing the input complex data.// Therefore, it is necessary to copy the // input data into the output arrays before// passing them to the FFT algorithm. System.arraycopy(realIn,0,realOut,0,dataLen);System.arraycopy(imagIn,0,imagOut,0,dataLen); //Perform the spectral analysis. The results// are stored in realOut and imagOut. Note // that the -1 value for the first// parameter causes the transform to be an // inverse transform. A +1 value would cause// it to be a forward transform. complexToComplex(-1,dataLen,realOut,imagOut);}//end inverseTransform method //-------------------------------------------////This method computes a complex-to-complex // FFT. The value of sign must be 1 for a// forward FFT and -1 for an inverse FFT. public static void complexToComplex(int sign, int len,double real[],double imag[]){double scale = 1.0; //Reorder the input data into reverse binary// order. int i,j;for (i=j=0; i<len; ++i) { if (j>=i) { double tempr = real[j]*scale; double tempi = imag[j]*scale; real[j]= real[i]*scale;imag[j] = imag[i]*scale; real[i]= tempr; imag[i]= tempi; }//end ifint m = len/2; while (m>=1&&j>=m) { j -= m;m /= 2; }//end while loopj += m; }//end for loop//Input data has been reordered. int stage = 0;int maxSpectraForStage,stepSize; //Loop once for each stage in the spectral// recombination process. for(maxSpectraForStage = 1,stepSize = 2*maxSpectraForStage; maxSpectraForStage<len; maxSpectraForStage = stepSize,stepSize = 2*maxSpectraForStage){ double deltaAngle =sign*Math.PI/maxSpectraForStage; //Loop once for each individual spectrafor (int spectraCnt = 0; spectraCnt<maxSpectraForStage; ++spectraCnt){double angle = spectraCnt*deltaAngle; double realCorrection = Math.cos(angle);double imagCorrection = Math.sin(angle); int right = 0;for (int left = spectraCnt; left<len;left += stepSize){ right = left + maxSpectraForStage;double tempReal = realCorrection*real[right]- imagCorrection*imag[right];double tempImag = realCorrection*imag[right]+ imagCorrection*real[right];real[right] = real[left]-tempReal; imag[right]= imag[left]-tempImag;real[left] += tempReal;imag[left] += tempImag;}//end for loop }//end for loop for individual spectramaxSpectraForStage = stepSize; }//end for loop for stages}//end complexToComplex method }//end class InverseComplexToRealFFT01

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