How can we determine how many peaks are at each plot?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How can we determine how many peaks are at each plot?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1381854/image.png)
0 commentaires
Réponses (1)
Sulaymon Eshkabilov
le 12 Mai 2023
Use findpeaks() fcn: see DOC
e.g.:
t = linspace(0, 2, 1000); % Time
fs = 1/t(2); % Sampling freq [Hz]
f1 = 5; % Freq 1.
f2 = 25; % Freq 2.
f3 = 50; % Freq 3.
f4 = 100; % Freq 4.
% Signal generated with some noise effect
S = 5*sin(2*pi*t*f1)+2*cos(2*pi*t*f2)+1.5*sin(2*pi*t*f3)+.5*cos(2*pi*t*f4)+.1*randn(size(t));
% FFT caclculations:
L = length(S);
n = 2^nextpow2(L);
Y= fft(S, n);
f = fs*(0:(n/2))/n;
P2 = abs(Y/n);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
plot(f,P1)
title("FFT")
xlabel("f (Hz)")
ylabel("|P(f)|^2")
Peak_Freq_Values_ALL = findpeaks(P1);
figure(2)
findpeaks(P1,f, 'MinPeakProminence',.25,'Annotate','extents');
title("FFT with Peak Freq values")
xlabel("f (Hz)")
ylabel("|P(f)|^2")
0 commentaires
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!