【发布时间】:2014-06-01 00:45:02
【问题描述】:
我的目的是更多地了解 FFTW。我想使用 qt/Qwt 在图表中显示 FFTW 输入和输出数据。我的印象是我做错了什么,因为我的图表不是我想象的那样。
请让我知道出了什么问题。这是我的代码:
#include <iostream>
using namespace std;
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <qapplication.h>
#include <cmath>
#include <fftw3.h>
const int N=256;
int main (int argc, char **argv)
{
QApplication a(argc,argv);
double Fs=1000;//sampling frequency
double T=1/Fs;//sample time
double f=500;//frequency
double t[N-1];//time vector
double signal[N-1];
for (int i=0; i< N-1;i++)
{
t[i]=i*T;
signal[i]=0.7 *sin(2*M_PI*f*t[i]);// generate sine waveform
}
fftw_complex out[N];
fftw_plan p3;
p3 = fftw_plan_dft_r2c_1d(N, signal, out, FFTW_ESTIMATE);//create plan
fftw_execute(p3);// FFT
double reout[N];
double imgout[N];
for (int i = 0; i < N; i++) {
reout[i]=out[i][0];
imgout[i]=out[i][1];
cout << imgout[i]<<endl;
// cout << signal[i]<< endl;
}
fftw_destroy_plan(p3);
QwtPlot myPlot;
QwtPlotCurve *curve =new QwtPlotCurve();
curve->setSamples(reout,signal,N/2+1);//plot fft
curve->attach(&myPlot);
myPlot.show();
return a.exec();
}
【问题讨论】:
-
你想象它会是什么样子?它是什么样子的?您可以在此处或链接到其他网站的图片发布吗?
-
我需要至少 10 个声望才能发布图片
-
在您有足够的代表之前,您可以在 imgur.com 等网站上发布图片链接 - 然后有人可以为您编辑帖子以将图片包含在内。
标签: c++ qt signal-processing fft fftw