GSL快速傅立叶变换-双值高斯? [英] GSL Fast-Fourier Transform - Double-Valued Gaussian?

查看:217
本文介绍了GSL快速傅立叶变换-双值高斯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的就是评估高斯的傅立叶变换(当然是测试),但是我得到的是一个双值函数,如下图所示.当您仔细观察高斯的尾部时,您会发现FFT返回的值实际上在正负之间振荡,从而使DFT看起来是双值". 为什么会这样?有没有办法解决这个问题(当然不只是画复数模)?

All I want to do is evaluate the Fourier transform of a Gaussian (as a test of course), but I'm getting what looks like a double-valued function, as can be seen in the plot below. When you look closely at the tails of the Gaussian, you can see that the FFT returned values are actually oscillating between positive and negative, making the DFT look "double-valued". Why is this happening? Is there a way to fix this (without just plotting the complex modulus of course)?

#include <gsl/gsl_fft_complex.h>
#include <gsl/gsl_errno.h>
#include <fstream>
#include <iostream>
#include <iomanip> 

#define REAL(z,i) ((z)[2*(i)]) //complex arrays stored as    [Re(z0),Im(z0),Re(z1),Im(z1),...]
#define IMAG(z,i) ((z)[2*(i)+1])
#define MODU(z,i) ((z)[2*(i)])*((z)[2*(i)])+((z)[2*(i)+1])*((z)[2*(i)+1])
#define PI 3.14159265359

using namespace std;

int main(){

    int n = pow(2,9);
    double data[2*n];
    double N = (double) n;

    ofstream file_out("out.txt");

    double xmin=-10.;
    double xmax=10.;
    double dx=(xmax-xmin)/N;
    double x=xmin;

    for (int i=0; i<n; ++i){
        REAL(data,i)=exp(-100.*x*x);
        IMAG(data,i)=0.;
        x+=dx;
    }

    gsl_fft_complex_radix2_forward(data, 1, n); 

    for (int i=0; i<n; ++i){
        file_out<<(i-n/2)<<"    "<<REAL(data,((i+n/2)%n))<<'\n';
    }

    file_out.close();
}

推荐答案

您仅在绘制真实分量,例如偶数或余弦分量.注意,当N从奇数增加到偶数时,整数频率N的余弦波在中间为-1和中间为1之间切换.因此,DFT窗口输入中间的任何噪声都可能导致DFT结果中的各种实数分量发生切换(除非噪声与所有这些DFT基矢量完全正交).

You are plotting just the real component, e.g. the even or cosine component. Note that a cosine wave of integer frequency N toggles between being -1 in the middle and to being 1 in the middle, as N increases from an odd number to an even number. Thus any noise in the middle of the input to a DFT window can cause various real components in the DFT result to toggle (unless that noise is exactly orthogonal to all those DFT basis vectors) .

这篇关于GSL快速傅立叶变换-双值高斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆