작업입니다. -
차이 식 조작 차이 식 간단한 대수으로
명시 적으로 FORM, 당신은 다음 찾을 수 있습니다
y[n]/beta^n = y[0] + alpha * x[1]/beta + alpha * x[2]/beta^2 + ...
: 따라서
y[1] = beta * y[0] + alpha * x[1]
y[2] = beta^2 * y[0] + alpha * beta * x[1] + alpha * x[2]
y[3] = beta^3 * y[0] + alpha * beta^2 * x[1] + alpha * beta * x[2] + alpha * x[3]
을 명시 적 형태는 다음과 같다
쿠다 쓰루풋 구현
당신은 다음 단계로 위의 명시적인 형태로 구현할 수 있습니다
- 이
d_input[0] = 1.
를 제외하고 alpha
에 입력 순서 d_input
초기화를;
- 벡터
d_1_over_beta_to_the_n
을 1, 1/beta, 1/beta^2, 1/beta^3, ...
과 동일하게 정의하십시오.
- 요소 단위로 곱하기
d_input
d_1_over_beta_to_the_n
;
y[n]/beta^n
의 시퀀스를 얻기 위해 inclusive_scan
을 수행하십시오.
- 위의 시퀀스를
1, 1/beta, 1/beta^2, 1/beta^3, ...
으로 나눕니다.
편집은
위의 방법 선형 시변 (LTV) 시스템을 권장 할 수있다. Linear Time-Invariant (LTI) 시스템의 경우 Paul이 언급 한 FFT 접근 방식을 권장 할 수 있습니다. FIR filter in CUDA에 CUDA Thrust 및 cuFFT를 사용하여 이러한 접근 방식의 예를 제공합니다.
다른 접근 방식에 대한 전체 코드
#include <thrust/sequence.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
int main(void)
{
int N = 20;
// --- Filter parameters
double alpha = 2.7;
double beta = -0.3;
// --- Defining and initializing the input vector on the device
thrust::device_vector<double> d_input(N,alpha * 1.);
d_input[0] = d_input[0]/alpha;
// --- Defining the output vector on the device
thrust::device_vector<double> d_output(d_input);
// --- Defining the {1/beta^n} sequence
thrust::device_vector<double> d_1_over_beta(N,1./beta);
thrust::device_vector<double> d_1_over_beta_to_the_n(N,1./beta);
thrust::device_vector<double> d_n(N);
thrust::sequence(d_n.begin(), d_n.end());
thrust::inclusive_scan(d_1_over_beta.begin(), d_1_over_beta.end(), d_1_over_beta_to_the_n.begin(), thrust::multiplies<double>());
thrust::transform(d_1_over_beta_to_the_n.begin(), d_1_over_beta_to_the_n.end(), d_input.begin(), d_input.begin(), thrust::multiplies<double>());
thrust::inclusive_scan(d_input.begin(), d_input.end(), d_output.begin(), thrust::plus<double>());
thrust::transform(d_output.begin(), d_output.end(), d_1_over_beta_to_the_n.begin(), d_output.begin(), thrust::divides<double>());
for (int i=0; i<N; i++) {
double val = d_output[i];
printf("Device vector element number %i equal to %f\n",i,val);
}
// --- Defining and initializing the input vector on the host
thrust::host_vector<double> h_input(N,1.);
// --- Defining the output vector on the host
thrust::host_vector<double> h_output(h_input);
h_output[0] = h_input[0];
for(int i=1; i<N; i++)
{
h_output[i] = h_input[i] * alpha + beta * h_output[i-1];
}
for (int i=0; i<N; i++) {
double val = h_output[i];
printf("Host vector element number %i equal to %f\n",i,val);
}
for (int i=0; i<N; i++) {
double val = h_output[i] - d_output[i];
printf("Difference between host and device vector element number %i equal to %f\n",i,val);
}
getchar();
}
+1. 귀하의 접근 방식이 Linear Time-Invariant (LTI) 시스템에 가장 적합하다는 것에 동의합니다. [CUDA의 FIR 필터] (http://stackoverflow.com/questions/15853140/fir-filter-in-cuda/23741721#23741721)에서는 CUDA Thrust 및 cuFFT가 구현 한 FFT 접근법을 사용하는 예를 제공합니다. FIR (Finite Impulse Response) 필터 용 라이브러리 그에 따라 내 게시물을 편집했습니다. – JackOLantern