Determining the amplitude of peaks on a slowly changing signal?
1 view (last 30 days)
Show older comments
So as we all know, findpeaks will return the value of a peak using, e.g.,
[pks locs] = findpeaks(data, x);
My question is, how can I determine the value of the peaks when the function is changing? Normally I could just subtract the height of the function to get just the amplitude of the peaks, discounting the remainding function but now I can't because the function is decreasing.
I suppose my question is, how can I subtract a arying background from my peaks, i.e., isolate their true amplitude if that makes sense?
2 Comments
Mathieu NOE
on 12 May 2023
it's not super clear to me , do you have a working example (code & data) to share ?
Answers (1)
Shivam Malviya
on 17 May 2023
Hi,
I understand that you are interested in finding how much the peak stands out from the background.
Here are the possible ways to achieve this;
- One way is to use the prominence output of "findpeaks", which measures how much higher a peak is than its neighbouring valleys. This can give an idea of how much the peak stands out from the background. Here is an example of how to do this:
% Create a data with y = x, as a background
f = @(x) x + sin(x*pi);
x = 0:0.1:10;
data = f(x);
% Plot the data by running findpeaks without any output arguments
findpeaks(data)
% Execute the findpeaks and get prominence of the peaks
[pks, loc, w, p] = findpeaks(data);
disp("Prominence: " + mat2str(p));
- Another way is to subtract the background from the signal or data before using "findpeaks". This can be done by using "smoothdata" to estimate the background and then subtracting it from the original signal or data. Here is an example of how to do this:
% Create a data with y = x, as a background
f = @(x) sin(x/pi) + sin(x*pi);
x = 0:0.1:10;
data = f(x);
% Smoothen the data
backgroundData = smoothdata(data, "movmean", 20);
% Subract the backgroundData from the input data
fastMovingData = data - backgroundData;
% Plot data
plot(x, data)
hold on
plot(x, backgroundData)
plot(x, fastMovingData)
legend("Input Data","Background Data", "Fast Moving Data")
% Execute the findpeaks
[pks, loc, w, p] = findpeaks(fastMovingData);
disp("Peaks: " + mat2str(pks));
Refer to the following links for a better understanding;
0 Comments
See Also
Categories
Find more on Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!