-2
我有這個程序有問題:CUFFT輸出不正確
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cufft.h>
#include <cuComplex.h>
#define SIGNAL_SIZE 1024
int main(int argc, char **argv) {
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
// Allocate host memory for the signal
cuDoubleComplex *h_signal = (cuDoubleComplex *) malloc(sizeof(cuDoubleComplex) * SIGNAL_SIZE);
// Initalize the memory for the signal
for (unsigned int i = 0; i < SIGNAL_SIZE; ++i) {
if((double)i/SIGNAL_SIZE>=0 && (double)i/SIGNAL_SIZE<0.5) h_signal[i].x = (double)i/SIGNAL_SIZE;
else if((double)i/SIGNAL_SIZE>=0.5 && (double)i/SIGNAL_SIZE<1) h_signal[i].x = (double)i/SIGNAL_SIZE-1;
h_signal[i].y = 0;
}
// Allocate device memory for signal
cuDoubleComplex *d_signal;
cudaMalloc((void **) &d_signal, SIGNAL_SIZE*sizeof(cuDoubleComplex));
// Copy host memory to device
cudaMemcpy(d_signal, h_signal, SIGNAL_SIZE*sizeof(cuDoubleComplex), cudaMemcpyHostToDevice);
cudaEventRecord(start, 0);
cufftHandle plan;
cufftPlan1d(&plan, SIGNAL_SIZE , CUFFT_C2C, 1);
// FFT computation
cufftExecC2C(plan, (cufftComplex *) d_signal, (cufftComplex *) d_signal,
CUFFT_FORWARD);
cufftExecC2C(plan, (cufftComplex *) d_signal, (cufftComplex *) d_signal, CUFFT_INVERSE);
cuDoubleComplex *h_signal_inv =(cuDoubleComplex *) malloc(sizeof(cuDoubleComplex) * SIGNAL_SIZE);
cudaMemcpy(h_signal_inv, d_signal, sizeof(cuDoubleComplex) * SIGNAL_SIZE, cudaMemcpyDeviceToHost);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime, start, stop);
printf("Elapsed Time: %3.1f ms\n", elapsedTime);
for(int i=0;i<SIGNAL_SIZE;i++) printf("\n%f %f", h_signal[i].x, h_signal_inv[i].x);
cufftDestroy(plan);
free(h_signal);
free(h_signal_inv);
cudaFree(d_signal);
cudaDeviceReset();
return 0;
}
我想變換的信號,然後再回來與逆,但輸出是錯誤的上半年。
你能幫我找到錯誤嗎?
非常感謝!
而現在,隨着近期出臺的回調功能,您可以在CUFFT執行中直接嵌入IFFT正常化。 – JackOLantern 2014-10-05 20:00:04
謝謝你的回答! – Marco 2014-10-05 21:05:07
我還有一個問題!我想壓縮初始信號,所以我必須在頻率上設置一個閾值。我怎樣才能做到這一點?當我打電話給cufftExecZ2Z輸出是什麼? – Marco 2014-10-05 21:13:26