How do I find a max value of a signal defined within a range?

48 次查看(过去 30 天)
Hello, so I have a signal with several peaks, but I am only looking for a max peak within a specific range of that signal. So instead of getting the max peak, I want the max value within a specific range of that signal.
This is the code I am using right now to find the max peak of the signal:
if true
s = signal;
max = find(max(s) == s);
end
The key is that I still am looking for a max value of the signal 's', but only within a range of 12 to 15 seconds of that signal.
Any help would be greatly appreciated. Thank you for taking the time to look at my problem.

回答(1 个)

Image Analyst
Image Analyst 2017-3-17
To find the max of the signal and what element it occurs at, you can do this:
[maxSignal, indexOfMax] = max(signal)
I don't know how many elements correspond to 12 to 15 seconds, but let's just assume here that it is 100 elements. So you can do
index1 = indexOfMax - 100;
if index1 < 1
index1 = 1; % Don't allow negative or zero indexes.
end
index2 = indexOfMax + 100;
if index2 > length(signal)
index2 = length(signal); % Don't allow negative or zero indexes.
end
Now you want the max in the range from index1 to index2 but obviously not the first max you found. So you can set the array before index1, and after index2, and at the first max to minus infinity. Then call max again. This will find " max value of the signal 's', but only within a range of 12 to 15 seconds" of the first max as you asked for
signal(1:index1) = -inf; % Make a copy of signal if you want to save the original.
signal(index2:end) = -inf;
signal(indexOfMax) = -inf;
[secondMax, indexOfSecondMax] = max(signal);
An alternate method is to sort the signal but then you have to check the sorted values to see if their indexes are within 12-15 seconds of the first index.
[sortedValues, sortIndices] = sort(signal, 'descend');
maxSignal = sortedValues(1);
indexOfMax = sortIndices(1);
% Now find second, but has to be within, say, 100 elements
k = 2;
while k < length(sortIndices)
indexesApart = sortIndices(k) - sortIndices(1);
if abs(indexesApart) < 100
break;
end
% If we get here, it's not within 12-15 seconds of the first max.
% So increment the index and try again.
k = k +1;
end
% Get the actual index
indexOfSecondMax = sortIndices(k)
% Get the signal value at that location.
secondMax = signal(indexOfSecondMax)
  3 个评论
Image Analyst
Image Analyst 2017-3-18
I'm not sure I understand. First of all, it looks like signal is a time domain signal. You have not defined your t axis or the frequency. But the frequency looks like a single number, not a range. I can't even run your code because you have not defined t and f.
Anonymous45
Anonymous45 2017-3-18
I was trying not to give away to much of my code mostly just the skeleton of it with hopes that someone can just help me define a range and find a peak within that range. The signal is Fourier Transformed into frequency domain.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by