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
| Parameter | Use Case | Behavior |
|---|---|---|
'MinPeakHeight' | Flat, stable baseline | Discards any peak where \(y < \text{threshold}\). |
'MinPeakProminence' | Drifting or curved baseline | Measures height relative to adjacent valleys. |
'MinPeakDistance' | Closely spaced noise spikes | Keeps only the largest peak within a specified window. |
'Threshold' | Flat plateau suppression | Minimum 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.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.
Explore similar technical troubleshooting questions and verified MATLAB solutions: