How to extract only first peak of each pulse (positive or negative) in sequence throughout the signal

조회 수: 10 (최근 30일)
I would like to extract only first value of the peak, whether its positive or negative in a sequence and store in a array
My code is
data = C;
t = 1:length(data);
figure
plot(t,data)
xlabel('original data');
ylabel('amp')
legend('Noisy data Signal')
grid on
[p,s,mu] = polyfit((1:numel(data))',data,1);
fn = polyval(p,(1:numel(data))',[],mu);
x_data = data - fn;
[~,locs_Rwave] = findpeaks(x_data,'MinPeakHeight',0.005,'MinPeakDistance',3000);
inv = -x_data;[~,locs_Swave] = findpeaks(inv,'MinPeakHeight',0.005,'MinPeakDistance',3000);
[m_Peak, locs_m_peak] = findpeaks(abs(x_data),'MinPeakHeight',0.005,'MinPeakDistance',3000);
pos_pulses= [x_data(locs_Rwave),locs_Rwave];
neg_pulses= [x_data(locs_Swave),locs_Swave];

채택된 답변

Voss
Voss 2022년 5월 25일
load Example.mat
data = C;
t = 1:length(data);
[p,s,mu] = polyfit((1:numel(data))',data,1);
fn = polyval(p,(1:numel(data))',[],mu);
x_data = data - fn;
[pks_Rwave,locs_Rwave] = findpeaks(x_data,'MinPeakHeight',0.005,'MinPeakDistance',3000);
[pks_Swave,locs_Swave] = findpeaks(-x_data,'MinPeakHeight',0.005,'MinPeakDistance',3000);
[peak_locations,sort_idx] = sort([locs_Rwave; locs_Swave]);
peak_values = [pks_Rwave; -pks_Swave];
peak_values = peak_values(sort_idx);
plot(x_data)
hold on
plot(peak_locations,peak_values,'ro')
xlim([2.992e5 2.996e5])
first_peak_location = peak_locations(1)
first_peak_location = 299266
first_peak_value = peak_values(1)
first_peak_value = -0.0122
  댓글 수: 4
MANINDER CHOUDHARY
MANINDER CHOUDHARY 2022년 5월 27일
There are two peaks i.e. positive and negative however the pulse starts with negative peak value (First peak), i just want to take first peak value and store it somwewhere, and then move ahead to second pulse and repeat the same procedure trhrougout . Hope now its clear
Voss
Voss 2022년 5월 27일
I think I understand now. You want to know the location and/or value of the first peak of each pulse, under the assumption that each pulse has two peaks.
The code I showed has all the peak locations sorted, so, since each pulse has two peaks and you want the first peak of each pulse, you can simply take every alternate peak, starting with the first peak:
peak_locations(1:2:end) % location of the first peak of each pulse
peak_values(1:2:end) % value or height of the first peak of each pulse

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by