How can I remove a set of given peaks such as the peaks located at (7.9000,0.9989) and (14.1000, 0.9993) in the following code? I want to be able to do this even when the plot expands and has many more peaks.

13 vues (au cours des 30 derniers jours)
t=[0:0.1:6*pi];
y=sin(t);
[pks,pk_locs] = findpeaks(y,t);
[trghs,trgh_locs] = findpeaks(-y,t);
plot(t,y);
hold on;
plot(pk_locs,pks,'^r');
plot(trgh_locs,-trghs,'vg');
hold off;
  2 commentaires
Image Analyst
Image Analyst le 13 Juil 2018
I don't see why that won't work for any number of peaks or signal length.
You forgot to read this link. So no data, no screenshot = no answer.
Also, please read this link so you know how to format your code so that people can read it.
dpb
dpb le 13 Juil 2018
How to decide which specific peaks to remove is the bigger question...after that,
doc ismembertol
probably answers the Q?.

Connectez-vous pour commenter.

Réponses (1)

Carlos Felipe Rengifo
Carlos Felipe Rengifo le 14 Juil 2018
Hi, it can be done by replacing the undesired peaks by nan values. In your case, it will be:
% The first two lines of your script
t = [0:0.1:6*pi];
y = sin(t);
% I just added this line to your code
y(ismembertol(t,[7.9,14.1],1E-3)) = nan;
% The rest of your code
[pks,pk_locs] = findpeaks(y,t);
[trghs,trgh_locs] = findpeaks(-y,t);
plot(t,y);
hold on;
plot(pk_locs,pks,'^r');
plot(trgh_locs,-trghs,'vg');
hold off;
  2 commentaires
Edii Mason
Edii Mason le 16 Juil 2018
Thank you for your answer! That is what I want except it seems to also erase part of the sin plot and I want to only erase the peak marker while maintaining the original plot. Do you have any ideas how to do this?
Carlos Felipe Rengifo
Carlos Felipe Rengifo le 18 Juil 2018
In that case, I propose the following solution:
% Signal generation
t = 0:0.1:6*pi;
y = sin(t);
% Find peaks
[pks,pk_locs] = findpeaks(y,t);
[trghs,trgh_locs] = findpeaks(-y,t);
% Removing undesired peaks
removals = ismembertol(pk_locs,[7.9,14.1],1E-3);
pk_locs(removals) = [];
pks(removals) = [];
% Plot
plot(t,y);
hold on;
plot(pk_locs,pks,'^r');
plot(trgh_locs,-trghs,'vg');
hold off;
I hope this solution meets your requirements. If that is not the case, I will be happy to try again.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by