Remove peaks below a threshold using findpeaks function

D
Diego · Jan 15, 2021 · 2.3K views
Question
I know this topic has been discussed before to some extent, but I can't seem to figure out a way to do the following. I am finding peaks in my kernel distribution function which is returned in terms of PDF and X, where PDF vs. X is plotted. To find the peaks I do the following: [Peaks, Locs] = findpeaks(PDF) ; %Find Y value of the peaks X_peakVal = X(Locs) ; %Find X value of the peaks However, I would like to reject some values for some peaks that lie below a threshold:   [Peaks, Locs] = findpeaks(PDF) ; %Find Y value of the peaks Peaks(Peaks < 0.01*max(Peaks)) = [] ; %Reject Y value of peaks below this threshold X_peakVal = X(Locs) ; %Find X value of the peaks The above code does not reject the corresponding indices noted as Locs, such as the corresponding X_peakVal (or X values corresponding to the Y peaks) are also rejected.   What is a way to exclude the corresponding X values to the rejected Y?
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Sep 16, 2026






Filter Peaks Below a Threshold with findpeaks in MATLAB


To exclude unwanted noise or small peaks in MATLAB, use the 'MinPeakHeight' or 'MinPeakProminence' name-value pairs in the findpeaks() function.

1. Method 1: Absolute Amplitude Threshold ('MinPeakHeight')


This filters out any peak whose absolute value falls below a specified minimum level (e.g., threshold = 1.5).

% Generate sample noisy signal with peaks of different heights
t = linspace(0, 10, 1000);
signal = sin(t) + 0.8*cos(3*t) + 0.5*sin(7*t) + 0.1*randn(size(t));

% Define threshold
minHeight = 1.2;

% Find peaks strictly greater than minHeight
[pks, locs] = findpeaks(signal, t, 'MinPeakHeight', minHeight);

% Plot signal and detected peaks
figure('Color', 'w', 'Position', [100, 100, 750, 400]);
plot(t, signal, 'b-', 'LineWidth', 1.2, 'DisplayName', 'Signal');
hold on;
plot(locs, pks, 'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 6, ...
    'DisplayName', sprintf('Peaks > %.1f', minHeight));
yline(minHeight, 'k--', 'LineWidth', 1.5, ...
    'DisplayName', sprintf('Threshold (%.1f)', minHeight));

xlabel('Time (s)');
ylabel('Amplitude');
title('Peak Filtering Using MinPeakHeight');
legend('Location', 'northeast');
grid on;

2. Method 2: Prominence-Based Filtering ('MinPeakProminence')


When the signal baseline drifts up and down, absolute height thresholds fail. Use 'MinPeakProminence' to measure how much a peak stands out relative to its local surrounding valleys.

% Signal on a drifting baseline
driftingBaseline = 0.5 * t;
noisySignal = sin(2*pi*0.5*t) + driftingBaseline + 0.15*randn(size(t));

% Detect only significant peaks regardless of baseline height
minProminence = 1.0;
[pks_prom, locs_prom] = findpeaks(noisySignal, t, ...
    'MinPeakProminence', minProminence);

figure('Color', 'w');
plot(t, noisySignal, 'Color', [0.3 0.3 0.8], 'DisplayName', 'Drifting Signal');
hold on;
plot(locs_prom, pks_prom, 'rv', 'MarkerFaceColor', 'r', 'MarkerSize', 7, ...
    'DisplayName', 'Significant Peaks');
xlabel('Time (s)');
ylabel('Amplitude');
title('Prominence-Based Peak Detection (Handles Baseline Drift)');
legend('Location', 'northwest');
grid on;

3. Combining Multiple Peak Constraints


Combine height, prominence, and minimum distance between peaks for robust noise rejection.

[pks, locs, w, p] = findpeaks(signal, t, ...
    'MinPeakHeight', 1.0, ...      % Absolute height threshold
    'MinPeakProminence', 0.5, ...  % Prominence threshold
    'MinPeakDistance', 0.8);       % Minimum time spacing between peaks

% Built-in plot visualization
figure('Color', 'w');
findpeaks(signal, t, ...
    'MinPeakHeight', 1.0, ...
    'MinPeakProminence', 0.5, ...
    'MinPeakDistance', 0.8);
grid on;

Parameter Selection Guide












ParameterUse CaseBehavior
'MinPeakHeight'Flat, stable baselineDiscards any peak where \(y < \text{threshold}\).
'MinPeakProminence'Drifting or curved baselineMeasures height relative to adjacent valleys.
'MinPeakDistance'Closely spaced noise spikesKeeps only the largest peak within a specified window.
'Threshold'Flat plateau suppressionMinimum difference between a peak and immediate neighbors.


Tip: Calling findpeaks(signal, t, ...) with no output arguments plots the signal, labels peak locations, and draws the threshold boundary automatically.



100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!