Question of FFFT in Matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!