How to find second dominant frequency?

here i have code that determine dominant frequency, but i want to find the second dominant from the signal.
if true
y = fft(x,nfft); % Fast Fourier Transform
y = abs(y.^2); % raw power spectrum density
y = y(1:1+nfft/2); % half-spectrum
[v,k] = max(y); % find maximum
f_scale = (0:nfft/2)* Fs/nfft; % frequency scale
plot(f_scale, y),axis('tight'),grid('on'),title('Dominant Frequency')
fest = f_scale(k); % dominant frequency estimate
fprintf('Dominant freq.: true %f Hz, estimated %f Hznn', f, fest)
fprintf('Frequency step (resolution) = %f Hznn', f_scale(2))
end

Respuestas (2)

Image Analyst
Image Analyst el 21 de Mzo. de 2016

0 votos

Depends on how you define "dominant". You could just sort the signal and take the second largest one. But there are other ways you could define it. Why don't you supply x, or at least a screenshot of your plots?
Star Strider
Star Strider el 21 de Mzo. de 2016

0 votos

If you have the Signal Processing Toolbox, use the findpeaks function.

3 comentarios

Nidhi Singh
Nidhi Singh el 2 de Mzo. de 2022
It will give all the peaks..I also want first 3 dominant frequencies from fft plot..how can we achieve that?
Star Strider
Star Strider el 2 de Mzo. de 2022
Use the findpeaks name-value pair arguments to constrain what the function does and the results it produces.
@Nidhi Singh findpeaks gives the peak values. If you want you could sort them and take the 3 highest.
[peakValues, indexesOfPeaks] = findpeaks(y);
[sortedValues, sortOrder] = sort(peakValues, 'descend');
threeHighestValues = sortedValues(1:3)
indexes3 = indexesOfPeaks(sortOrder(1:3))

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 21 de Mzo. de 2016

Comentada:

el 2 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by