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!