Determining the amplitude of peaks on a slowly changing signal?

조회 수: 3 (최근 30일)
HC98
HC98 2023년 5월 11일
답변: Shivam Malviya 2023년 5월 17일
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
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
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));
Prominence: [1.10211303259031 1.10211303259031 1.10211303259031 1.10211303259031 1.10211303259031]
  • 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));
Peaks: [0.740895126540801 1.02301187483928 1.01888189993183 1.00735436778235 0.992945538896567]
Refer to the following links for a better understanding;

카테고리

Help CenterFile Exchange에서 Spectral Estimation에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by