Question of FFFT in Matlab

2 ビュー (過去 30 日間)
Nathan Jaqua
Nathan Jaqua 2019 年 10 月 22 日
回答済み: Ajay Pattassery 2019 年 10 月 31 日
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 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 22 日
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 2019 年 10 月 22 日
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.

サインインしてコメントする。

採用された回答

Ajay Pattassery
Ajay Pattassery 2019 年 10 月 31 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by