How to find the maximum of peaks ?

18 ビュー (過去 30 日間)
Ramesh Bala
Ramesh Bala 2021 年 8 月 18 日
コメント済み: Ramesh Bala 2021 年 8 月 19 日
I want to find the first maximum 4 peaks in loop.My code finds all the peaks,how can I find only 4 and plot them ?
A= load ('ZT2.mat');
for i= 1:1:300
s3= abs(fft( A.A1(:,i)));
subplot (3,2,1)
plot (s3((1:end/2)));
subplot (3,2,2)
plot ( (locSA{i}),(pkSA{i}));
title('Peaks ZT1');


Yazan 2021 年 8 月 18 日
Below, I am proposing an implementation of what I understood to be your task. You have to experiment with the findpeaks multiple options to find a setting good for your data.
clc, clear
load ('ZT2.mat');
fftData = abs(fft(A1, [], 2));
N = size(fftData, 2);
fftData = [fftData(:, 1:N/2), fftData(:, 1)];
freq = linspace(0, 0.5, N/2+1);
locSA = cell(1, size(A1, 1));
pkSA = cell(1, size(A1, 1));
Np = 4;
sortP = 'descend';
minPeakDis = 1;
for i=1:size(fftData,1)
[pkSA{i}, locSA{i}] = findpeaks(fftData(i,:), 'NPeaks', 4, 'SortStr', sortP, ...
'MinPeakDistance', minPeakDis);
subplot (1, 2, 1)
plot(freq, fftData(i,:)); xlabel('Normalized frequency')
ylabel('Amplitude'), title('Positive spectrum')
hold on, plot(freq(locSA{i}), pkSA{i}, 's', 'MarkerSize', 5, 'MarkerEdgeColor', 'g',...
'MarkerFaceColor', 'g'); grid minor, hold off
subplot (1, 2, 2)
stem(freq(locSA{i}), pkSA{i}, 'Marker', 's', 'MarkerSize', 7, 'MarkerEdgeColor', 'g',...
'MarkerFaceColor', 'g'); xlabel('Normalized frequency')
ylabel('Amplitude'), title('Spectral peaks locations'), grid minor
  1 件のコメント
Ramesh Bala
Ramesh Bala 2021 年 8 月 19 日
This is perfect .Thanks Yazan
this the key that I was expecting especially 'SortStr', sortP, ...
'MinPeakDistance', minPeakDis


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by