<< Chapter < Page
  Digital signal processing - dsp     Page 12 / 14
Chapter >> Page >
Listing 15. InverseComplexToReal01.hava.
/*File InverseComplexToReal01.java Copyright 2004, R.G.BaldwinRev 5/24/04 Although there are more efficient ways to writethis program, it was written the way it was to mimic the behavior of an FFT algorithm.Therefore, the complex input must extend from zero to the sampling frequency.The static method named inverseTransform performs a complex to real inverse discrete Fouriertransform returning a real result only. In other words, the method transforms a complex input to areal output. Does not implement the FFT algorithm. Implementsa straight-forward sampled-data version of the continuous inverse Fourier transform definedusing integral calculus. The parameters are:double[] realIn - incoming real datadouble[] imagIn - incoming imag datadouble[] realOut - outgoing real dataConsiders the data length to be realIn.lengthComputational time increment is1.0/realIn.length Returns a number of points equal to the datalength. Assumes real input consists of positivefrequency points for a symmetric real frequency function. That is, the real input is assumed tobe symmetric about the folding frequency. Does not test this assumption.Assumes imaginary input consists of positive frequency points for an asymmetric imaginaryfrequency function. That is, the imaginary input is assumed to be asymmetric about thefolding frequency. Does not test this assumption.The assumption of a symmetric real part and an asymmetric imaginary part guarantees that theimaginary output would be all zero if it were to be computed. Thus the program makes no attemptto compute an imaginary output. Tested using J2SE v1.4.2 under WinXP.************************************************/ public class InverseComplexToReal01{public static void inverseTransform( double[]realIn, double[]imagIn, double[]realOut){ int dataLen = realIn.length;double delT = 1.0/realIn.length; double startTime = 0.0;//Outer loop interates on time domain // values.for(int i=0; i<dataLen;i++){ double time = startTime + i*delT;double real = 0; //Inner loop iterates on frequency// domain values. for(int j=0; j<dataLen; j++){ real += realIn[j]* Math.cos(2*Math.PI*time*j)+ imagIn[j]*Math.sin(2*Math.PI*time*j); }//end inner looprealOut[i] = real;}//end outer loop }//end inverseTransform}//end class InverseComplexToReal01
Listing 16. Dsp036.java.
/* File Dsp036.java Copyright 2004, R.G.BaldwinRevised 5/24/04 Illustrates forward and inverse Fouriertransforms using FFT algorithms. Performs spectral analysis on a time seriesconsisting of pulses and a sinusoid. Passes resulting real and complex parts toinverse Fourier transform program to reconstruct the original time series.Run with Graph03. Tested using J2SE 1.4.2 under WinXP.************************************************/ import java.util.*;class Dsp036 implements GraphIntfc01{ final double pi = Math.PI;int len = 256; double[]timeDataIn = new double[len];double[] realSpect = new double[len]; double[]imagSpect = new double[len];double[] angle = new double[len];//unused double[]magnitude = new double[len];double[] timeOut = new double[len]; public Dsp036(){//constructor//Create the raw data pulses timeDataIn[0]= 0; timeDataIn[1]= 50; timeDataIn[2]= 75; timeDataIn[3]= 80; timeDataIn[4]= 75; timeDataIn[5]= 50; timeDataIn[6]= 25; timeDataIn[7]= 0; timeDataIn[8]= -25; timeDataIn[9]= -50; timeDataIn[10]= -75; timeDataIn[11]= -80; timeDataIn[12]= -60; timeDataIn[13]= -40; timeDataIn[14]= -26; timeDataIn[15]= -17; timeDataIn[16]= -11; timeDataIn[17]= -8; timeDataIn[18]= -5; timeDataIn[19]= -3; timeDataIn[20]= -2; timeDataIn[21]= -1; timeDataIn[240]= 80; timeDataIn[241]= 80; timeDataIn[242]= 80; timeDataIn[243]= 80; timeDataIn[244]= -80; timeDataIn[245]= -80; timeDataIn[246]= -80; timeDataIn[247]= -80; timeDataIn[248]= 80; timeDataIn[249]= 80; timeDataIn[250]= 80; timeDataIn[251]= 80; timeDataIn[252]= -80; timeDataIn[253]= -80; timeDataIn[254]= -80; timeDataIn[255]= -80; //Create raw data sinusoidfor(int x = len/3;x<3*len/4;x++){ timeDataIn[x]= 80.0 * Math.sin( 2*pi*(x)*1.0/20.0);}//end for loop //Compute FFT of the time data and save it in// the output arrays. ForwardRealToComplexFFT01.transform(timeDataIn, realSpect,imagSpect, angle,magnitude); //Compute inverse FFT of spectral dataInverseComplexToRealFFT01. inverseTransform(realSpect, imagSpect,timeOut); }//end constructor//-------------------------------------------// //The following six methods are required by the// interface named GraphIntfc01. public int getNmbr(){//Return number of curves to plot. Must not // exceed 5.return 5; }//end getNmbr//-------------------------------------------// public double f1(double x){int index = (int)Math.round(x); if(index<0 || index>timeDataIn.length-1){ return 0;}else{ return timeDataIn[index]; }//end else}//end function //-------------------------------------------//public double f2(double x){ int index = (int)Math.round(x);if(index<0 || index>realSpect.length-1){ return 0;}else{ //scale for convenient viewingreturn 5*realSpect[index]/len;}//end else }//end function//-------------------------------------------// public double f3(double x){int index = (int)Math.round(x); if(index<0 || index>imagSpect.length-1){ return 0;}else{ //scale for convenient viewingreturn 5*imagSpect[index]/len;}//end else }//end function//-------------------------------------------// public double f4(double x){int index = (int)Math.round(x); if(index<0 || index>magnitude.length-1){ return 0;}else{ //scale for convenient viewingreturn 5*magnitude[index];}//end else }//end function//-------------------------------------------// public double f5(double x){int index = (int)Math.round(x); if(index<0 || index>timeOut.length-1){ return 0;}else{ //scale for convenient viewingreturn timeOut[index]/len;}//end else }//end function}//end sample class Dsp036

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