how to get frequency of a discrete signal by using fft in matlab

조회 수: 13 (최근 30일)
i want to find the frequency of a discrete signal using matlab and also want to apply a bandpass filter to that spectrum how can i do that pls help me out guys!!!

채택된 답변

Wayne King
Wayne King 2012년 5월 18일
You identify the peak in the Fourier transform, find the index in DFT vector corresponding to that peak and relate that to frequency.
For example:
% sampling frequency is 1 kHz
Fs = 1000;
% I'll create a signal consisting of a 100 Hz sine wave in noise
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fft(x);
% I only need to search 1/2 of xdft for the max because x is real-valued
xdft(1:length(x)/2+1);
[Y,I] = max(abs(xdft));
freq = 0:Fs/length(x):Fs/2;
fprintf('Maximum occurs at %3.2f Hz\n.',freq(I))
Note that the frequency bins in the DFT are spaced at Fs/N where Fs is the sampling frequency and N is the length of the signal. The first DFT "bin" corresponds to zero frequency.
Your next step is to construct a bandpass filter around 1 kHz, you can do that a number of ways in MATLAB. See fdesign.bandpass for example.
  댓글 수: 1
newbie traveller
newbie traveller 2012년 5월 18일
ok sir .....thank you very much! but i need to know somethg more silly from you......the thing that you have did to find from 1/2 of xdft .......
xdft(1:length(x)/2+1);
[Y,I] = max(abs(xdft));
freq = 0:Fs/length(x):Fs/2;
fprintf('Maximum occurs at %3.2f Hz\n.',freq(I))
can pls explainn that more easily seems confusing to me ...pls explain me that more theoritically so that i can also do with my own !!!
as i know fft doesn't give me the real spectrum of a signal i have to do the fftshift to get the real one ....i just know these things so it would be better to make me understand further .it will probably help me ...thank you very much sir!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Wayne King
Wayne King 2012년 5월 18일
You don't have to do fftshift() to get the real spectrum. fftshift just puts 0 in the center with "negative" frequencies to the left and "positive" frequencies to the right. That is convenient in many applications, but not necessary.
If the signal is real-valued (not complex-valued), then a symmetry will exist between the two halfs of the Fourier transform. Therefore, in order to identify the peak frequency, you only need to work with 1/2 of the result.

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by