#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
// Include CUDA runtime and CUFFT
#include <cuda_runtime.h>
#include <cufft.h> // Helper functions for CUDA
#include <helper_functions.h>
#include <helper_cuda.h>
#include "device_launch_parameters.h" #define pi 3.1415926535
#define LENGTH 100 //signal sampling points
int main()
{
// data gen
float Data[LENGTH] = {,,,};
float fs = 1000000.000;//sampling frequency
float f0 = 200000.00;// signal frequency
for(int i=;i<LENGTH;i++)
{
Data[i] = 1.35*cos(*pi*f0*i/fs);//signal gen, } cufftComplex *CompData=(cufftComplex*)malloc(LENGTH*sizeof(cufftComplex));//allocate memory for the data in host
int i;
for(i=;i<LENGTH;i++)
{
CompData[i].x=Data[i];
CompData[i].y=;
} cufftComplex *d_fftData;
cudaMalloc((void**)&d_fftData,LENGTH*sizeof(cufftComplex));// allocate memory for the data in device
cudaMemcpy(d_fftData,CompData,LENGTH*sizeof(cufftComplex),cudaMemcpyHostToDevice);// copy data from host to device cufftHandle plan;// cuda library function handle
cufftPlan1d(&plan,LENGTH,CUFFT_C2C,);//declaration
cufftExecC2C(plan,(cufftComplex*)d_fftData,(cufftComplex*)d_fftData,CUFFT_FORWARD);//execute
cudaDeviceSynchronize();//wait to be done
cudaMemcpy(CompData,d_fftData,LENGTH*sizeof(cufftComplex),cudaMemcpyDeviceToHost);// copy the result from device to host for(i=;i<LENGTH/;i++)
{
//if(CompData[i].x != 0)
//{
printf("i=%d\tf= %6.1fHz\tRealAmp=%3.1f\t",i,fs*i/LENGTH,CompData[i].x*2.0/LENGTH);//print the result:
//}
//if(CompData[i].y != 0 )
//{
printf("ImagAmp=+%3.1fi",CompData[i].y*2.0/LENGTH);
// }
printf("\n");
}
cufftDestroy(plan);
free(CompData);
cudaFree(d_fftData); }

i=0 f= 0.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=1 f= 10000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=2 f= 20000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=3 f= 30000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=4 f= 40000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=5 f= 50000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=6 f= 60000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=7 f= 70000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=8 f= 80000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=9 f= 90000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=10 f= 100000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=11 f= 110000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=12 f= 120000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=13 f= 130000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=14 f= 140000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=15 f= 150000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=16 f= 160000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=17 f= 170000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=18 f= 180000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=19 f= 190000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=20 f= 200000.0Hz RealAmp=1.4 ImagAmp=+0.0i
i=21 f= 210000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
i=22 f= 220000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
i=23 f= 230000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=24 f= 240000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=25 f= 250000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=26 f= 260000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
i=27 f= 270000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=28 f= 280000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=29 f= 290000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=30 f= 300000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=31 f= 310000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
i=32 f= 320000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=33 f= 330000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=34 f= 340000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=35 f= 350000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=36 f= 360000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
i=37 f= 370000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=38 f= 380000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=39 f= 390000.0Hz RealAmp=-0.0 ImagAmp=+-0.0i
i=40 f= 400000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=41 f= 410000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=42 f= 420000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=43 f= 430000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=44 f= 440000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
i=45 f= 450000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=46 f= 460000.0Hz RealAmp=0.0 ImagAmp=+0.0i
i=47 f= 470000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=48 f= 480000.0Hz RealAmp=-0.0 ImagAmp=+0.0i
i=49 f= 490000.0Hz RealAmp=0.0 ImagAmp=+-0.0i
请按任意键继续. . .

04-15 04:17