- CodeProjectMBishop_12_22_2012.zip
- CodeProjectMBishop_12_22_2012
- JCudaFftDemo
- bin
- CaxpyGpu.class
- ComplexCalcFloat.class
- ComplexFloat.class
- FftCpuFloat.class
- FftGpuFloat.class
- Main.class
- Stopwatch.class
- src
- Notes
|
/**
* Adaption of JCuda.org example.
* Author Mark Bishop; 2012
* License GNU v3;
* This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import jcuda.jcufft.JCufft;
import jcuda.jcufft.cufftHandle;
import jcuda.jcufft.cufftType;
/**
* Computation class for FFT on Central Processor Unit. and related utilities.
*/
public class FftGpuFloat {
/**
*
* @param input
* an interleaved array (ft)
* @return C2C FFT (hf)
*/
public static float[] C2C_1D(float[] input) {
float outputJCufft[] = input.clone();
// The plan uses the number of complex elements in the input array, i.e:
// length/2.
cufftHandle plan = new cufftHandle();
JCufft.cufftPlan1d(plan, input.length / 2, cufftType.CUFFT_C2C, 1);
JCufft.cufftExecC2C(plan, outputJCufft, outputJCufft,
JCufft.CUFFT_FORWARD);
JCufft.cufftDestroy(plan);
return outputJCufft;
}
/**
*
* @param input
* an interleaved array (hf)
* @param isNormalize
* Set true if result should be multiplied by 1/N
* @return C2C IFFT (ft)
*/
public static float[] InverseC2C_1D(float[] input, boolean isNormalize) {
float outputJCufft[] = input.clone();
// The plan uses the number of complex elements in the input array, i.e:
// length/2.
cufftHandle plan = new cufftHandle();
JCufft.cufftPlan1d(plan, input.length / 2, cufftType.CUFFT_C2C, 1);
JCufft.cufftExecC2C(plan, outputJCufft, outputJCufft,
JCufft.CUFFT_INVERSE);
JCufft.cufftDestroy(plan);
// Normalization allows for amplitude reconstruction of the original
// signal.
if (isNormalize) {
float normalize = 2 / (float) outputJCufft.length;
outputJCufft = CaxpyGpu.CaxpyFloatScalar(normalize, outputJCufft);
}
return outputJCufft;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am an analytical chemist and an educator. I program primarily to perform matrix computations for regression analysis, process signals, acquire data from sensors, and to control devices.
I participate in many open source development communities and Linux user forums. I do contract work for an environmental analytical laboratory, where I am primarily focused on LIMS programming and network administration.
I am a member of several community-interest groups such as the Prince Edward Island Watershed Alliance, the Lot 11 and Area Watershed Management Group, and the Petersham Historic Commission.