MATLAB: How to restrict the Max Peak Height of findpeaks

max peak heightSignal Processing Toolbox

I've managed to set a minimum peak height when plotting some data and finding the peaks but is there a function I can ue to set a max peak height? I can't seem to find one.
As you can see the errors are quite large. My code is as follows:
figure(nF)
findpeaks(ResAcceltrim,'MinPeakDistance',300,'MinPeakHeight',pe);
pks=findpeaks(ResAcceltrim,'MinPeakDistance',300,'MinPeakHeight',pe);
pks=pks(1:20,1);

Best Answer

If you don't want it to find peaks higher than some amount, just set those elements equal to the min. Actually it would be better to find the peaks and then "fall down" the peaks until they turn up again and then interpolate in from both sides, but that's more complicated even though it would be better. Maybe this simple way will do the job for you:
minValue = min(yourSignal);
tallPeakIndexes = yourSignal > someThreshold; % Whatever value you want.
yourSignal(tallPeakIndexes) = minValue; % Or you can use someThreshold instead of minValue.
If that ends up finding spurious peaks at the edges of the flattened peak, then use the more robust second method I suggested.