如何使用FFTW3 / QWT绘制谱图? [英] How to plot spectrum using FFTW3/ QWT?
问题描述
我想绘制频谱(像他们在Audacity中做的那样)。因此,我想要频率在赫兹在x轴和振幅在y轴。
我的输入是一个周期性正弦波,其中0,7作为幅度,500HZ作为频率。我使用FFTW来计算幅度和QWT绘图。
我的问题,我应该把什么参数setSamples获得一个图片在500 HZ?
任何帮助将被赞赏
这里是我的代码
I want to plot the frequency spectrum (like they do for example in Audacity). Hence I want the frequency in Hertz on the x-axis and the amplitude on the y-axis. My input is a periodically sine wave with 0,7 as amplitude and 500HZ as frequency.I use FFTW to compute the magnitude and QWT to plot. My problem , what parameters should I put in setSamples to get a pic on 500 HZ ? Any help would be appreciated here is my code
推荐答案
从文档,您必须为构建曲线和大小(您的案例中的样本数)的数据设置两个指针。 p>
From documentation you must set two pointers to data that build the curve and the size (number of samples in your case).
void QwtPlotCurve::setSamples(const double *xData, const double *yData, int size)
在你的情况下,yData是来自FFT的数据,xData是一个数组,从FFT的最小到最大/当信号是实信号时的另一半:
In your case yData is the data from FFT, the xData is an array that sweep from min to max/2 frequency values of the FFT discarding the other half when the signal is a real signal:
curve->setSamples(signalx, magnitude, N/2);
如果我是正确的,这应该可以工作。
this should work if I'm correct.
编辑
更改:
signalx[i]=i;
magnitude[i]=sqrt(reout[i]*reout[i] + imgout[i]*imgout[i]); //calculate magnitude
到:
signalx[i]=(double)(Fs * i) / (double)N;
magnitude[i]=sqrt(reout[i]*reout[i] + imgout[i]*imgout[i]) / ((double)N / 2.0);
代表图中幅度[i]元素的频率。
to represent the frequency for magnitude[i] element in plot.
您还应该检查纽约州频率。在1000Hz采样500Hz正弦波产生混叠,如果绘制信号[]数据(以离散步长),您可以看到它。
You should check also for the nyquist frequency. Sampling 500Hz sine wave at 1000Hz produce aliasing and if you plot your signal[] data (at discrete steps) you can see it.
这篇关于如何使用FFTW3 / QWT绘制谱图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!