question: public static double [ ] genPulseFromFourierMag ( double [ ] mag , double f0 ) { int numHarm = mag . length ; int currentF0 = ( int ) Math . round ( f0 ) ; int T ; if ( currentF0 < 512 ) T = 512 ; else T = 1024 ; int T2 = 2 * T ; double [ ] pulse = new double [ T ] ; double [ ] real = new double [ T2 ] ; double [ ] imag = new double [ T2 ] ; real [ 0 ] = real [ T ] = 0.0 ; for ( int i = 1 ; i <= numHarm ; i ++ ) { real [ i ] = real [ T - i ] = real [ T + i ] = real [ T2 - i ] = mag [ i - 1 ] ; imag [ i ] = imag [ T - i ] = imag [ T + i ] = imag [ T2 - i ] = 0.0 ; } for ( int i = ( numHarm + 1 ) ; i < ( T - numHarm ) ; i ++ ) { real [ i ] = real [ T - i ] = real [ T + i ] = real [ T2 - i ] = 1.0 ; imag [ i ] = imag [ T - i ] = imag [ T + i ] = imag [ T2 - i ] = 0.0 ; } FFT . transform ( real , imag , true ) ; double sqrt_f0 = Math . sqrt ( currentF0 ) ; for ( int i = 0 ; i < T ; i ++ ) pulse [ i ] = real [ ( i - numHarm ) % T ] * sqrt_f0 ; return pulse ; }
target:  Generate one pitch period from Fourier magnitudes