Filtering signal

Hi. I need to filter some signal, but I am stuck. Array with “in” samples is going good through GPU, also is array with coefficients of filter “MassFilter”. But “out” is filled by zeros. I have a low pass filter, so result is depend on Fotn. If Fotn > then bandpass frequency - the result is either as “in”, if <, the result is going to be near zeros. Bandpass freq = 250, stopband freq = 400.

Help please, what am I doing wrong? Thanks.

#include <iostream>
#include <cuda.h>
#include <cmath>
#include <fstream>

#define M_PI       3.14159
#define SizeSample 1000  
#define SizeFilter 10   
#define Fotn       0.1 

double Fd = 1000;
double in;
double out;

__global__ void mult(double* in, double* out, double* MassFilter1, int SizeFilter1, int SizeSample1)

	double sum = 0.0f;
	int idx = blockIdx.x * blockDim.x + threadIdx.x;

	__shared__ double as [1024];





	for(int i=0;i<SizeFilter1;i++)






int main()
    int dataLength = 1000;

    double *h_data = new double[1000];
    double *h_filteredData = new double;
    double *h_filter = new double;
    double A=-1.0;
    double B=1.0;
    double Amp = ((double)A + rand() / ((B + 1) - A));

for(int i = 0; i < 1000; i++)
		in[i] = Amp * sinf(2 * M_PI * Fotn * i);

double MassFilter = {0.0150682406405476188, 0.0631055096724139019, -0.107340878395980121, 0.0151929408492773276,
	0.495319687127840069, 0.495319687127840069, 0.0151929408492773276, -0.107340878395980121, 0.0631055096724139019, 0.0150682406405476188};

cudaMemcpy(in, h_data, dataLength* sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(MassFilter, h_filter, SizeFilter * sizeof(double), cudaMemcpyHostToDevice);  

dim3 threads (SizeFilter);
dim3 blocks  (SizeSample/threads.x );
mult<<<blocks, threads>>>(in, out, MassFilter, SizeFilter, SizeSample);

cudaMemcpy(h_filteredData, out, SizeSample * sizeof(double), cudaMemcpyDeviceToHost);

for(int i = 0; i < 1000; i++)
	     printf("%d \n", out[i]);

delete [] h_data;
    delete [] h_filteredData;
    delete [] h_filter;
    return 0;

No, it isn’t.

Your in and out and MassFilter variables are allocated in host memory, not device memory. Your cudaMemcpy operation is throwing an error. CUDA kernels cannot access host memory.

You have some basic CUDA programming skills to learn.

  1. Study the vectorAdd sample code. Study carefully how it uses cudaMalloc, and passes data to and from the device. Modify your code accordingly.
  2. Use proper CUDA error checking. Not sure what that is? google “proper CUDA error checking” and take the first hit, and start reading, and apply it to your code.
  3. Any time you are having trouble with a CUDA code, it’s a good idea to run it with cuda-memcheck