How to extract only first peak of each pulse (positive or negative) in sequence throughout the signal
17 次查看(过去 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];
0 个评论
采纳的回答
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_value = peak_values(1)
4 个评论
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 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!