0

I wrote a small script to get the fft of a sinus signal :

    N = 1000; % number of samples 
n = (0:N-1)'; % generate a vector n for x[n]
Fs_normal = 36621.09375;
%generate a signal in pass-band, N samples and simulate filter
f0 = 1000; % set 1000 Hz 
x= sin(2*pi*f0*n/Fs_normal); % input signal
figure(3);
stem(x),title('sinus wave with 1000 Hz (n)'),grid;
figure(4);
plot(abs(fft(x))),grid,title('FFT of sin wave with 1000 Hz  frequency');

here is the fft result that I get :

enter image description here

as you can see the axis doesn't make any sense ( at least to me), is there a way to get this the right way ?

Engine
  • 5,360
  • 18
  • 84
  • 162
  • 1
    I suggest reading into the [theory of sampling and DFT](https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem) (see also: [aliasing](https://en.wikipedia.org/wiki/Aliasing)). If your problem is the two peaks, that is. Your question is far from clear. – Andras Deak -- Слава Україні Jan 07 '16 at 22:15

1 Answers1

1

The FFT gives you 1000 bins

freqvals = [0:N-1]/N * Fs_normal;
plot(freqvals, abs(fft(x))),grid,title('FFT of sin wave with 1000 Hz  frequency');

You have to add the scale on your own. The whole FFT gives you also 1000 complex coefficients back when you give it 1000 samples. The range is from 0 to the sampling frequency.

Bins are separated by a frequency shift of Fs_normal/N.

Matthias W.
  • 1,039
  • 1
  • 11
  • 23