Determining the amplitude of peaks on a slowly changing signal?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Mathieu NOE
2023-5-12
it's not super clear to me , do you have a working example (code & data) to share ?
回答(1 个)
Shivam Malviya
2023-5-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!