Asked by Edii Mason
on 13 Jul 2018

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;

Answer by Carlos Felipe Rengifo
on 14 Jul 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;

Edii Mason
on 16 Jul 2018

Carlos Felipe Rengifo
on 18 Jul 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.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Image Analyst (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/410320-how-can-i-remove-a-set-of-given-peaks-such-as-the-peaks-located-at-7-9000-0-9989-and-14-1000-0-9#comment_589179

## dpb (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/410320-how-can-i-remove-a-set-of-given-peaks-such-as-the-peaks-located-at-7-9000-0-9989-and-14-1000-0-9#comment_589189

Sign in to comment.