Finding the main frequency after fft
이전 댓글 표시
Hi,
I've got these blocks in simulink:
Sine Wave -> Buffer -> Matrix sum -> Matlab function.
I have to find the frequency of the input, so I wrote some code in Matlab function (by the http://www.mathworks.com/help/techdoc/ref/fft.html) :
{
function [freq, amp] = fcn(u)
%#codegen
Fs=2000;
T=1/Fs;
L=length(u);
t = (0:L-1)*T;
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(u,NFFT);
f = Fs/2*linspace(0,1,NFFT/2+1);
amp = abs(max(Y));
}
It's working properly, I'm getting the maximum value, but I can't get from code frequency of maxium value :/ how Can I get it? Thank You for response.
Best regards, Pawel
채택된 답변
추가 답변 (1개)
Pawel Burzynski
2011년 9월 17일
0 개 추천
댓글 수: 3
Wayne King
2011년 9월 17일
Glad it's working. Your mismatch is likely due to your frequencies not falling directly on a DFT bin.
Wayne
Pawel Burzynski
2011년 9월 23일
Wayne King
2011년 9월 23일
Can you please provide code? It is hard to say the source of the error without a coded example.
카테고리
도움말 센터 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!