Question of FFFT in Matlab

4 vues (au cours des 30 derniers jours)
Nathan Jaqua
Nathan Jaqua le 22 Oct 2019
WIth the code below, I am taking the DFT of the sinewave at multiple samples in frequency domain. Why am I not seeing in DFT spectrum (second part, N=100) clear two impulses at 100 Hz?
clc;
clear all;
f = 128;
Fs = 1024;
t = (0:2047)/Fs;
x = sin(2*pi*f*t);
% calculate full sample point DFT
N = 128;
X = (1/sqrt(N))*fft(x, N);
XdB1 = 20*log10(abs(fftshift(X)));
f1 = -(Fs/2):Fs/N:(Fs/2)-1;
% plot magnitude spectrum
plot(f1, XdB1); title('DFT of sine wave at 100 Hz');
xlabel('Frequency --> f'); ylabel('Amplitude in dB'); axis([-512 511 -30 20]); hold on;
% calculate only 128 point DFT
N = 100;
deltaF = Fs/N;
X = (1/sqrt(N))*fft(x, N);
XdB2 = 20*log10(abs(fftshift(X)));
f2 = -(Fs/2):deltaF:(Fs/2)-1;
% plot magnitude spectrum
plot(f2, XdB2,'r');
xlabel('Frequency --> f'); ylabel('Amplitude in dB');
  2 commentaires
Walter Roberson
Walter Roberson le 22 Oct 2019
Fs = 1024;
That is not 100 Hz. 100Hz would be Fs = 100
f = 128;
That is not 100 Hz either; it is 128 Hz.
Daniel M
Daniel M le 22 Oct 2019
Not able to test it right now, but seems odd for you to only take a 128 point fft. Just take the whole thing, should be 2047. You will probably get better resolution. By the way, your code and your comments do not match up with each other. It makes it difficult to assess what level of understanding you have of this process.

Connectez-vous pour commenter.

Réponse acceptée

Ajay Pattassery
Ajay Pattassery le 31 Oct 2019
The frequency of the sine wave is defined as 128 Hz (f = 128) in the above code. Hence there will be two impulses (ideally, but here since x is just an approximation of the sine wave you can observe peaks at that frequency) at 128 Hz and -128Hz in the FFT output.
If you take FFT with N = 128 or N = 100, x is truncated to match the length of N and FFT is computed on the resultant x.
If the frequency f is changed to 100, you could observe a peak at 100Hz.

Plus de réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by