具有fftw的理想低通滤波器

时间:2012-05-01 19:17:06

标签: fft fftw lowpass-filter

我仍然试图让我的低通滤波器运行,但我不知道为什么它仍然没有运行。我根据FFT Filters和我之前的问题FFT Question定向我的代码,以便为图像应用理想的低通滤波器。下面的代码只会使图像变暗,并在生成的图像中放置一些白色像素。

// forward fft the result is in freqBuffer
fftw_execute(forward);

for (int y = 0; y < h; y++)
{
    for (int x = 0; x < w; x++)
    {
        uint gid = y * w + x;

        // shifting coordinates normalized to [-0.5 ... 0.5]
        double xN = (x - (w / 2)) / (double)w;
        double yN = (y - (h / 2)) / (double)h;

        // max radius
        double maxR = sqrt(0.5f * 0.5f + 0.5f * 0.5f);

        // current radius normalized to [0 .. 1]
        double r = sqrt(xN * xN + yN * yN) / maxR ;

        // filter response
        double filter = r > 0.7f ? 0.0f : 1.0f;

        // applying filter response
        freqBuffer[gid][0] *= filter;
        freqBuffer[gid][1] *= filter;
    }
}

// normlization (see fftw scaling)
for (uint i = 0; i < size; i++)
{
    freqBuffer[i][0] /= (float)size;
    freqBuffer[i][1] /= (float)size;
}

// backward fft
fftw_execute(backward);

一些帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

如果您在频域中有一个带有阶跃响应的滤镜,那么您会在空间域中看到重要的sin(x)/x 振铃。这被称为Gibbs Phenomenon。您需要将window function应用于所需的频率响应以缓解此问题。