12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

fourier analysis: signals and filters 241containing the Z values by a vector of length N of y value. The time for this DFTscales like N 2 , while the time for the FFT algorithm scales as N log 2 N. Althoughthis may not seem like much of a difference, for N =10 2−3 , the difference of 10 3−5is the difference between a minute and a week. For this reason, FFT is often usedfor on-line analysis of data. We discuss FFT techniques in §10.8.✞☎//DFT. java : Discrete Fourier Transformimport java . io .∗ ;public class DFT {static final int N = 1000, Np = N; / / Global constantsstatic double [] signal = new double [N + 1];static double twopi = 2.∗ Math . PI , sq2pi = 1./Math . sqrt (twopi ) ;static double h = twopi/N;public static void main ( String [] argv ) {double dftreal [] = new double [Np] , dftimag [] = new double [Np] ;f ( signal ) ;fourier ( dftreal , dftimag ) ;}public static void fourier ( double dftreal [] , double dftimag []) {double real , imag ; // Calc & plot Y(w)int n, k;for ( n = 0; n < Np; n++ ) { / / Loop on frequencyreal = imag = 0. ; // Clear variablesfor ( k = 0; k < N; k++ ) { / / Loop for sumsreal += signal [k]∗Math . cos ( ( twopi∗k∗n)/N) ;imag += signal [k]∗Math . sin ( ( twopi∗k∗n)/N) ;}dftreal [n] = real∗sq2pi ;dftimag [n] = −imag∗sq2pi ;}}✝}public static void f(double [] signal ) { // Initial functionint i;double step = twopi/N, x = 0 . ;for ( i =0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!