reading frequency from fft
8 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Youssef Khmou
on 27 Jan 2018
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 Comments
uzmeed
on 27 Jan 2018
1 Comment
Youssef Khmou
on 30 Jan 2018
Edited: Youssef Khmou
on 30 Jan 2018
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.
See Also
Categories
Find more on Measurements and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!