0
$\begingroup$

I have a 4096 sequence of FFT coefficient. All of which a real values. My sampling frequency is also 4096 samples per seconds. Now I want to make a plot. I know my Y axis would be my FFT magnitude values, but what would my x- axis be. Would it be my sampling frequency, that is 1,2,3,4.........4096?

$\endgroup$
1
$\begingroup$

Here's a short snippet of code that returns the domain of the FFT depending on if you have the onesided or twosided FFT. This is from some code I posted on a somewhat related question here.

% Nfft - FFT size
% Fs - Sampling frequency in Hz
% oneside - flag indicating FFT results will be onesided or two sided

% Compute the frequency vector
if oneside == true
  f = fs * (0:Nfft/2).'./Nfft;
else
  f = fs * (-Nfft/2:Nfft/2-1).'./Nfft;
end
| improve this answer | |
$\endgroup$
0
$\begingroup$

It is actually [-4096/2:4096/2-1]/4096*4096;

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ The x-axis for a real-input FFT plot is typically Fs*[0:N/2-1]/N where N is the FFT size, and N/2 samples are kept from the FFT. $\endgroup$ – John Jan 8 '14 at 23:18
  • $\begingroup$ Thank you John. So is it usually written as [-N/2:N/2-1]/N*Fs? $\endgroup$ – lennon310 Jan 9 '14 at 1:07
  • $\begingroup$ @Olu Please read FAQ - dsp.stackexchange.com/help/someone-answers $\endgroup$ – SergV Jan 9 '14 at 9:30
  • $\begingroup$ For a sin wave, I did plot it this way, and the spike was at the correct frequency. But for the fft of a square wave values, I did not get a full sinc graph. I only got one side of it. How do I plot properly to get a complete sinc graph with the frequency spike at the correct frequency $\endgroup$ – Nazario_Jnr Jan 9 '14 at 11:08
  • $\begingroup$ @Olu, try fftshift(fft(x)) $\endgroup$ – lennon310 Jan 9 '14 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.