How to extract only first peak of each pulse (positive or negative) in sequence throughout the signal
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MANINDER CHOUDHARY
am 25 Mai 2022
Kommentiert: Voss
am 27 Mai 2022
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 Kommentare
Akzeptierte Antwort
Voss
am 25 Mai 2022
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 Kommentare
Voss
am 27 Mai 2022
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
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!