reading frequency from fft
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to read the frequencies of all peaks of fft the following program is not reading it correctly instead of giving 100 and so its giving output as 360 400 or so please help how can I get value of the freq
Fs = 65536; % Sampling Frequency (Hz) Ts = 1/Fs; % Sampling Interval (sec) Fn = Fs/2; % Nyquist Frequency (Hz) L = 16384; % Signal Length (samples) t = [0:(L-1)]*Ts; % Time Vector (sec) s = cos(2*pi*100*t);% Signal (100 Hz) figure(1) plot(s) FTs = fft(s,Fs)/L; % Experiment #1 Fv = linspace(0, 1, fix(Fs/2)+1)*Fn; Iv = 1:length(Fv); [PeakFTs,Idx] = max(abs(FTs(Iv))*2); % Find MAximum and Index figure(2)
plot(Fv, abs(FTs(Iv))*2) axis([0 500 ylim]) grid
f = Fs/2*linspace(0,1,L/2+1); [B,IX] = sort(2*abs(FTs(1:L/2+1))); %order the amplitudes A1=B(end); %amplitude of the first peak A2=B(end-1); %amplitude of second peak f1=f(IX(end)); %frequency of first peak f2=f(IX(end-1)); %frequency of second peak BFloor=0.1; %BFloor is the minimum amplitude value (ignore small values) Amplitudes=B(B>=BFloor) %find all amplitudes above the BFloor Frequencies=f(IX(1+end-numel(Amplitudes):end)) %frequency of the peaks
regards uzmeed
댓글 수: 0
답변 (2개)
Youssef Khmou
2018년 1월 27일
The first part of the program is correct, the result is 100 Hz:
Fs = 65536; % Sampling Frequency (Hz)
Ts = 1/Fs; % Sampling Interval (sec)
Fn = Fs/2; % Nyquist Frequency (Hz)
L = 16384; % Signal Length (samples)
t = [0:(L-1)]*Ts; % Time Vector (sec)
s = cos(2*pi*100*t);% Signal (100 Hz)
figure(1),plot(s),
FTs = fft(s,Fs)/L; % Experiment #1
Fv = linspace(0, 1, fix(Fs/2)+1)*Fn;
Iv = 1:length(Fv);
[PeakFTs,Idx] = max(abs(FTs(Iv))*2); % Find MAximum and Index
figure(2)
plot(Fv, abs(FTs(Iv))*2),
axis([0 500 ylim]),grid on;
The frequency value is
>>Fv(Idx)
댓글 수: 0
uzmeed
2018년 1월 27일
댓글 수: 1
Youssef Khmou
2018년 1월 30일
편집: Youssef Khmou
2018년 1월 30일
for the case of mutiple peaks, you can use a peak detection procedure, and if the waveform is given by frequency that varies with continous rate then you can per example compute the with of the spectrum at half maximum to estimate the bandwidth.
참고 항목
카테고리
Help Center 및 File Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!