简体   繁体   中英

How to plot spectrum using FFTW3/ QWT?

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

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)

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.

EDIT

Change also:

signalx[i]=i;
magnitude[i]=sqrt(reout[i]*reout[i] + imgout[i]*imgout[i]); //calculate magnitude 

to:

signalx[i]=(double)(Fs * i) / (double)N;
magnitude[i]=sqrt(reout[i]*reout[i] + imgout[i]*imgout[i]) / ((double)N / 2.0);

to represent the frequency for magnitude[i] element in plot.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM